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>>.constructorProperties
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.emitoff<K>(type, listener): EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>
Inherited from
Section titled “Inherited from”RunHooks.offon<K>(type, listener): EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>
Inherited from
Section titled “Inherited from”RunHooks.ononce()
Section titled “once()”once<K>(type, listener): EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>
Inherited from
Section titled “Inherited from”RunHooks.onceCall 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
|
|
|
|
Options for the run, including streaming behavior, execution context, and the maximum number of turns. |
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
|
|
|
|
Options for the run, including streaming behavior, execution context, and the maximum number of turns. |
Returns
Section titled “Returns”Promise<StreamedRunResult<TContext, TAgent>>
The result of the run.