Skip to content

AgentResult

Defined in: src/types/agent.ts:431

Result returned by the agent loop.

new AgentResult(data): AgentResult;

Defined in: src/types/agent.ts:485

ParameterType
data{ stopReason: StopReason; lastMessage: Message; invocationState: InvocationState; traces?: AgentTrace[]; metrics?: AgentMetrics; structuredOutput?: output<ZodType>; interrupts?: Interrupt[]; checkpoint?: Checkpoint; }
data.stopReasonStopReason
data.lastMessageMessage
data.invocationStateInvocationState
data.traces?AgentTrace[]
data.metrics?AgentMetrics
data.structuredOutput?output<ZodType>
data.interrupts?Interrupt[]
data.checkpoint?Checkpoint

AgentResult

readonly type: "agentResult";

Defined in: src/types/agent.ts:432


readonly stopReason: StopReason;

Defined in: src/types/agent.ts:437

The stop reason from the final model response.


readonly lastMessage: Message;

Defined in: src/types/agent.ts:442

The last message added to the messages array.


readonly optional traces?: AgentTrace[];

Defined in: src/types/agent.ts:448

Local execution traces collected during the agent invocation. Contains timing and hierarchy of operations within the agent loop.


readonly optional structuredOutput?: output<ZodType>;

Defined in: src/types/agent.ts:454

The validated structured output from the LLM, if a schema was provided. Type represents any validated Zod schema output.


readonly optional metrics?: AgentMetrics;

Defined in: src/types/agent.ts:460

Aggregated metrics for the agent’s loop execution. Tracks cycle counts, token usage, tool execution stats, and model latency.


readonly invocationState: InvocationState;

Defined in: src/types/agent.ts:468

Per-invocation state passed into the agent, threaded through hooks and tools, and surfaced here at the end of the invocation. See InvocationState for details. Always defined — defaults to {} when no invocationState was provided in InvokeOptions.


readonly optional interrupts?: Interrupt[];

Defined in: src/types/agent.ts:474

Interrupts that caused the agent to stop, when stopReason is 'interrupt'. Contains the unanswered interrupts that require human input to resume.


readonly optional checkpoint?: Checkpoint;

Defined in: src/types/agent.ts:483

Experimental

Checkpoint captured when the agent paused for durable execution. Populated only when stopReason is 'checkpoint'. See the experimental checkpoint module for usage.

get contextSize(): number;

Defined in: src/types/agent.ts:520

The total prompt the model processed on the last invocation, including cached tokens. Convenience accessor that delegates to metrics.latestContextSize. Returns undefined when no metrics or invocations are available.

number


get projectedContextSize(): number;

Defined in: src/types/agent.ts:530

Projected context size for the next model call (total prompt including cached tokens plus the generated output from the last call). Convenience accessor that delegates to metrics.projectedContextSize. Returns undefined when no metrics or invocations are available.

number

toJSON(): object;

Defined in: src/types/agent.ts:544

Custom JSON serialization that excludes traces, metrics, and invocationState. Traces and metrics are excluded to avoid sending large payloads over the wire in API responses; invocationState is excluded because its values are caller-owned and may not be serializable (see InvocationState).

All three remain accessible via their properties for debugging.

object

Object representation for safe serialization


toString(): string;

Defined in: src/types/agent.ts:564

Extracts a string representation of the result.

Priority order:

  1. interrupts serialized as JSON, if any are present
  2. structuredOutput serialized as JSON
  3. Text from textBlock, reasoningBlock, and citationsBlock content blocks

string

String representation of the result: JSON for interrupts/structuredOutput, or text content joined by newlines.