Python: Support an autonomous handoff flow#2497
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds autonomous interaction mode to the handoff workflow, allowing agents to iterate on tasks without returning to the user after each response. The key change enables specialists to perform long-running work (research, analysis, coding) until they explicitly invoke a handoff tool or reach a configured turn limit.
Key Changes:
- Added
with_interaction_mode()builder method to support "autonomous" and "human_in_loop" modes - Added
with_autonomous_turn_limit()to cap iterations and prevent runaway agents (default: 50) - Modified handoff coordinator to route responses back to the same agent in autonomous mode instead of requesting user input
- Turn counter resets on handoffs and new user input to track continuous autonomous execution
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/samples/getting_started/workflows/orchestration/handoff_autonomous.py | New sample demonstrating autonomous mode with research agent that iterates multiple times before handing back to coordinator |
| python/samples/getting_started/workflows/README.md | Added documentation entry for the new autonomous handoff sample |
| python/packages/core/tests/workflow/test_handoff.py | Added comprehensive unit tests covering autonomous mode behavior, turn limits, and routing without user input |
| python/packages/core/agent_framework/_workflows/_handoff.py | Core implementation of autonomous interaction mode in HandoffCoordinator and HandoffBuilder |
| python/samples/getting_started/workflows/agents/group_chat_workflow_as_agent.py | Unrelated refactoring: updated to use set_manager() instead of deprecated set_prompt_based_manager() |
| python/samples/autogen-migration/orchestrations/02_selector_group_chat.py | Unrelated refactoring: updated to use set_manager() instead of deprecated set_prompt_based_manager() |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
python/samples/getting_started/workflows/orchestration/handoff_autonomous.py
Show resolved
Hide resolved
python/samples/getting_started/workflows/orchestration/handoff_autonomous.py
Outdated
Show resolved
Hide resolved
|
Hi, will this be implemented for C# as well? I have a similar issue using specialized autonomous agents in my project where handoff defaults to user input. |
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Thanks for the feedback, @MrAssel. I will file an issue to track it for .NET. |
* Support an autonomous handoff flow. * Simplify public API * Address feedback
Motivation and Context
Right now the Handoff pattern requires a HITL as it passes back control to a human when no handoff is triggered. Per feedback, we should also support an autonomous mode where a sub-agent is able to iterate until done, and then handoff to the next agent.
Description
Adding ability to support an interaction mode of either "autonomous" or "human_in_the_loop" (this is the default).
Devs can now specify the autonomous mode:
There are some public API args (like
with_autonomous_turn_limit) to act as guards so that we don't have runaway agentsContribution Checklist