Python: Fix Responses API handoff state handling and add focused tests#4057
Open
alliscode wants to merge 2 commits intomicrosoft:mainfrom
Open
Python: Fix Responses API handoff state handling and add focused tests#4057alliscode wants to merge 2 commits intomicrosoft:mainfrom
alliscode wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes two critical bugs in the HandoffBuilder's handling of Responses API-style clients, ensuring conversation context and session state are correctly managed across agent handoffs. The fixes prevent "No tool output found" API errors and restore complete conversation history to agents after handoffs.
Changes:
- Fixed stale
previous_response_idissue by clearingservice_session_idafter handoffs - Restored full conversation context by passing
_full_conversationto agents instead of partial_cache - Added comprehensive regression tests with Responses API mock to prevent future regressions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
python/packages/orchestrations/tests/test_handoff_responses.py |
New test suite with mock Responses API client to verify handoff invariants: session clearing and context preservation |
python/packages/orchestrations/agent_framework_orchestrations/_handoff.py |
Two-line fix: copy full conversation to cache before agent runs, and clear service_session_id after handoffs |
TaoChenOSU
reviewed
Feb 19, 2026
| # from being sent on the next run. The handoff response contained a function_call | ||
| # for the handoff tool; referencing it via previous_response_id after the tool | ||
| # output has been cleaned would cause "No tool output found" API errors. | ||
| if self._session and self._session.service_session_id: |
Contributor
There was a problem hiding this comment.
Is this like saying each time it will create a new session in the service?
Contributor
|
I've got these same fixes in #3911, plus others that I found through testing workflows with handoff + AG-UI. We could add the regression tests from yours to 3911. |
moonbox3
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request addresses critical issues with agent handoff behavior when using Responses API-style clients, ensuring conversation context and session state are correctly managed across handoffs. It introduces regression tests to verify these invariants and updates the orchestration logic to prevent context loss and stale session IDs that could cause API errors.
Bug fixes for handoff and session management:
_full_conversation) as input after a handoff, rather than just the latest broadcast, to preserve context for APIs like the Responses API.service_session_idafter a handoff to prevent sending a staleprevious_response_id, which could otherwise cause "No tool output found" errors with the Responses API.Testing and regression coverage:
test_handoff_responses.py) with regression tests to verify that (1) handoffs correctly clear the session's conversation pointer and (2) agents receive the complete conversation context after a handoff. This includes a mock client and agent simulating Responses API behavior.Closes #4053
Contribution Checklist