Repository navigation
Python: Read orchestration outputs as agent responses in tool approval samples - #10084
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
Conversation
…l samples Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the workflow sample response-handling updates.
No open issues 🎉
What changed in this PR
Updates four Python workflow samples to consume the response types emitted by orchestration builders, fixing crashes caused by treating outputs as message lists.
Changes:
- Sequential and group chat approval samples combine streamed
AgentResponseUpdatevalues and print messages containing text. - Concurrent samples read messages from
AgentResponse.messages. - Imports and output comments are updated to match the corrected handling.
| File | Description |
|---|---|
python/samples/03-workflows/tool-approval/sequential_builder_tool_approval.py |
Builds the summary from the final participant’s streamed response. |
python/samples/03-workflows/tool-approval/group_chat_builder_tool_approval.py |
Combines streamed response updates and skips messages without text. |
python/samples/03-workflows/tool-approval/concurrent_builder_tool_approval.py |
Validates AgentResponse output and reads its messages. |
python/samples/03-workflows/orchestrations/concurrent_custom_agent_executors.py |
Reads aggregated messages from the workflow’s AgentResponse. |
Review effort: Balanced
| print("===== Final Aggregated Conversation (messages) =====") | ||
| messages: list[Message] | Any = outputs[0] # Get the first (and typically only) output | ||
| for i, msg in enumerate(messages, start=1): | ||
| response = cast(AgentResponse, outputs[0]) # The aggregated conversation |
There was a problem hiding this comment.
Naveen Chatlapalli (@1aifanatic), this correctly switches the code to AgentResponse, but the sample docstring and expected-output block still describe the old list[Message] behavior and show a user message that this loop no longer prints. The same stale expected-output wording remains in the changed sequential and concurrent approval samples. Please update those docs to match the actual AgentResponse / AgentResponseUpdate output.
Motivation & Context
Four orchestration samples treat workflow
outputevents as alist[Message]. Sequential, group chat and concurrent orchestrations emitAgentResponseUpdatevalues while streaming and anAgentResponseotherwise, so each sample crashes when the output arrives. In the three tool-approval samples that happens after the approval has already gone through:maintool-approval/sequential_builder_tool_approval.pyTypeError: 'AgentResponseUpdate' object is not iterabletool-approval/group_chat_builder_tool_approval.pyTypeError: 'AgentResponseUpdate' object is not iterabletool-approval/concurrent_builder_tool_approval.pyTypeError: 'AgentResponse' object is not iterable(after the "not a list of Message" check is skipped by itsand)orchestrations/concurrent_custom_agent_executors.pyTypeError: 'AgentResponse' object is not iterableDescription & Review Guide
AgentResponseUpdateoutputs and print the summary fromAgentResponse.from_updates(...), skipping messages with no text, such as the tool call..messagesfrom theAgentResponse, asconcurrent_agents.pyalready does.Verification: I replaced the Foundry client with a scripted stub that first calls the approval-required tool and answers once the result comes back. Each sample then goes through the approval request, the simulated approval and the final summary, for example
Workflow summary: [DatabaseAgent]: Stub final answer.The unmodified files crash with the errors above under the same stub. Ruff and the repo'spyrightconfig.samples.json(with--warnings) are clean.Related Issue
N/A - trivial change: samples are updated to the output types the orchestrations already emit.
AI Assistance
AI assistance details: Claude Code helped find the crashes by running the samples against a stub client, update the output handling, re-run the approval flow, and draft this description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.🤖 Generated with Claude Code