run(...)
run(...) is the main execution entrypoint.
Signatures
Section titled “Signatures”run(agent, input, { stream: true, ...options }): Promise<StreamedRunResult<TContext>>
run(agent, input, options?): Promise<RunResult<TContext>>Where:
agentis the startingAgentinputis eitherstringorAgentInputItem[]streamdefaults tofalse
Non-streaming Result
Section titled “Non-streaming Result”type RunResult<TContext> = { finalOutput: string; history: AgentInputItem[]; lastAgent: Agent<TContext>;}Streaming Result
Section titled “Streaming Result”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:
historylastAgent
Options
Section titled “Options”The current shared option surface is:
{ context?: TContext; maxTurns?: number; logger?: RunLogger; policies?: PolicyConfiguration<TContext>; record?: RunRecordOptions<TContext>;}Important Operational Notes
Section titled “Important Operational Notes”Default provider
Section titled “Default provider”run(...) uses the configured default provider.
If no default provider has been set, runtime execution fails.
Model requirement
Section titled “Model requirement”The active agent must have model configured.
Default max turns
Section titled “Default max turns”If omitted, maxTurns defaults to 10.
Input normalization
Section titled “Input normalization”If input is a string, it is normalized to a single user message item.
Runtime logging
Section titled “Runtime logging”If logger is configured, run(...) emits structured runtime events during execution.
See Logging.
Example
Section titled “Example”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);