Skip to content

Runner

A Runner is responsible for running an agent workflow.

new Runner(config): Runner
Parameter Type

config

Partial<RunConfig>

Runner

RunHooks<any, AgentOutputType<unknown>>.constructor
readonly config: RunConfig;
emit<K>(type, ...args): boolean
Type Parameter

K extends keyof RunHookEvents<any, AgentOutputType<unknown>>

Parameter Type

type

K

args

RunHookEvents<any, AgentOutputType<unknown>>[K]

boolean

RunHooks.emit

off<K>(type, listener): EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>
Type Parameter

K extends keyof RunHookEvents<any, AgentOutputType<unknown>>

Parameter Type

type

K

listener

(…args) => void

EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>

RunHooks.off

on<K>(type, listener): EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>
Type Parameter

K extends keyof RunHookEvents<any, AgentOutputType<unknown>>

Parameter Type

type

K

listener

(…args) => void

EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>

RunHooks.on

once<K>(type, listener): EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>
Type Parameter

K extends keyof RunHookEvents<any, AgentOutputType<unknown>>

Parameter Type

type

K

listener

(…args) => void

EventEmitter<RunHookEvents<any, AgentOutputType<unknown>>>

RunHooks.once

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:

  1. The agent is invoked with the given input.
  2. If there is a final output (i.e. the agent produces something of type agent.outputType, the loop terminates.
  3. If there’s a handoff, we run the loop again, with the new agent.
  4. Else, we run tool calls (if any), and re-run the loop.

In two cases, the agent may raise an exception:

  1. If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised.
  2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised.

Note that only the first agent’s input guardrails are run.

Type Parameter Default type

TAgent extends Agent<any, any>

TContext

undefined

Parameter Type Description

agent

TAgent

The starting agent to run.

input

| string | AgentInputItem[] | RunState<TContext, TAgent>

The initial input to the agent. You can pass a string or an array of AgentInputItem.

options?

NonStreamRunOptions<TContext>

The options for the run.

Promise<RunResult<TContext, TAgent>>

The result of the run.

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:

  1. The agent is invoked with the given input.
  2. If there is a final output (i.e. the agent produces something of type agent.outputType, the loop terminates.
  3. If there’s a handoff, we run the loop again, with the new agent.
  4. Else, we run tool calls (if any), and re-run the loop.

In two cases, the agent may raise an exception:

  1. If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised.
  2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised.

Note that only the first agent’s input guardrails are run.

Type Parameter Default type

TAgent extends Agent<any, any>

TContext

undefined

Parameter Type Description

agent

TAgent

The starting agent to run.

input

| string | AgentInputItem[] | RunState<TContext, TAgent>

The initial input to the agent. You can pass a string or an array of AgentInputItem.

options?

StreamRunOptions<TContext>

The options for the run.

Promise<StreamedRunResult<TContext, TAgent>>

The result of the run.