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
feat: introduce ModelClientStreamingChunkEvent for streaming model output and update handling in agents and console (microsoft#5208)
Resolvesmicrosoft#3983
* introduce `model_client_stream` parameter in `AssistantAgent` to
enable token-level streaming output.
* introduce `ModelClientStreamingChunkEvent` as a type of `AgentEvent`
to pass the streaming chunks to the application via `run_stream` and
`on_messages_stream`. Although this will not affect the inner messages
list in the final `Response` or `TaskResult`.
* handle this new message type in `Console`.
messages as the model client produces chunks of response.
138
+
The chunk messages will not be included in the final response's inner messages.
139
+
129
140
130
141
Args:
131
142
name (str): The name of the agent.
@@ -138,6 +149,9 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
138
149
model_context (ChatCompletionContext | None, optional): The model context for storing and retrieving :class:`~autogen_core.models.LLMMessage`. It can be preloaded with initial messages. The initial messages will be cleared when the agent is reset.
139
150
description (str, optional): The description of the agent.
140
151
system_message (str, optional): The system message for the model. If provided, it will be prepended to the messages in the model context when making an inference. Set to `None` to disable.
152
+
model_client_stream (bool, optional): If `True`, the model client will be used in streaming mode.
153
+
:meth:`on_messages_stream` and :meth:`BaseChatAgent.run_stream` methods will also yield :class:`~autogen_agentchat.messages.ModelClientStreamingChunkEvent`
154
+
messages as the model client produces chunks of response. Defaults to `False`.
141
155
reflect_on_tool_use (bool, optional): If `True`, the agent will make another model inference using the tool call and result
142
156
to generate a response. If `False`, the tool call result will be returned as the response. Defaults to `False`.
143
157
tool_call_summary_format (str, optional): The format string used to create a tool call summary for every tool call result.
@@ -268,12 +282,14 @@ def __init__(
268
282
system_message: (
269
283
str|None
270
284
) ="You are a helpful AI assistant. Solve tasks using your tools. Reply with TERMINATE when the task has been completed.",
Copy file name to clipboardexpand all lines: python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py
+17-2
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@
21
21
22
22
from ... importEVENT_LOGGER_NAME
23
23
from ...baseimportChatAgent, TaskResult, Team, TerminationCondition
24
-
from ...messagesimportAgentEvent, BaseChatMessage, ChatMessage, TextMessage
24
+
from ...messagesimportAgentEvent, BaseChatMessage, ChatMessage, ModelClientStreamingChunkEvent, TextMessage
25
25
from ...stateimportTeamState
26
26
from ._chat_agent_containerimportChatAgentContainer
27
27
from ._eventsimportGroupChatMessage, GroupChatReset, GroupChatStart, GroupChatTermination
@@ -190,6 +190,9 @@ async def run(
190
190
and it may not reset the termination condition.
191
191
To gracefully stop the team, use :class:`~autogen_agentchat.conditions.ExternalTermination` instead.
192
192
193
+
Returns:
194
+
result: The result of the task as :class:`~autogen_agentchat.base.TaskResult`. The result contains the messages produced by the team and the stop reason.
195
+
193
196
Example using the :class:`~autogen_agentchat.teams.RoundRobinGroupChat` team:
task (str | ChatMessage | Sequence[ChatMessage] | None): The task to run the team with. Can be a string, a single :class:`ChatMessage` , or a list of :class:`ChatMessage`.
287
296
cancellation_token (CancellationToken | None): The cancellation token to kill the task immediately.
288
297
Setting the cancellation token potentially put the team in an inconsistent state,
289
298
and it may not reset the termination condition.
290
299
To gracefully stop the team, use :class:`~autogen_agentchat.conditions.ExternalTermination` instead.
291
300
301
+
Returns:
302
+
stream: an :class:`~collections.abc.AsyncGenerator` that yields :class:`~autogen_agentchat.messages.AgentEvent`, :class:`~autogen_agentchat.messages.ChatMessage`, and the final result :class:`~autogen_agentchat.base.TaskResult` as the last item in the stream.
303
+
292
304
Example using the :class:`~autogen_agentchat.teams.RoundRobinGroupChat` team:
0 commit comments