Skip to content

Interface: AgentStateInterface

@providerprotocol/agents


@providerprotocol/agents / index / AgentStateInterface

Defined in: src/state/types.ts:262

Interface defining the contract for agent state operations.

All methods follow immutable patterns, returning new state instances rather than mutating the existing state. This enables safe state management, easy rollback, and predictable behavior.

Implementations should ensure thread-safety by never mutating internal data structures.

AgentState for the concrete implementation

readonly id: string

Defined in: src/state/types.ts:264

Unique identifier for this state snapshot (UUIDv4)


readonly messages: readonly Message[]

Defined in: src/state/types.ts:267

Immutable conversation history containing UPP Messages


readonly metadata: Readonly<Record<string, unknown>>

Defined in: src/state/types.ts:273

User-defined metadata for storing arbitrary state


readonly plan: readonly PlanStep[] | undefined

Defined in: src/state/types.ts:279

Execution plan for Plan-strategy agents (undefined if not using Plan strategy)


readonly reasoning: readonly string[]

Defined in: src/state/types.ts:276

Reasoning traces captured during ReAct-style execution


readonly step: number

Defined in: src/state/types.ts:270

Current step number in the agent’s execution lifecycle


readonly subagentTraces: readonly SubagentExecutionTrace[]

Defined in: src/state/types.ts:282

Sub-agent execution traces per UAP spec Section 8.8

toJSON(): AgentStateJSON

Defined in: src/state/types.ts:358

Serializes the state to JSON for persistence.

AgentStateJSON

A JSON-serializable representation of the state


withContext(messages): AgentStateInterface

Defined in: src/state/types.ts:310

Creates a new state with the entire message context replaced.

Message[]

The new complete message history

AgentStateInterface

A new AgentState instance with the replaced context

Use this for context window management operations like pruning or summarization, where you need to replace the entire history.


withMessage(message): AgentStateInterface

Defined in: src/state/types.ts:290

Creates a new state with the given message appended.

Message

The message to add to the conversation history

AgentStateInterface

A new AgentState instance with the message appended


withMessages(messages): AgentStateInterface

Defined in: src/state/types.ts:298

Creates a new state with multiple messages appended.

Message[]

The messages to add to the conversation history

AgentStateInterface

A new AgentState instance with all messages appended


withMetadata(key, value): AgentStateInterface

Defined in: src/state/types.ts:327

Creates a new state with a metadata entry added or updated.

string

The metadata key

unknown

The value to store

AgentStateInterface

A new AgentState instance with the updated metadata


withPlan(plan): AgentStateInterface

Defined in: src/state/types.ts:343

Creates a new state with the execution plan set.

PlanStep[]

The execution plan steps

AgentStateInterface

A new AgentState instance with the plan set


withReasoning(reasoning): AgentStateInterface

Defined in: src/state/types.ts:335

Creates a new state with a reasoning trace appended.

string

The reasoning trace to add

AgentStateInterface

A new AgentState instance with the reasoning appended


withStep(step): AgentStateInterface

Defined in: src/state/types.ts:318

Creates a new state with an updated step number.

number

The new step number

AgentStateInterface

A new AgentState instance with the updated step


withSubagentTrace(trace): AgentStateInterface

Defined in: src/state/types.ts:351

Creates a new state with a sub-agent execution trace appended.

SubagentExecutionTrace

The sub-agent execution trace to add

AgentStateInterface

A new AgentState instance with the trace appended