Skip to content

Handoff

A handoff is when an agent delegates a task to another agent. For example, in a customer support scenario you might have a “triage agent” that determines which agent should handle the user’s request, and sub-agents that specialize in different areas like billing, account management, etc.

Type Parameter Default type Description

TContext

UnknownContext

The context of the handoff

TOutput extends AgentOutputType

TextOutput

The output type of the handoff

new Handoff<TContext, TOutput>(agent, onInvokeHandoff): Handoff<TContext, TOutput>
Parameter Type

agent

Agent<TContext, TOutput>

onInvokeHandoff

(context, args) => | Agent<TContext, TOutput> | Promise<Agent<TContext, TOutput>>

Handoff<TContext, TOutput>

agent: Agent<TContext, TOutput>;

The agent that is being handed off to.


agentName: string;

The name of the agent that is being handed off to.


optional inputFilter: HandoffInputFilter;

A function that filters the inputs that are passed to the next agent. By default, the new agent sees the entire conversation history. In some cases, you may want to filter inputs e.g. to remove older inputs, or remove tools from existing inputs.

The function will receive the entire conversation hisstory so far, including the input item that triggered the handoff and a tool call output item representing the handoff tool’s output.

You are free to modify the input history or new items as you see fit. The next agent that runs will receive `handoffInputData.allItems


inputJsonSchema: JsonObjectSchema<any>;

The JSON schema for the handoff input. Can be empty if the handoff does not take an input


onInvokeHandoff: (context, args) =>
| Agent<TContext, TOutput>
| Promise<Agent<TContext, TOutput>>;

The function that invokes the handoff. The parameters passed are:

  1. The handoff run context
  2. The arugments from the LLM, as a JSON string. Empty string if inputJsonSchema is empty.

Must return an agent

Parameter Type

context

RunContext<TContext>

args

string

| Agent<TContext, TOutput> | Promise<Agent<TContext, TOutput>>


strictJsonSchema: boolean = true;

Whether the input JSON schema is in strict mode. We strongly recommend setting this to true, as it increases the likelihood of correct JSON input.


toolDescription: string;

The description of the tool that represents the handoff.


toolName: string;

The name of the tool that represents the handoff.

getHandoffAsFunctionTool(): object

Returns a function tool definition that can be used to invoke the handoff.

object

description: string;
name: string;
parameters: JsonObjectSchema<any>;
strict: boolean;
type: "function";