Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool call result summary message #4755

Merged
merged 13 commits into from
Dec 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TextMessage,
ToolCallMessage,
ToolCallResultMessage,
ToolCallResultSummaryMessage,
)
from ..state import AssistantAgentState
from ._base_chat_agent import BaseChatAgent
Expand Down Expand Up @@ -62,7 +63,7 @@ class AssistantAgent(BaseChatAgent):

* If the model returns no tool call, then the response is immediately returned as a :class:`~autogen_agentchat.messages.TextMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`.
* When the model returns tool calls, they will be executed right away:
- When `reflect_on_tool_use` is False (default), the tool call results are returned as a :class:`~autogen_agentchat.messages.TextMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`. `tool_call_summary_format` can be used to customize the tool call summary.
- When `reflect_on_tool_use` is False (default), the tool call results are returned as a :class:`~autogen_agentchat.messages.ToolCallResultSummaryMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`. `tool_call_summary_format` can be used to customize the tool call summary.
- When `reflect_on_tool_use` is True, the another model inference is made using the tool calls and results, and the text response is returned as a :class:`~autogen_agentchat.messages.TextMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`.

Hand off behavior:
Expand Down Expand Up @@ -379,7 +380,7 @@ async def on_messages_stream(
)
tool_call_summary = "\n".join(tool_call_summaries)
yield Response(
chat_message=TextMessage(content=tool_call_summary, source=self.name),
chat_message=ToolCallResultSummaryMessage(content=tool_call_summary, source=self.name),
inner_messages=inner_messages,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,21 @@ class ToolCallResultMessage(BaseMessage):
type: Literal["ToolCallResultMessage"] = "ToolCallResultMessage"


class ToolCallResultSummaryMessage(BaseMessage):
"""A message signaling the summary of tool call results."""

content: str
"""Summary of the the tool call results."""

type: Literal["ToolCallResultSummaryMessage"] = "ToolCallResultSummaryMessage"


ChatMessage = Annotated[TextMessage | MultiModalMessage | StopMessage | HandoffMessage, Field(discriminator="type")]
"""Messages for agent-to-agent communication."""


AgentMessage = Annotated[
TextMessage | MultiModalMessage | StopMessage | HandoffMessage | ToolCallMessage | ToolCallResultMessage,
TextMessage | MultiModalMessage | StopMessage | HandoffMessage | ToolCallMessage | ToolCallResultMessage | ToolCallResultSummaryMessage,
Field(discriminator="type"),
]
"""All message types."""
Expand All @@ -100,6 +109,7 @@ class ToolCallResultMessage(BaseMessage):
"HandoffMessage",
"ToolCallMessage",
"ToolCallResultMessage",
"ToolCallResultSummaryMessage",
"ChatMessage",
"AgentMessage",
]