Skip to content

AgentRun

Defined in: agent/src/agent/agent.run.ts:97

Drives a single agent run over the OpenAI chat API: streams model output, executes tool calls, and appends everything to the latest prompt in the transcript. When an action interrupts, the run suspends and can be continued via AgentRun.resume or AgentRun.reject. Emits AgentRunEvents. All state lives on the prompt, so a run reconstructed over persisted prompts behaves like the original.

new AgentRun(options): AgentRun;

Defined in: agent/src/agent/agent.run.ts:101

Parameter Type
options AgentRunOptions

AgentRun

EventEmitter<AgentRunEvents>.constructor
get state(): AgentRunState;

Defined in: agent/src/agent/agent.run.ts:116

The run’s current position, read from the prompt itself: interrupted when a tool call’s latest interrupt has no resolution yet, ready otherwise. Works on a freshly constructed run over persisted prompts.

AgentRunState

emit<K>(event, ...args): void;

Defined in: core/src/utils/utils.eventemitter.ts:62

Invokes all listeners for event synchronously, without awaiting async listeners.

Type Parameter
K extends keyof AgentRunEvents
Parameter Type
event K
args Parameters<AgentRunEvents[K]>

void

EventEmitter.emit

emitAsync<K>(event, ...args): Promise<void>;

Defined in: core/src/utils/utils.eventemitter.ts:73

Invokes all listeners for event and awaits them concurrently via Promise.all.

Type Parameter
K extends keyof AgentRunEvents
Parameter Type
event K
args Parameters<AgentRunEvents[K]>

Promise<void>

EventEmitter.emitAsync

on<K>(
event,
callback,
options?): () => void;

Defined in: core/src/utils/utils.eventemitter.ts:21

Registers callback for event. Returns an unsubscribe function; passing options.abortSignal also removes the listener when that signal aborts.

Type Parameter
K extends keyof AgentRunEvents
Parameter Type
event K
callback EventListener<Parameters<AgentRunEvents[K]>>
options OnOptions

() => void

EventEmitter.on

once<K>(
event,
callback,
options?): () => void;

Defined in: core/src/utils/utils.eventemitter.ts:45

Like on, but the listener is removed after firing once.

Type Parameter
K extends keyof AgentRunEvents
Parameter Type
event K
callback EventListener<Parameters<AgentRunEvents[K]>>
options OnOptions

() => void

EventEmitter.once

reject(error): Promise<AgentRunResult>;

Defined in: agent/src/agent/agent.run.ts:149

Answer the pending interrupt: skip the suspended tool call, recording error as its failure, then continue.

Parameter Type
error unknown

Promise<AgentRunResult>


resume(data?): Promise<AgentRunResult>;

Defined in: agent/src/agent/agent.run.ts:143

Answer the pending interrupt: re-run the suspended tool call with data as its resumption, then continue.

Parameter Type
data? unknown

Promise<AgentRunResult>


run(): Promise<AgentRunResult>;

Defined in: agent/src/agent/agent.run.ts:135

Run the agent: call the model and execute tool calls until no more are requested, then resolve as completed (or interrupted if an action suspends the run). Throws when the run is already suspended — use AgentRun.resume or AgentRun.reject instead.

Promise<AgentRunResult>