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 Parameters
Section titled “Type Parameters”Type Parameter | Default type | Description |
---|---|---|
|
The context of the handoff |
|
|
The output type of the handoff |
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Handoff<TContext, TOutput>(agent, onInvokeHandoff): Handoff<TContext, TOutput>
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
|
( |
Returns
Section titled “Returns”Handoff
<TContext
, TOutput
>
Properties
Section titled “Properties”agent: Agent<TContext, TOutput>;
The agent that is being handed off to.
agentName
Section titled “agentName”agentName: string;
The name of the agent that is being handed off to.
inputFilter?
Section titled “inputFilter?”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
Section titled “inputJsonSchema”inputJsonSchema: JsonObjectSchema<any>;
The JSON schema for the handoff input. Can be empty if the handoff does not take an input
onInvokeHandoff()
Section titled “onInvokeHandoff()”onInvokeHandoff: (context, args) => | Agent<TContext, TOutput>| Promise<Agent<TContext, TOutput>>;
The function that invokes the handoff. The parameters passed are:
- The handoff run context
- The arugments from the LLM, as a JSON string. Empty string if inputJsonSchema is empty.
Must return an agent
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
|
|
Returns
Section titled “Returns”| Agent
<TContext
, TOutput
>
| Promise
<Agent
<TContext
, TOutput
>>
strictJsonSchema
Section titled “strictJsonSchema”strictJsonSchema: boolean;
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
Section titled “toolDescription”toolDescription: string;
The description of the tool that represents the handoff.
toolName
Section titled “toolName”toolName: string;
The name of the tool that represents the handoff.
Methods
Section titled “Methods”getHandoffAsFunctionTool()
Section titled “getHandoffAsFunctionTool()”getHandoffAsFunctionTool(): object
Returns a function tool definition that can be used to invoke the handoff.
Returns
Section titled “Returns”object
description
Section titled “description”description: string;
name: string;
parameters
Section titled “parameters”parameters: JsonObjectSchema<any>;
strict
Section titled “strict”strict: boolean;
type: "function";