Skip to content

A programming framework for agentic AI

Fix message ID for correlation between streaming chunks and final mes… (#6969)

gym60331078550445f
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.py
index b1b1c7b57..8b8316fb0 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
@@ -972,9 +972,11 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
# --- NEW: If the model produced a hidden "thought," yield it as an event ---
if model_result.thought:
- thought_event = ThoughtEvent(content=model_result.thought, source=agent_name)
+ thought_event = ThoughtEvent(content=model_result.thought, source=agent_name, id=message_id)
yield thought_event
inner_messages.append(thought_event)
+ # Regenerate the message ID for correlation between streaming chunks and final message
+ message_id = str(uuid.uuid4())
# Add the assistant message to the model context (including thought if present)
await model_context.add_message(
@@ -1281,9 +1283,11 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
# Yield thought event if present
if current_model_result.thought:
- thought_event = ThoughtEvent(content=current_model_result.thought, source=agent_name)
+ thought_event = ThoughtEvent(content=current_model_result.thought, source=agent_name, id=message_id)
yield thought_event
inner_messages.append(thought_event)
+ # Regenerate the message ID for correlation between streaming chunks and final message
+ message_id = str(uuid.uuid4())
# Add the assistant message to the model context (including thought if present)
await model_context.add_message(