AgentResult
Defined in: src/types/agent.ts:212
Result returned by the agent loop.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AgentResult(data): AgentResult;Defined in: src/types/agent.ts:243
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | { stopReason: StopReason; lastMessage: Message; traces?: AgentTrace[]; metrics?: AgentMetrics; structuredOutput?: unknown; } |
data.stopReason | StopReason |
data.lastMessage | Message |
data.traces? | AgentTrace[] |
data.metrics? | AgentMetrics |
data.structuredOutput? | unknown |
Returns
Section titled “Returns”AgentResult
Properties
Section titled “Properties”readonly type: "agentResult";Defined in: src/types/agent.ts:213
stopReason
Section titled “stopReason”readonly stopReason: StopReason;Defined in: src/types/agent.ts:218
The stop reason from the final model response.
lastMessage
Section titled “lastMessage”readonly lastMessage: Message;Defined in: src/types/agent.ts:223
The last message added to the messages array.
traces?
Section titled “traces?”readonly optional traces?: AgentTrace[];Defined in: src/types/agent.ts:229
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?: unknown;Defined in: src/types/agent.ts:235
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:241
Aggregated metrics for the agent’s loop execution. Tracks cycle counts, token usage, tool execution stats, and model latency.
Accessors
Section titled “Accessors”contextSize
Section titled “contextSize”Get Signature
Section titled “Get Signature”get contextSize(): number;Defined in: src/types/agent.ts:268
The most recent input token count from the last model invocation.
Convenience accessor that delegates to metrics.latestContextSize.
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:282
Custom JSON serialization that excludes traces and metrics by default. This prevents accidentally sending large trace/metric data over the wire when serializing AgentResult for API responses.
Traces and metrics remain accessible via their properties for debugging, but won’t be included in JSON.stringify() output.
Returns
Section titled “Returns”object
Object representation without traces/metrics for safe serialization
toString()
Section titled “toString()”toString(): string;Defined in: src/types/agent.ts:297
Extracts and concatenates all text content from the last message. Includes text from TextBlock and ReasoningBlock content blocks.
Returns
Section titled “Returns”string
The agent’s last message as a string, with multiple blocks joined by newlines.