diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py index f7ef1ecd1c2..9e709bad156 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py @@ -191,8 +191,5 @@ async def load_state(self, state: Mapping[str, Any]) -> None: """Restore agent from saved state. Default implementation for stateless agents.""" BaseState.model_validate(state) - async def activate(self) -> None: - pass - - async def deactivate(self) -> None: + async def close(self) -> None: pass diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py index 19f01115e9d..256f752bfa8 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py @@ -65,10 +65,6 @@ async def load_state(self, state: Mapping[str, Any]) -> None: """Restore agent from saved state""" ... - async def activate(self) -> None: - """Lazily called the first time a runtime sends a message to this agent""" - ... - - async def deactivate(self) -> None: + async def close(self) -> None: """Called when the runtime is stopped or any stop method is called""" ... diff --git a/python/packages/autogen-core/src/autogen_core/_agent.py b/python/packages/autogen-core/src/autogen_core/_agent.py index 0711fad5fc0..321b6ccd8ef 100644 --- a/python/packages/autogen-core/src/autogen_core/_agent.py +++ b/python/packages/autogen-core/src/autogen_core/_agent.py @@ -46,10 +46,6 @@ async def load_state(self, state: Mapping[str, Any]) -> None: ... - async def activate(self) -> None: - """Lazily called the first time a runtime sends a message to this agent""" - ... - - async def deactivate(self) -> None: + async def close(self) -> None: """Called when the runtime is stopped or any stop method is called""" ... diff --git a/python/packages/autogen-core/src/autogen_core/_base_agent.py b/python/packages/autogen-core/src/autogen_core/_base_agent.py index 2d11786ab67..bffb61b876b 100644 --- a/python/packages/autogen-core/src/autogen_core/_base_agent.py +++ b/python/packages/autogen-core/src/autogen_core/_base_agent.py @@ -152,10 +152,7 @@ async def load_state(self, state: Mapping[str, Any]) -> None: warnings.warn("load_state not implemented", stacklevel=2) pass - async def activate(self) -> None: - pass - - async def deactivate(self) -> None: + async def close(self) -> None: pass @classmethod diff --git a/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py b/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py index f3989ca5e84..dbfc999c56d 100644 --- a/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py +++ b/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py @@ -160,7 +160,6 @@ def __init__( str, Callable[[], Agent | Awaitable[Agent]] | Callable[[AgentRuntime, AgentId], Agent | Awaitable[Agent]] ] = {} self._instantiated_agents: Dict[AgentId, Agent] = {} - self._activated_agents: set[AgentId] = set() self._intervention_handlers = intervention_handlers self._background_tasks: Set[Task[Any]] = set() self._subscription_manager = SubscriptionManager() @@ -311,10 +310,6 @@ async def _process_send(self, message_envelope: SendMessageEnvelope) -> None: ) recipient_agent = await self._get_agent(recipient) - if recipient not in self._activated_agents: - self._activated_agents.add(recipient) - await recipient_agent.activate() - message_context = MessageContext( sender=message_envelope.sender, topic_id=None, @@ -407,10 +402,6 @@ async def _process_publish(self, message_envelope: PublishMessageEnvelope) -> No ) agent = await self._get_agent(agent_id) - if agent_id not in self._activated_agents: - self._activated_agents.add(agent_id) - await agent.activate() - async def _on_message(agent: Agent, message_context: MessageContext) -> Any: with self._tracer_helper.trace_block("process", agent.id, parent=None): with MessageHandlerContext.populate_context(agent.id): @@ -588,11 +579,10 @@ async def stop(self) -> None: if self._run_context is None: raise RuntimeError("Runtime is not started") - # deactivate all the agents that have been activated - for agent_id in self._activated_agents: + # close all the agents that have been instantiated + for agent_id in self._instantiated_agents: agent = await self._get_agent(agent_id) - await agent.deactivate() - self._activated_agents.clear() + await agent.close() await self._run_context.stop() self._run_context = None @@ -605,11 +595,10 @@ async def stop_when_idle(self) -> None: raise RuntimeError("Runtime is not started") await self._run_context.stop_when_idle() - # deactivate all the agents that have been activated - for agent_id in self._activated_agents: + # close all the agents that have been instantiated + for agent_id in self._instantiated_agents: agent = await self._get_agent(agent_id) - await agent.deactivate() - self._activated_agents.clear() + await agent.close() self._run_context = None self._message_queue = Queue() @@ -632,11 +621,10 @@ async def stop_when(self, condition: Callable[[], bool]) -> None: raise RuntimeError("Runtime is not started") await self._run_context.stop_when(condition) - # deactivate all the agents that have been activated - for agent_id in self._activated_agents: + # close all the agents that have been instantiated + for agent_id in self._instantiated_agents: agent = await self._get_agent(agent_id) - await agent.deactivate() - self._activated_agents.clear() + await agent.close() self._run_context = None self._message_queue = Queue() diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.py b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.py index de5f9055867..c6bcf2c85d7 100644 --- a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.py +++ b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.py @@ -74,7 +74,7 @@ class MultimodalWebSurfer(BaseChatAgent): When :meth:`on_messages` or :meth:`on_messages_stream` is called, the following occurs: - 1) If this is the first call, the browser is initialized and the page is loaded. This is done in :meth:`_lazy_init`. The browser is only closed when :meth:`deactivate` is called. + 1) If this is the first call, the browser is initialized and the page is loaded. This is done in :meth:`_lazy_init`. The browser is only closed when :meth:`close` is called. 2) The method :meth:`_generate_reply` is called, which then creates the final response as below. 3) The agent takes a screenshot of the page, extracts the interactive elements, and prepares a set-of-mark screenshot with bounding boxes around the interactive elements. 4) The agent makes a call to the :attr:`model_client` with the SOM screenshot, history of messages, and the list of available tools. @@ -138,7 +138,7 @@ async def main() -> None: stream = agent_team.run_stream(task="Navigate to the AutoGen readme on GitHub.") await Console(stream) # Close the browser controlled by the agent - await web_surfer_agent.deactivate() + await web_surfer_agent.close() asyncio.run(main()) @@ -291,7 +291,7 @@ async def _lazy_init( await self._set_debug_dir(self.debug_dir) self.did_lazy_init = True - async def deactivate(self) -> None: + async def close(self) -> None: """ Close the browser and the page. Should be called when the agent is no longer needed. diff --git a/python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py b/python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py index b4d6da4a4c2..4ae66e44ccf 100644 --- a/python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py +++ b/python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py @@ -179,7 +179,7 @@ async def recv(self) -> agent_worker_pb2.Message: class GrpcWorkerAgentRuntime(AgentRuntime): - # TODO: Needs to handle agent activate()/deactivate() calls + # TODO: Needs to handle agent close() call def __init__( self, host_address: str,