Runner
A Runner is responsible for running an agent workflow.
Extends
Section titled “Extends”RunHooks
<any
,AgentOutputType
<unknown
>>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Runner(config?): Runner
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
Returns
Section titled “Returns”Runner
Overrides
Section titled “Overrides”RunHooks<any, AgentOutputType<unknown>>.constructor
Properties
Section titled “Properties”config
Section titled “config”readonly config: RunConfig;
Methods
Section titled “Methods”emit()
Section titled “emit()”emit<K>(type, ...args): boolean
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
… |
|
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”RunHooks.emit
off<K>(type, listener): EventEmitter<EventTypes>
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter
<EventTypes
>
Inherited from
Section titled “Inherited from”RunHooks.off
on<K>(type, listener): EventEmitter<EventTypes>
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter
<EventTypes
>
Inherited from
Section titled “Inherited from”RunHooks.on
once()
Section titled “once()”once<K>(type, listener): EventEmitter<EventTypes>
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter
<EventTypes
>
Inherited from
Section titled “Inherited from”RunHooks.once
Call Signature
Section titled “Call Signature”run<TAgent, TContext>( agent, input,options?): Promise<RunResult<TContext, TAgent>>
Run a workflow starting at the given agent. The agent will run in a loop until a final output is generated. The loop runs like so:
- The agent is invoked with the given input.
- If there is a final output (i.e. the agent produces something of type
agent.outputType
, the loop terminates. - If there’s a handoff, we run the loop again, with the new agent.
- Else, we run tool calls (if any), and re-run the loop.
In two cases, the agent may raise an exception:
- If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised.
- If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised.
Note that only the first agent’s input guardrails are run.
Type Parameters
Section titled “Type Parameters”Type Parameter | Default type |
---|---|
|
‐ |
|
|
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
The starting agent to run. |
|
| |
The initial input to the agent. You can pass a string or an array of
|
|
|
The options for the run. |
Returns
Section titled “Returns”Promise
<RunResult
<TContext
, TAgent
>>
The result of the run.
Call Signature
Section titled “Call Signature”run<TAgent, TContext>( agent, input,options?): Promise<StreamedRunResult<TContext, TAgent>>
Run a workflow starting at the given agent. The agent will run in a loop until a final output is generated. The loop runs like so:
- The agent is invoked with the given input.
- If there is a final output (i.e. the agent produces something of type
agent.outputType
, the loop terminates. - If there’s a handoff, we run the loop again, with the new agent.
- Else, we run tool calls (if any), and re-run the loop.
In two cases, the agent may raise an exception:
- If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised.
- If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised.
Note that only the first agent’s input guardrails are run.
Type Parameters
Section titled “Type Parameters”Type Parameter | Default type |
---|---|
|
‐ |
|
|
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
The starting agent to run. |
|
| |
The initial input to the agent. You can pass a string or an array of
|
|
|
The options for the run. |
Returns
Section titled “Returns”Promise
<StreamedRunResult
<TContext
, TAgent
>>
The result of the run.