applyForceHandoff routes the conversation to the agent's configured force_handoff target after a natural stop, bypassing the LLM's tool-calling entirely. The conversation context carries over because the same session keeps running; an implicit user message tells the target agent what happened so the
(ctx context.Context, sess *session.Session, from, to *agent.Agent)
| 615 | // continuing the run loop, where the next iteration re-resolves the |
| 616 | // current agent and emits the AgentInfo event. |
| 617 | func (r *LocalRuntime) applyForceHandoff(ctx context.Context, sess *session.Session, from, to *agent.Agent) { |
| 618 | slog.InfoContext(ctx, "Forced handoff", "from_agent", from.Name(), "to_agent", to.Name(), "session_id", sess.ID) |
| 619 | |
| 620 | r.executeOnAgentSwitchHooks(ctx, from, sess.ID, from.Name(), to.Name(), agentSwitchKindForceHandoff) |
| 621 | r.setCurrentAgent(to.Name()) |
| 622 | |
| 623 | sess.AddMessage(session.ImplicitUserMessage( |
| 624 | "The agent " + from.Name() + " finished its response and the conversation was automatically " + |
| 625 | "handed off to you. Your available handoff agents and tools are specified in the system " + |
| 626 | "messages that follow. Only use those capabilities - do not attempt to use tools or hand " + |
| 627 | "off to agents that you see in the conversation history from previous agents, as those were " + |
| 628 | "available to different agents with different capabilities. Look at the conversation history " + |
| 629 | "for context, continue the work from where the previous agent stopped, and complete your " + |
| 630 | "part of the task.")) |
| 631 | } |
no test coverage detected