Skip to content

Comments

Remove ServiceAgentNetworkStorage singleton#289

Merged
d1donlydfink merged 8 commits intomainfrom
DEF-remove-network-storage-singleton
Jul 8, 2025
Merged

Remove ServiceAgentNetworkStorage singleton#289
d1donlydfink merged 8 commits intomainfrom
DEF-remove-network-storage-singleton

Conversation

@d1donlydfink
Copy link
Collaborator

@d1donlydfink d1donlydfink commented Jul 8, 2025

  • Remove ServiceAgentNetworkStorage.get_instance()
  • Have the object originate in 2 places:
    • In the server: ServerMainLoop
    • In the client: DirectAgentSessionFactory
  • Plumb access to these objects to sessions and throughout the service
  • Rename ServiceAgentNetworkStorage to AgentNetworkStorage. Service aspect of name doesn't really need to be there.

Tested: {music_nerd_pro, math_guy_passthrough} x {http, grpc, direct} with local/service externals on direct

@d1donlydfink d1donlydfink marked this pull request as draft July 8, 2025 17:51
from neuro_san.internals.graph.persistence.registry_manifest_restorer import RegistryManifestRestorer
from neuro_san.internals.interfaces.agent_network_provider import AgentNetworkProvider
from neuro_san.internals.network_providers.service_agent_network_storage import ServiceAgentNetworkStorage
from neuro_san.internals.network_providers.agent_network_storage import AgentNetworkStorage
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename ServiceAgentNetworkStorage -> AgentNetworkStorage

manifest_restorer = RegistryManifestRestorer()
self.manifest_networks: Dict[str, AgentNetwork] = manifest_restorer.restore()
network_storage: ServiceAgentNetworkStorage = ServiceAgentNetworkStorage.get_instance()
self.network_storage = AgentNetworkStorage()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the two places where an object instance originates.

toolbox_factory.load()

factory = ExternalAgentSessionFactory(use_direct=use_direct)
factory = ExternalAgentSessionFactory(use_direct=use_direct, network_storage=self.network_storage)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where we pass the AgentNetworkStorage into the ExternalAgentSessionFactory.
Other places are in the service and the always pass use_direct=False, whose code paths will never user the network storage.



class ServiceAgentNetworkStorage:
class AgentNetworkStorage:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename.

"""
if not ServiceAgentNetworkStorage.instance:
ServiceAgentNetworkStorage.instance = ServiceAgentNetworkStorage()
return ServiceAgentNetworkStorage.instance
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need get_instance() any more.

security_cfg: Dict[str, Any],
server_logging: AgentServerLogging):
server_logging: AgentServerLogging,
network_storage: AgentNetworkStorage):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typical plumbing addition.

"""
network_storage: ServiceAgentNetworkStorage =\
ServiceAgentNetworkStorage.get_instance()
network_storage.setup_agent_networks(self.agent_networks)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really need this method. Just call the network storage directly (see below)


self.setup_agent_network_storage()
# DEF - It's possible this could move outside this class.
self.network_storage.setup_agent_networks(self.agent_networks)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call the network storage directly instead of using the method.
Interesting note in the comment here. It's possible we might want to move this out somewhere else.
We'll see. Enough going on in this PR.

self.forwarded_request_metadata: List[str] = forwarded_request_metadata
self.openapi_service_spec_path: str = openapi_service_spec_path
self.logger = HttpLogger(forwarded_request_metadata)
self.network_storage: AgentNetworkStorage = network_storage
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseRequestHandler itself doesn't really need the AgentNetworkStorage, but subclasses do and this is the closest thing the tornado infrastructure has to a constructor that is available to us.

"forwarded_request_metadata": self.forwarded_request_metadata,
"openapi_service_spec_path": self.openapi_service_spec_path
"openapi_service_spec_path": self.openapi_service_spec_path,
"network_storage": self.network_storage
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add network_storage to this "request data" dictionary. This is the mechanism by which args are passed to BaseRequestHandler.initialize()

self.manifest_update_period_seconds: int = 0
self.server: GrpcAgentServer = None
self.manifest_files: List[str] = []
self.network_storage = AgentNetworkStorage()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the two places where an object instance originates.

@d1donlydfink d1donlydfink marked this pull request as ready for review July 8, 2025 21:25
Copy link
Contributor

@andreidenissov-cog andreidenissov-cog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@d1donlydfink d1donlydfink merged commit 88591e5 into main Jul 8, 2025
4 checks passed
@d1donlydfink d1donlydfink deleted the DEF-remove-network-storage-singleton branch July 8, 2025 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants