Skip to content

Commit 3107855

Browse files
smalltalkmanekzhu
andauthored
Fix message ID for correlation between streaming chunks and final mes… (#6969)
Co-authored-by: Eric Zhu <[email protected]>
1 parent 8e2c5f0 commit 3107855

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,9 +972,11 @@ async def on_messages_stream(
972972

973973
# --- NEW: If the model produced a hidden "thought," yield it as an event ---
974974
if model_result.thought:
975-
thought_event = ThoughtEvent(content=model_result.thought, source=agent_name)
975+
thought_event = ThoughtEvent(content=model_result.thought, source=agent_name, id=message_id)
976976
yield thought_event
977977
inner_messages.append(thought_event)
978+
# Regenerate the message ID for correlation between streaming chunks and final message
979+
message_id = str(uuid.uuid4())
978980

979981
# Add the assistant message to the model context (including thought if present)
980982
await model_context.add_message(
@@ -1281,9 +1283,11 @@ async def _execute_tool_calls(
12811283

12821284
# Yield thought event if present
12831285
if current_model_result.thought:
1284-
thought_event = ThoughtEvent(content=current_model_result.thought, source=agent_name)
1286+
thought_event = ThoughtEvent(content=current_model_result.thought, source=agent_name, id=message_id)
12851287
yield thought_event
12861288
inner_messages.append(thought_event)
1289+
# Regenerate the message ID for correlation between streaming chunks and final message
1290+
message_id = str(uuid.uuid4())
12871291

12881292
# Add the assistant message to the model context (including thought if present)
12891293
await model_context.add_message(

0 commit comments

Comments
 (0)