Skip to content

run(...)

run(...) is the main execution entrypoint.

run(agent, input, { stream: true, ...options }): Promise<StreamedRunResult<TContext>>
run(agent, input, options?): Promise<RunResult<TContext>>

Where:

  • agent is the starting Agent
  • input is either string or AgentInputItem[]
  • stream defaults to false
type RunResult<TContext> = {
finalOutput: string;
history: AgentInputItem[];
lastAgent: Agent<TContext>;
}

When stream: true, run(...) returns StreamedRunResult<TContext>.

The important API is:

result.toStream(): AsyncIterable<RunStreamEvent<TContext>>

The stream can be consumed only once.

StreamedRunResult also exposes:

  • history
  • lastAgent

The current shared option surface is:

{
context?: TContext;
maxTurns?: number;
logger?: RunLogger;
policies?: PolicyConfiguration<TContext>;
record?: RunRecordOptions<TContext>;
}

run(...) uses the configured default provider.

If no default provider has been set, runtime execution fails.

The active agent must have model configured.

If omitted, maxTurns defaults to 10.

If input is a string, it is normalized to a single user message item.

If logger is configured, run(...) emits structured runtime events during execution.

See Logging.

const result = await run(agent, "Summarize report Q1.", {
context: { actor: { groups: ["finance"] } },
policies: { toolPolicy },
record: {
includePromptText: true,
sink: (record) => records.push(record),
},
});
console.log(result.finalOutput);