Remove ServiceAgentNetworkStorage singleton#289
Conversation
| 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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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: |
| """ | ||
| if not ServiceAgentNetworkStorage.instance: | ||
| ServiceAgentNetworkStorage.instance = ServiceAgentNetworkStorage() | ||
| return ServiceAgentNetworkStorage.instance |
There was a problem hiding this comment.
Don't need get_instance() any more.
| security_cfg: Dict[str, Any], | ||
| server_logging: AgentServerLogging): | ||
| server_logging: AgentServerLogging, | ||
| network_storage: AgentNetworkStorage): |
There was a problem hiding this comment.
Typical plumbing addition.
| """ | ||
| network_storage: ServiceAgentNetworkStorage =\ | ||
| ServiceAgentNetworkStorage.get_instance() | ||
| network_storage.setup_agent_networks(self.agent_networks) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
This is one of the two places where an object instance originates.
Tested: {music_nerd_pro, math_guy_passthrough} x {http, grpc, direct} with local/service externals on direct