Skip to content

AgentResult

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

Result returned by the agent loop.

new AgentResult(data): AgentResult;

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

ParameterType
data{ stopReason: StopReason; lastMessage: Message; traces?: AgentTrace[]; metrics?: AgentMetrics; structuredOutput?: unknown; }
data.stopReasonStopReason
data.lastMessageMessage
data.traces?AgentTrace[]
data.metrics?AgentMetrics
data.structuredOutput?unknown

AgentResult

readonly type: "agentResult";

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


readonly stopReason: StopReason;

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

The stop reason from the final model response.


readonly lastMessage: Message;

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

The last message added to the messages array.


readonly optional traces?: AgentTrace[];

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

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


readonly optional structuredOutput?: unknown;

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

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:176

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

toJSON(): object;

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

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.

object

Object representation without traces/metrics for safe serialization


toString(): string;

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

Extracts and concatenates all text content from the last message. Includes text from TextBlock and ReasoningBlock content blocks.

string

The agent’s last message as a string, with multiple blocks joined by newlines.