Class AgentHandoffException

All Implemented Interfaces:
Serializable

public class AgentHandoffException extends RuntimeException
Exception thrown when an agent tool is called to signal a handoff.

When the model calls an agent-as-tool, this exception is thrown to signal that the chat should switch context to the target agent. The Chat class catches this exception and updates its system prompt, tools, and model to those of the target agent.

This enables the "handoff" pattern where conversations can be transferred between specialized agents.

See Also:
  • Constructor Details

    • AgentHandoffException

      public AgentHandoffException(String targetAgentName, AgentConfig targetAgentConfig, Map<String,Object> handoffInput)
      Creates a new AgentHandoffException.
      Parameters:
      targetAgentName - the name of the agent to hand off to
      targetAgentConfig - the configuration of the target agent
      handoffInput - the input passed to the agent tool (can be used for context)
  • Method Details

    • getTargetAgentName

      public String getTargetAgentName()
      Gets the name of the target agent.
      Returns:
      the target agent name
    • getTargetAgentConfig

      public AgentConfig getTargetAgentConfig()
      Gets the configuration of the target agent.
      Returns:
      the target agent config
    • getHandoffInput

      public Map<String,Object> getHandoffInput()
      Gets the input passed to the agent tool.
      Returns:
      the handoff input