Skip to content

Python: [Breaking] Python: Respond with AgentRunResponse with serialized structured output#2285

Merged
larohra merged 21 commits intomicrosoft:mainfrom
larohra:fix-func-agent-response
Nov 26, 2025
Merged

Python: [Breaking] Python: Respond with AgentRunResponse with serialized structured output#2285
larohra merged 21 commits intomicrosoft:mainfrom
larohra:fix-func-agent-response

Conversation

@larohra
Copy link
Contributor

@larohra larohra commented Nov 17, 2025

Motivation and Context

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 from when calling the DurableAIAgent (vs just yield before) -

initial_raw = yield from writer.run(
        messages=f"Write a short article about '{payload.topic}'.",
        thread=writer_thread,
        response_format=GeneratedContent,
    )

Additionally, the responses are now of type AgentRunResponse and the structured response is stored in AgentRunResponse.value (as opposed to response["structured_response"] before).

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@larohra larohra requested a review from a team as a code owner November 17, 2025 22:21
Copilot AI review requested due to automatic review settings November 17, 2025 22:21
@larohra larohra added the azure-functions Issues and PRs related to Azure Functions label Nov 17, 2025
@github-actions github-actions bot changed the title [Breaking] Python: Respond with AgentRunResponse with serialized structured output Python: [Breaking] Python: Respond with AgentRunResponse with serialized structured output Nov 17, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Nov 17, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azurefunctions/agent_framework_azurefunctions
   _entities.py1792188%120, 160–161, 212, 220, 225–226, 253–254, 263, 270, 281, 287–288, 307–308, 378, 410–412, 414
   _models.py1501292%204, 207, 210, 222, 225, 244, 247, 252, 257, 274, 329, 348
   _orchestration.py871879%168, 173, 175–176, 178, 193, 202–203, 205, 261, 266–273
TOTAL15449236084% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2220 130 💤 0 ❌ 0 🔥 53.413s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 typed AgentRunResponse
  • Removed the AgentResponse wrapper class in favor of using AgentRunResponse directly with metadata in additional_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 from syntax and access structured responses via .value property

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@larohra
Copy link
Contributor Author

larohra commented Nov 24, 2025

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?

Opened an issue #2435

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest version looks great! Just one comment to fix up the sample.

@larohra larohra added this pull request to the merge queue Nov 26, 2025
Merged via the queue into microsoft:main with commit 306c81a Nov 26, 2025
23 checks passed
@larohra larohra deleted the fix-func-agent-response branch November 26, 2025 18:50
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-functions Issues and PRs related to Azure Functions python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants