> ## 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.

# ports.state

> `readonly` **state**: [`AgentHarnessStatePort`](/docs/agent-sdk/harness-sdk/ports/state#agentharnessstateport)\<`State`>

## On the Agent Runtime

[The runtime adapter](/docs/agent-sdk/harness-sdk/adapters/runtime#on-the-agent-runtime) builds the port from `host`, which carries the protected members of the `Agent` class.

```ts theme={null}
// runtime-adapter.ts
const state = Object.freeze({
  get: () => host.getState(),
  merge: (patch) => host.mergeState(patch),
  replace: (next) => host.replaceState(next),
});
```

* `get()` calls [`getState()`](/docs/agent-sdk/interface/getState). Until a state is written, it returns [`initialState()`](/docs/agent-sdk/interface/initialState).
* `merge()` calls [`setState()`](/docs/agent-sdk/interface/setState), which `host` carries as `mergeState`. The patch follows RFC 7396, so `null` deletes a key.
* `replace()` calls [`replaceState()`](/docs/agent-sdk/interface/replaceState). Nothing of the previous state survives.
* `merge()` and `replace()` run the class's [`onStateChanged()`](/docs/agent-sdk/interface/onStateChanged) after the write commits.

## AgentHarnessStatePort

Existing persistent Agent state semantics.

`merge()` and `replace()` include the Agent's post-commit state-change hook.
They may therefore reject after the new value is already persistent; callers
must read state before deciding whether a rejected mutation can be retried.

**Type Parameters**

| Type Parameter |
| - |
|  `State` *extends* `Record`\<`string`, `unknown`> |

**Methods**
**get()**

> **get**(): `Promise`\<`State`>

**Returns**
`Promise`\<`State`>

**merge()**

> **merge**(`patch`): `Promise`\<`State`>

**Parameters**

| Parameter | Type |
| - | - |
| `patch` | `MergePatch`\<`State`> |

**Returns**
`Promise`\<`State`>

**replace()**

> **replace**(`state`): `Promise`\<`State`>

**Parameters**

| Parameter | Type |
| - | - |
| `state` | `State` |

**Returns**
`Promise`\<`State`>
