Skip to content

Commit

Permalink
remove activate. Rename deactivate to close
Browse files Browse the repository at this point in the history
  • Loading branch information
peterychang committed Jan 2, 2025
1 parent de89455 commit 3165734
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
...
6 changes: 1 addition & 5 deletions python/packages/autogen-core/src/autogen_core/_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
...
5 changes: 1 addition & 4 deletions python/packages/autogen-core/src/autogen_core/_base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3165734

Please sign in to comment.