> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Durable State

> Merge-patch state with setState and getState, persisted per actor.

`this.setState()` merges a patch into the actor's current state. Use it for small
structured values you want to read quickly — the current conversation state, user
preferences, last-seen timestamp.

```ts theme={null}
export interface MyState extends Record<string, unknown> {
  status: "idle" | "processing" | "waiting";
  lastReply: string;
  at: number;
}

export class MyAgent extends Agent<RuntimeEnv, MyState> {
  // Default state for a new actor
  protected override initialState(): MyState {
    return { status: "idle", lastReply: "", at: 0 };
  }

  async process(): Promise<void> {
    await this.setState({ status: "processing" });
    // ... do work ...
    await this.setState({ status: "idle", lastReply: "Done.", at: Date.now() });
  }

  async report(): Promise<MyState> {
    return this.getState();
  }
}
```

`setState` is a **recursive merge** (RFC 7396) — top-level keys you pass are merged in,
nested objects are deep-merged, and `null` deletes a key. `replaceState` replaces the
whole state object.

State is one value, read whole. The moment data turns relational or queryable —
orders, events, anything you'd filter or aggregate — put it in the actor's embedded
[SQL database](/docs/agent-sdk/sql) instead.
