Python: [Breaking] Python: Respond with AgentRunResponse with serialized structured output#2285
Conversation
AgentRunResponse with serialized structured outputAgentRunResponse with serialized structured output
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a breaking change to make DurableAIAgent.run() return AgentRunResponse instead of raw dictionaries, aligning with the agent-framework protocols and bringing parity with the .NET experience. The key changes include:
- Modified
DurableAIAgent.run()to use generator protocol (yield from) and return typedAgentRunResponse - Removed the
AgentResponsewrapper class in favor of usingAgentRunResponsedirectly with metadata inadditional_properties - Deserialization of structured output (
response.value) now happens in the orchestration layer via_ensure_response_format() - Updated all samples and tests to use
yield fromsyntax and access structured responses via.valueproperty
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py | Added generator-based run() method returning AgentRunResponse, with helper methods _load_agent_response() and _ensure_response_format() for response handling and structured output parsing |
| python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py | Modified run_agent() to return AgentRunResponse directly, removed JSON parsing logic (now handled at orchestration layer), updated metadata handling via additional_properties |
| python/packages/azurefunctions/agent_framework_azurefunctions/_models.py | Removed AgentResponse dataclass as it's replaced by AgentRunResponse |
| python/samples/getting_started/azure_functions/04_single_agent_orchestration_chaining/function_app.py | Updated to use yield from and access response via .text property |
| python/samples/getting_started/azure_functions/05_multi_agent_orchestration_concurrency/function_app.py | Updated to manually advance generators for concurrent execution, accessing results via .text property |
| python/samples/getting_started/azure_functions/06_multi_agent_orchestration_conditionals/function_app.py | Updated to use yield from and access structured responses via .value property, removed _coerce_structured() helper |
| python/samples/getting_started/azure_functions/07_single_agent_orchestration_hitl/function_app.py | Updated to use yield from and access structured responses via .value property with validation, removed _coerce_generated_content() helper |
| python/packages/azurefunctions/tests/test_orchestration.py | Added tests for _load_agent_response() helper method covering instance, serialized, and None cases |
| python/packages/azurefunctions/tests/test_models.py | Removed all tests for the deleted AgentResponse class |
| python/packages/azurefunctions/tests/test_entities.py | Updated assertions to check AgentRunResponse type and access metadata via additional_properties |
| python/packages/azurefunctions/tests/test_app.py | Updated assertions to check AgentRunResponse type and access metadata via additional_properties |
...n/samples/getting_started/azure_functions/07_single_agent_orchestration_hitl/function_app.py
Outdated
Show resolved
Hide resolved
...n/samples/getting_started/azure_functions/07_single_agent_orchestration_hitl/function_app.py
Outdated
Show resolved
Hide resolved
...les/getting_started/azure_functions/05_multi_agent_orchestration_concurrency/function_app.py
Outdated
Show resolved
Hide resolved
...les/getting_started/azure_functions/05_multi_agent_orchestration_concurrency/function_app.py
Outdated
Show resolved
Hide resolved
...les/getting_started/azure_functions/05_multi_agent_orchestration_concurrency/function_app.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
...les/getting_started/azure_functions/05_multi_agent_orchestration_concurrency/function_app.py
Outdated
Show resolved
Hide resolved
...n/samples/getting_started/azure_functions/07_single_agent_orchestration_hitl/function_app.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
cgillum
left a comment
There was a problem hiding this comment.
In addition to the feedback below, can we open an issue to track updating the snippets lab (the one we used for Ignite) to account for these breaking changes?
python/packages/azurefunctions/agent_framework_azurefunctions/_entities.py
Show resolved
Hide resolved
...les/getting_started/azure_functions/05_multi_agent_orchestration_concurrency/function_app.py
Outdated
Show resolved
Hide resolved
Opened an issue #2435 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
cgillum
left a comment
There was a problem hiding this comment.
The latest version looks great! Just one comment to fix up the sample.
...les/getting_started/azure_functions/05_multi_agent_orchestration_concurrency/function_app.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py
Outdated
Show resolved
Hide resolved
…lized structured output (microsoft#2285) * Respond with AgentRunResponse * Fix response_Format type * Address comments * Fix tests * Fix log * Addressed comments * Code cleanup * Use AgentTask vs Generator * Address comments * use lazy logging * fix mypy errors
Motivation and Context
DurableAIAgent.runfunction to respond withAgentRunResponserather thanAnyto be more in line with agent-framework's protocols.response.valueas part of the agent run, making it easier for the customer to author their codes.AgentResponse).Description
The changes bring parity with Dotnet experience and also with agent-framework in general.
This introduces a breaking change where now we need to use
yield fromwhen calling theDurableAIAgent(vs justyieldbefore) -Additionally, the responses are now of type
AgentRunResponseand the structured response is stored inAgentRunResponse.value(as opposed toresponse["structured_response"]before).Contribution Checklist