AgentResult
Defined in: src/types/agent.ts:440
Result returned by the agent loop.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AgentResult(data): AgentResult;Defined in: src/types/agent.ts:505
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | { stopReason: StopReason; lastMessage: Message; invocationState: InvocationState; traces?: AgentTrace[]; metrics?: AgentMetrics; invocationContext?: InvocationContext; structuredOutput?: output<ZodType>; interrupts?: Interrupt[]; checkpoint?: Checkpoint; } |
data.stopReason | StopReason |
data.lastMessage | Message |
data.invocationState | InvocationState |
data.traces? | AgentTrace[] |
data.metrics? | AgentMetrics |
data.invocationContext? | InvocationContext |
data.structuredOutput? | output<ZodType> |
data.interrupts? | Interrupt[] |
data.checkpoint? | Checkpoint |
Returns
Section titled “Returns”AgentResult
Properties
Section titled “Properties”readonly type: "agentResult";Defined in: src/types/agent.ts:441
stopReason
Section titled “stopReason”readonly stopReason: StopReason;Defined in: src/types/agent.ts:446
The stop reason from the final model response.
lastMessage
Section titled “lastMessage”readonly lastMessage: Message;Defined in: src/types/agent.ts:451
The last message added to the messages array.
traces?
Section titled “traces?”readonly optional traces?: AgentTrace[];Defined in: src/types/agent.ts:457
Local execution traces collected during the agent invocation. Contains timing and hierarchy of operations within the agent loop.
structuredOutput?
Section titled “structuredOutput?”readonly optional structuredOutput?: output<ZodType>;Defined in: src/types/agent.ts:463
The validated structured output from the LLM, if a schema was provided. Type represents any validated Zod schema output.
metrics?
Section titled “metrics?”readonly optional metrics?: AgentMetrics;Defined in: src/types/agent.ts:469
Aggregated metrics for the agent’s loop execution. Tracks cycle counts, token usage, tool execution stats, and model latency.
invocationContext?
Section titled “invocationContext?”readonly optional invocationContext?: InvocationContext;Defined in: src/types/agent.ts:480
The invocation context this call ran in. Its usage covers the whole request
(this agent, its nested calls, and auxiliary calls), unlike metrics,
which covers this agent only; for a nested call that set its own limits, it is
that call’s context and covers its share. Pass it as
InvokeOptions.invocationContext to continue on the same limits and
usage. It is live, so work that finishes after this call returns (for example
a background task) still adds to it.
invocationState
Section titled “invocationState”readonly invocationState: InvocationState;Defined in: src/types/agent.ts:488
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.
interrupts?
Section titled “interrupts?”readonly optional interrupts?: Interrupt[];Defined in: src/types/agent.ts:494
Interrupts that caused the agent to stop, when stopReason is 'interrupt'.
Contains the unanswered interrupts that require human input to resume.
checkpoint?
Section titled “checkpoint?”readonly optional checkpoint?: Checkpoint;Defined in: src/types/agent.ts:503
Experimental
Checkpoint captured when the agent paused for durable execution. Populated
only when stopReason is 'checkpoint'. See the experimental checkpoint
module for usage.
Accessors
Section titled “Accessors”contextSize
Section titled “contextSize”Get Signature
Section titled “Get Signature”get contextSize(): number;Defined in: src/types/agent.ts:544
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.
Returns
Section titled “Returns”number
projectedContextSize
Section titled “projectedContextSize”Get Signature
Section titled “Get Signature”get projectedContextSize(): number;Defined in: src/types/agent.ts:554
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.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”toJSON()
Section titled “toJSON()”toJSON(): object;Defined in: src/types/agent.ts:569
Custom JSON serialization that excludes traces, metrics, invocationContext, and invocationState.
Traces and metrics are excluded to avoid sending large payloads over the wire
in API responses; invocationContext is excluded because it is live and can
still change; invocationState is excluded because its values are caller-owned and
may not be serializable (see InvocationState).
All four remain accessible via their properties for debugging.
Returns
Section titled “Returns”object
Object representation for safe serialization
toString()
Section titled “toString()”toString(): string;Defined in: src/types/agent.ts:589
Extracts a string representation of the result.
Priority order:
interruptsserialized as JSON, if any are presentstructuredOutputserialized as JSON- Text from
textBlock,reasoningBlock, andcitationsBlockcontent blocks
Returns
Section titled “Returns”string
String representation of the result: JSON for interrupts/structuredOutput, or text content joined by newlines.