You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add tool_call_summary_msg_format_fct and test (microsoft#6460)
## Why are these changes needed?
This change introduces support for dynamic formatting of tool call
summary messages by allowing a user-defined
`tool_call_summary_format_fct`. Instead of relying solely on a static
string template, this function enables runtime generation of summary
messages based on the specific tool call and its result. This provides
greater flexibility and cleaner integration without introducing any
breaking changes.
### My Use Case / Problem
In my use case, I needed concise summaries for successful tool calls and
detailed messages for failures. The existing static summary string
didn't allow conditional formatting, which led to overly verbose success
messages or inconsistent failure outputs. This change allows customizing
summaries per result type, solving that limitation cleanly.
## Related issue number
Closesmicrosoft#6426
## Checks
- [x] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [x] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [x] I've made sure all auto checks have passed.
---------
Co-authored-by: Chris Wieczorek <Chris.Wieczorek@iav.de>
Co-authored-by: EeS <chiyoung.song@motov.co.kr>
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
Co-authored-by: Mehrsa Golestaneh <mehrsa.golestaneh@gmail.com>
Co-authored-by: Mehrsa Golestaneh <mgolestaneh@microsoft.com>
Co-authored-by: Zhenyu <81767213+Dormiveglia-elf@users.noreply.github.com>
Copy file name to clipboardExpand all lines: python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py
+52-20Lines changed: 52 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -131,17 +131,26 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
131
131
132
132
* If the model returns no tool call, then the response is immediately returned as a :class:`~autogen_agentchat.messages.TextMessage` or a :class:`~autogen_agentchat.messages.StructuredMessage` (when using structured output) in :attr:`~autogen_agentchat.base.Response.chat_message`.
133
133
* When the model returns tool calls, they will be executed right away:
134
-
- When `reflect_on_tool_use` is False, the tool call results are returned as a :class:`~autogen_agentchat.messages.ToolCallSummaryMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`. `tool_call_summary_format` can be used to customize the tool call summary.
134
+
- When `reflect_on_tool_use` is False, the tool call results are returned as a :class:`~autogen_agentchat.messages.ToolCallSummaryMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`. You can customise the summary with either a static format string (`tool_call_summary_format`) **or** a callable (`tool_call_summary_formatter`); the callable is evaluated once per tool call.
135
135
- When `reflect_on_tool_use` is True, the another model inference is made using the tool calls and results, and final response is returned as a :class:`~autogen_agentchat.messages.TextMessage` or a :class:`~autogen_agentchat.messages.StructuredMessage` (when using structured output) in :attr:`~autogen_agentchat.base.Response.chat_message`.
136
136
- `reflect_on_tool_use` is set to `True` by default when `output_content_type` is set.
137
137
- `reflect_on_tool_use` is set to `False` by default when `output_content_type` is not set.
138
138
* If the model returns multiple tool calls, they will be executed concurrently. To disable parallel tool calls you need to configure the model client. For example, set `parallel_tool_calls=False` for :class:`~autogen_ext.models.openai.OpenAIChatCompletionClient` and :class:`~autogen_ext.models.openai.AzureOpenAIChatCompletionClient`.
139
139
140
140
.. tip::
141
-
By default, the tool call results are returned as response when tool calls are made.
142
-
So it is recommended to pay attention to the formatting of the tools return values,
143
-
especially if another agent is expecting them in a specific format.
144
-
Use `tool_call_summary_format` to customize the tool call summary, if needed.
141
+
142
+
By default, the tool call results are returned as the response when tool
143
+
calls are made, so pay close attention to how the tools’ return values
144
+
are formatted—especially if another agent expects a specific schema.
145
+
146
+
* Use **`tool_call_summary_format`** for a simple static template.
147
+
* Use **`tool_call_summary_formatter`** for full programmatic control
148
+
(e.g., “hide large success payloads, show full details on error”).
149
+
150
+
*Note*: `tool_call_summary_formatter` is **not serializable** and will
151
+
be ignored when an agent is loaded from, or exported to, YAML/JSON
152
+
configuration files.
153
+
145
154
146
155
**Hand off behavior:**
147
156
@@ -199,13 +208,22 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
199
208
If this is set, the agent will respond with a :class:`~autogen_agentchat.messages.StructuredMessage` instead of a :class:`~autogen_agentchat.messages.TextMessage`
200
209
in the final response, unless `reflect_on_tool_use` is `False` and a tool call is made.
201
210
output_content_type_format (str | None, optional): (Experimental) The format string used for the content of a :class:`~autogen_agentchat.messages.StructuredMessage` response.
202
-
tool_call_summary_format (str, optional): The format string used to create the content for a :class:`~autogen_agentchat.messages.ToolCallSummaryMessage` response.
203
-
The format string is used to format the tool call summary for every tool call result.
204
-
Defaults to "{result}".
205
-
When `reflect_on_tool_use` is `False`, a concatenation of all the tool call summaries, separated by a new line character ('\\n')
206
-
will be returned as the response.
207
-
Available variables: `{tool_name}`, `{arguments}`, `{result}`.
208
-
For example, `"{tool_name}: {result}"` will create a summary like `"tool_name: result"`.
211
+
tool_call_summary_format (str, optional): Static format string applied to each tool call result when composing the :class:`~autogen_agentchat.messages.ToolCallSummaryMessage`.
212
+
Defaults to ``"{result}"``. Ignored if `tool_call_summary_formatter` is provided. When `reflect_on_tool_use` is ``False``, the summaries for all tool
213
+
calls are concatenated with a newline ('\\n') and returned as the response. Placeholders available in the template:
0 commit comments