[BREAKING] Python: Fix handoff workflow context management and improve AG-UI demo#5136
Open
moonbox3 wants to merge 1 commit intomicrosoft:mainfrom
Open
[BREAKING] Python: Fix handoff workflow context management and improve AG-UI demo#5136moonbox3 wants to merge 1 commit intomicrosoft:mainfrom
moonbox3 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
Author
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes multiple Python handoff-workflow context management issues (duplicate history, stale/partial context after handoff, and replay of tool artifacts/IDs), and updates the AG-UI handoff demo + samples/tests to align with the new handoff persistence requirements.
Changes:
- Refactors
HandoffAgentExecutorcontext handling and adds a build-time validation requiringrequire_per_service_call_history_persistence=Truefor all handoff participants. - Improves core workflow runtime behavior (message delivery ordering helper placement; warnings when running agents with an empty cache).
- Updates handoff samples + AG-UI demo UI/backend to reflect new behavior and provide clearer demo lifecycle semantics.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| python/uv.lock | Adjusts dependency markers (notably for pythonnet/cffi) for Python version gating. |
| python/packages/orchestrations/agent_framework_orchestrations/_handoff.py | Refactors handoff executor behavior, removes forced store=False, adds build-time validation for per-service-call history persistence. |
| python/packages/orchestrations/agent_framework_orchestrations/_orchestrator_helpers.py | Expands docs/notes for clean_conversation_for_handoff. |
| python/packages/core/agent_framework/_workflows/_runner.py | Refactors message delivery helper placement (no behavior change intended beyond flow ordering). |
| python/packages/core/agent_framework/_workflows/_agent_executor.py | Adds warnings when running an agent with an empty message cache (streaming + non-streaming). |
| python/packages/orchestrations/tests/test_handoff.py | Updates unit/integration tests for new handoff requirements and client usage; adds validation test. |
| python/packages/a2a/tests/test_a2a_agent.py | Formatting-only adjustments in test setup arrays. |
| python/samples/03-workflows/orchestrations/README.md | Documents the new require_per_service_call_history_persistence handoff requirement. |
| python/samples/03-workflows/orchestrations/handoff_simple.py | Sets require_per_service_call_history_persistence=True on all participants. |
| python/samples/03-workflows/orchestrations/handoff_autonomous.py | Sets require_per_service_call_history_persistence=True on all participants. |
| python/samples/03-workflows/orchestrations/handoff_with_tool_approval_checkpoint_resume.py | Sets require_per_service_call_history_persistence=True on all participants. |
| python/samples/03-workflows/orchestrations/handoff_with_code_interpreter_file.py | Sets require_per_service_call_history_persistence=True on all participants. |
| python/samples/03-workflows/agents/handoff_workflow_as_agent.py | Sets require_per_service_call_history_persistence=True on all participants. |
| python/samples/autogen-migration/orchestrations/03_swarm.py | Sets require_per_service_call_history_persistence=True on all participants. |
| python/samples/semantic-kernel-migration/orchestrations/handoff.py | Sets require_per_service_call_history_persistence=True on all participants. |
| python/samples/05-end-to-end/ag_ui_workflow_handoff/README.md | Adds demo lifecycle notes and documents the per-service-call persistence requirement. |
| python/samples/05-end-to-end/ag_ui_workflow_handoff/frontend/src/styles.css | Adds styling for “Start New Case” and pending empty state. |
| python/samples/05-end-to-end/ag_ui_workflow_handoff/frontend/src/App.tsx | Adds “case closed” behavior and a UI reset path for starting a new thread/case. |
| python/samples/05-end-to-end/ag_ui_workflow_handoff/backend/server.py | Wraps the workflow to block new top-level input on completed threads; adds closed-case notice workflow. |
python/packages/orchestrations/agent_framework_orchestrations/_handoff.py
Show resolved
Hide resolved
python/packages/orchestrations/agent_framework_orchestrations/_handoff.py
Show resolved
Hide resolved
python/packages/orchestrations/agent_framework_orchestrations/_handoff.py
Show resolved
Hide resolved
4 tasks
eavanvalkenburg
approved these changes
Apr 7, 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.
Motivation and Context
Supersedes #4509
Addresses #4695, #4053, #4357
Handoff workflows had several context management bugs:
_full_conversationacross turns (Python: [Bug]: Duplicate messages in Handoff workflow #4695)previous_response_idand partial cache (Python: [Bug]: HandoffBuilder with AzureOpenAIResponsesClient fails with stale previous_response_id and loses conversation context on handoff #4053)rs_*,fc_*) replayed understore=False, causing API errors (Python: [Bug]: Handoff workflow with store=False sends server-assigned item IDs (rs_*, fc_*) in input, causing "Item not found" API errors #4357)Important
HandoffBuilder.build()now requires all participant agents to setrequire_per_service_call_history_persistence=True. Existing code that constructs handoff workflows without this flag will raise aValueErrorat build time with a message identifying which agents need updating. This is a one-line fix per agent constructor. This breaking change only affects theagent-framework-orchestrationspackage, which is still in beta.Description
Handoff context management (
_handoff.py):_run_agent_and_emit— removed cache manipulation, stale session clearing, and runtime tool message tracking_full_conversationnow only stores cleaned (text-only) responses viaclean_conversation_for_handoff, preventing tool content with server-assigned IDs from being replayedstore=Falseon cloned agents — users now control storage behavior_persist_pending_approval_function_callsand_persist_missing_approved_function_results(no longer needed)_is_handoff_requestedto return the handoff message so it can be appended to the cache for call/result pairingrequire_per_service_call_history_persistence=Trueon all handoff participantsCore workflow improvements:
AgentExecutor._run_agentand_run_agent_streaming_deliver_messages_for_edge_runnerbefore early return in_runner.pyArgs/Returnsdocstring and TODO toclean_conversation_for_handoffAG-UI handoff demo (
samples/05-end-to-end/ag_ui_workflow_handoff):require_per_service_call_history_persistence=Trueon all agentsSamples and tests:
require_per_service_call_history_persistence=TrueFoundryChatClientinstead of removedAzureOpenAIResponsesClientrequire_per_service_call_history_persistencerequirementstore=Falseforcing, stale session clearing, persist methods)Contribution Checklist