-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description
The Python SDK recently added enable_return_to_previous() to HandoffBuilder (PR #2037), which allows specialists to maintain control across multiple user turns without routing back through the coordinator. This feature is not available in the .NET SDK, making multi-turn handoff workflows significantly more difficult to implement.
Expected Behavior
When EnableReturnToPrevious() is enabled, user input should route directly back to the specialist agent that is currently handling the conversation, rather than always going through the coordinator for re-evaluation.
Flow with EnableReturnToPrevious(true):
User → Coordinator → Specialist → User → Specialist → User → Specialist → ...
Actual Behavior
Every user message always routes through the initial agent (coordinator/triage), even when a specialist agent is in the middle of a multi-turn conversation with the user.
Current flow:
User → Coordinator → Specialist → User → Coordinator → Specialist → ...
Example Problem
User: "I want to book an appointment"
→ Triage routes to Scheduler ✓
Scheduler: "What's your patient ID?"
User: "12345"
→ Triage receives this instead of Scheduler ✗
Triage: "What is the reason for your appointment?" ← Scheduler's job ideally
Python SDK Solution
The Python SDK solves this elegantly with enable_return_to_previous():
workflow = (
HandoffBuilder(participants=[triage, scheduler, inquiry])
.set_coordinator("triage_agent")
.add_handoff(triage, [scheduler, inquiry])
.enable_return_to_previous() # ← User input goes back to current specialist
.build()
)Implementation details from PR #2037:
_HandoffCoordinatortracks_current_agent_idto remember which agent is handling the conversation- When
_return_to_previousis enabled, user input routes to_current_agent_idinstead of_starting_agent_id - The current agent ID updates whenever a handoff occurs
Proposed .NET API
Workflow workflow = AgentWorkflowBuilder
.CreateHandoffBuilderWith(triageAgent)
.WithHandoffs(triageAgent, [schedulerAgent, inquiryAgent, researchAgent])
.WithHandoffs([schedulerAgent, inquiryAgent, researchAgent], triageAgent)
.EnableReturnToPrevious() // ← New method
.Build();Steps to Reproduce (Sample):
- Create agents for a patient scheduling scenario:
// Triage agent - routes to specialists based on user's request
ChatClientAgent triageAgent = new(
chatClient,
instructions: """
You are a receptionist that routes patients to the appropriate specialist .....
""",
name: "triage_agent",
description: "Routes to the appropriate specialist agent");
// Scheduler specialist
ChatClientAgent schedulerAgent = new(
chatClient,
instructions: """
You are an appointment scheduler ......
""",
name: "scheduler_agent",
description: "Specialist agent for bookingappointments");
// Information specialist
ChatClientAgent inquiryAgent = new(
chatClient,
instructions: """
You are information specialist.......
""",
name: "information_agent",
description: "Specialist agent forinformation and inquiries");- Create a handoff workflow:
Workflow workflow = AgentWorkflowBuilder
.CreateHandoffBuilderWith(triageAgent)
.WithHandoffs(triageAgent, [schedulerAgent, inquiryAgent])
.WithHandoffs([schedulerAgent, inquiryAgent], triageAgent)
.Build();- Run multi-turn conversation and observe the specialist cannot maintain context:
// Turn 1: User asks to book
messages.Add(new ChatMessage(ChatRole.User, "I want to book an appointment"));
messages = await RunWorkflowAsync(workflow, messages);
// Scheduler asks: "What's your ID?"
// Turn 2: User provides ID
messages.Add(new ChatMessage(ChatRole.User, "12345"));
messages = await RunWorkflowAsync(workflow, messages);
// Expected: Scheduler receives "12345" and continues booking flow
// Actual: Triage receives "12345" and re-routes, asking "What can I help you with?"Environment
- Agent Framework Version: 1.0.0-preview.251028.1
- .NET Version: 9.0 / 10.0
- OS: Windows
Additional Context
- Python PR that added this feature: #2037
- This is a parity gap between Python and .NET SDKs
- The feature is essential for real-world multi-agent scenarios (customer support, scheduling, intake workflows)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status