Skip to content

Commit

Permalink
reset --> on_reset :D (#4121)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhu authored Nov 11, 2024
1 parent 12becdd commit 8f7c717
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,6 @@ async def _execute_tool_call(
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()
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ async def run_stream(
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."""
...
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token:
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."""
pass
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def on_messages_stream(
# 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def on_messages_stream(
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."""
...
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def handle_agent_response(self, message: GroupChatAgentResponse, ctx: Mess
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)

@event
async def handle_request(self, message: GroupChatRequestPublish, ctx: MessageContext) -> None:
Expand Down
4 changes: 2 additions & 2 deletions python/packages/autogen-agentchat/tests/test_group_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token:
assert self._last_message is not None
return 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


Expand Down Expand Up @@ -633,7 +633,7 @@ async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token:
)
)

async def reset(self, cancellation_token: CancellationToken) -> None:
async def on_reset(self, cancellation_token: CancellationToken) -> None:
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -281,7 +281,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 8f7c717

Please sign in to comment.