A programming framework for agentic AI
reset --> on_reset :D (#4121)
Eric Zhu8f7c7171495f
diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.pyindex d18e755fe..2c0d16760 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py@@ -298,6 +298,6 @@ class AssistantAgent(BaseChatAgent):except Exception as e:return FunctionExecutionResult(content=f"Error: {e}", call_id=tool_call.id)- async def reset(self, cancellation_token: CancellationToken) -> None:+ async def on_reset(self, cancellation_token: CancellationToken) -> None:"""Reset the assistant agent to its initialization state."""self._model_context.clear()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.pyindex bc337de9d..5fd4c1854 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@@ -106,6 +106,6 @@ class BaseChatAgent(ChatAgent, ABC):yield message@abstractmethod- async def reset(self, cancellation_token: CancellationToken) -> None:+ async def on_reset(self, cancellation_token: CancellationToken) -> None:"""Resets the agent to its initialization state."""...diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.pyindex 4b7848bbd..7f5447fb5 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py@@ -39,6 +39,6 @@ class CodeExecutorAgent(BaseChatAgent):else:return Response(chat_message=TextMessage(content="No code blocks found in the thread.", source=self.name))- async def reset(self, cancellation_token: CancellationToken) -> None:+ async def on_reset(self, cancellation_token: CancellationToken) -> None:"""It it's a no-op as the code executor agent has no mutable state."""passdiff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.pyindex 5b2f05000..9a8cdffaa 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.py@@ -141,7 +141,7 @@ class SocietyOfMindAgent(BaseChatAgent):# Reset the team.await self._team.reset()- async def reset(self, cancellation_token: CancellationToken) -> None:+ async def on_reset(self, cancellation_token: CancellationToken) -> None:await self._team.reset()def _create_transcript(self, messages: Sequence[AgentMessage]) -> str: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.pyindex 3bf54f999..dd3a2be2c 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@@ -51,6 +51,6 @@ class ChatAgent(TaskRunner, Protocol):and the final item is the response."""...- async def reset(self, cancellation_token: CancellationToken) -> None:+ async def on_reset(self, cancellation_token: CancellationToken) -> None:"""Resets the agent to its initialization state."""...diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.pyindex 19739dfdf..d249676fd 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py@@ -42,7 +42,7 @@ class ChatAgentContainer(SequentialRoutedAgent):async def handle_reset(self, message: GroupChatReset, ctx: MessageContext) -> None:"""Handle a reset event by resetting the agent."""self._message_buffer.clear()- await self._agent.reset(ctx.cancellation_token)+ await self._agent.on_reset(ctx.cancellation_token)@eventasync def handle_request(self, message: GroupChatRequestPublish, ctx: MessageContext) -> None:diff --git a/python/packages/autogen-agentchat/tests/test_group_chat.py b/python/packages/autogen-agentchat/tests/test_group_chat.pyindex b2a200e22..fc6da212b 100644--- a/python/packages/autogen-agentchat/tests/test_group_chat.py+++ b/python/packages/autogen-agentchat/tests/test_group_chat.py@@ -83,7 +83,7 @@ class _EchoAgent(BaseChatAgent):assert self._last_message is not Nonereturn Response(chat_message=TextMessage(content=self._last_message, source=self.name))- async def reset(self, cancellation_token: CancellationToken) -> None:+ async def on_reset(self, cancellation_token: CancellationToken) -> None:self._last_message = None@@ -633,7 +633,7 @@ class _HandOffAgent(BaseChatAgent):))- async def reset(self, cancellation_token: CancellationToken) -> None:+ async def on_reset(self, cancellation_token: CancellationToken) -> None:passdiff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynbindex 5b14e0e72..9c01c45b1 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb@@ -16,7 +16,7 @@"- {py:attr}`~autogen_agentchat.agents.BaseChatAgent.description`: The description of the agent in text.\n","- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages`: Send the agent a sequence of {py:class}`~autogen_agentchat.messages.ChatMessage` get a {py:class}`~autogen_agentchat.base.Response`.\n","- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream`: Same as {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages` but returns an iterator of {py:class}`~autogen_agentchat.messages.AgentMessage` followed by a {py:class}`~autogen_agentchat.base.Response` as the last item.\n",- "- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.reset`: Reset the agent to its initial state.\n",+ "- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_reset`: Reset the agent to its initial state.\n","\n","See {py:mod}`autogen_agentchat.messages` for more information on AgentChat message types.\n","\n",@@ -272,7 +272,7 @@"class and implement the following abstract methods and attributes:\n","\n","- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages`: The abstract method that defines the behavior of the agent in response to messages. This method is called when the agent is asked to provide a response in {py:meth}`~autogen_agentchat.agents.BaseChatAgent.run`. It returns a {py:class}`~autogen_agentchat.base.Response` object.\n",- "- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.reset`: The abstract method that resets the agent to its initial state. This method is called when the agent is asked to reset itself.\n",+ "- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_reset`: The abstract method that resets the agent to its initial state. This method is called when the agent is asked to reset itself.\n","- {py:attr}`~autogen_agentchat.agents.BaseChatAgent.produced_message_types`: The list of possible {py:class}`~autogen_agentchat.messages.ChatMessage` message types the agent can produce in its response.\n","\n","Optionally, you can implement the the {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream` method to stream messages as they are generated by the agent. If this method is not implemented, the agent\n",@@ -345,7 +345,7 @@" # It contains the final message and all the inner messages.\n"," yield Response(chat_message=TextMessage(content=\"Done!\", source=self.name), inner_messages=inner_messages)\n","\n",- " async def reset(self, cancellation_token: CancellationToken) -> None:\n",+ " async def on_reset(self, cancellation_token: CancellationToken) -> None:\n"," pass\n","\n","\n",@@ -406,7 +406,7 @@" user_input = await asyncio.get_event_loop().run_in_executor(None, input, \"Enter your response: \")\n"," return Response(chat_message=TextMessage(content=user_input, source=self.name))\n","\n",- " async def reset(self, cancellation_token: CancellationToken) -> None:\n",+ " async def on_reset(self, cancellation_token: CancellationToken) -> None:\n"," pass\n","\n","\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynbindex 6be1e1334..5124ca2e6 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynb@@ -82,7 +82,7 @@" return Response(chat_message=StopMessage(content=\"User has terminated the conversation.\", source=self.name))\n"," return Response(chat_message=TextMessage(content=user_input, source=self.name))\n","\n",- " async def reset(self, cancellation_token: CancellationToken) -> None:\n",+ " async def on_reset(self, cancellation_token: CancellationToken) -> None:\n"," pass"]},@@ -281,7 +281,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.12.6"+ "version": "3.11.5"}},"nbformat": 4,