Skip to content

Commit 0072789

Browse files
committed
store and sync state
1 parent 79731cb commit 0072789

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

public/_redirects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
# agents
100100
/agents/build/prompts/ /workers/get-started/prompting/ 301
101101
/agents/examples/browse-the-web/ /agents/api-reference/browse-the-web/ 301
102-
/agents/examples/manage-and-sync-state/ /agents/api-reference/manage-and-sync-state/ 301
102+
/agents/examples/manage-and-sync-state/ /agents/api-reference/store-and-sync-state/ 301
103103
/agents/examples/rag/ /agents/api-reference/rag/ 301
104104
/agents/examples/run-workflows/ /agents/api-reference/run-workflows/ 301
105105
/agents/examples/schedule-tasks/ /agents/api-reference/schedule-tasks/ 301

src/content/docs/agents/api-reference/sdk.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export default MyAgent;
493493

494494
:::note
495495

496-
To learn more about how to manage state within an Agent, refer to the documentation on [managing and syncing state](/agents/api-reference/manage-and-sync-state/).
496+
To learn more about how to manage state within an Agent, refer to the documentation on [managing and syncing state](/agents/api-reference/store-and-sync-state/).
497497

498498
:::
499499

src/content/docs/agents/api-reference/manage-and-sync-state.mdx renamed to src/content/docs/agents/api-reference/store-and-sync-state.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
---
2-
title: Manage and sync state
2+
title: Store and sync state
33
pcx_content_type: concept
44
sidebar:
55
order: 6
66
---
77

88
import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components";
99

10-
Every Agent has built-in state management capabilities, including built-in storage and synchronization between the Agent and frontend applications. State within an Agent is:
10+
Every Agent has built-in state management capabilities, including built-in storage and synchronization between the Agent and frontend applications.
1111

12-
* Persisted across Agent restarts: data is permanently persisted within the Agent.
12+
State within an Agent is:
13+
14+
* Persisted across Agent restarts: data is permanently stored within an Agent.
1315
* Automatically serialized/deserialized: you can store any JSON-serializable data.
1416
* Immediately consistent within the Agent: read your own writes.
1517
* Thread-safe for concurrent updates
18+
* Fast: state is colocated wherever the Agent is running. Reads and writes do not need to traverse the network.
1619

17-
Agent state is stored in a SQL database that is embedded within each individual Agent instance: you can interact with it using the higher-level `this.setState` API (recommended) or by directly querying the database with `this.sql`.
20+
Agent state is stored in a SQL database that is embedded within each individual Agent instance: you can interact with it using the higher-level `this.setState` API (recommended), which allows you to sync state and trigger events on state changes, or by directly querying the database with `this.sql`.
1821

1922
#### State API
2023

src/content/docs/agents/api-reference/using-ai-models.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class MyAgent extends Agent<Env> {
7575

7676
</TypeScriptExample>
7777

78-
You can also persist AI model responses back to [Agent's internal state](/agents/api-reference/manage-and-sync-state/) by using the `this.setState` method. For example, if you run a [scheduled task](/agents/api-reference/schedule-tasks/), you can store the output of the task and read it later. Or, if a user disconnects, read the message history back and send it to the user when they reconnect.
78+
You can also persist AI model responses back to [Agent's internal state](/agents/api-reference/store-and-sync-state/) by using the `this.setState` method. For example, if you run a [scheduled task](/agents/api-reference/schedule-tasks/), you can store the output of the task and read it later. Or, if a user disconnects, read the message history back and send it to the user when they reconnect.
7979

8080
### Workers AI
8181

src/content/docs/agents/api-reference/websockets.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function AgentInterface() {
120120
```
121121
</TypeScriptExample>
122122

123-
The `useAgent` hook automatically handles the lifecycle of the connection, ensuring that it is properly initialized and cleaned up when the component mounts and unmounts. You can also [combine `useAgent` with `useState`](/agents/api-reference/manage-and-sync-state/) to automatically synchronize state across all clients connected to your Agent.
123+
The `useAgent` hook automatically handles the lifecycle of the connection, ensuring that it is properly initialized and cleaned up when the component mounts and unmounts. You can also [combine `useAgent` with `useState`](/agents/api-reference/store-and-sync-state/) to automatically synchronize state across all clients connected to your Agent.
124124

125125
## Handling WebSocket events
126126

src/content/docs/agents/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Dive into the [Agent SDK reference](/agents/api-reference/sdk/) to learn more ab
5050

5151
We built the `agents-sdk` with a few things in mind:
5252

53-
- **Batteries (state) included**: Agents come with [built-in state management](/agents/api-reference/manage-and-sync-state/), with the ability to automatically sync state between an Agent and clients, trigger events on state changes, and read+write to each Agent's SQL database.
53+
- **Batteries (state) included**: Agents come with [built-in state management](/agents/api-reference/store-and-sync-state/), with the ability to automatically sync state between an Agent and clients, trigger events on state changes, and read+write to each Agent's SQL database.
5454
- **Communicative**: You can connect to an Agent via [WebSockets](/agents/api-reference/websockets/) and stream updates back to client in real-time. Handle a long-running response from a reasoning model, the results of an [asynchronous workflow](/agents/api-reference/run-workflows/), or build a chat app that builds on the `useAgent` hook included in the `agents-sdk`.
5555
- **Extensible**: Agents are code. Use the [AI models](/agents/api-reference/using-ai-models/) you want, bring-your-own headless browser service, pull data from your database hosted in another cloud, add your own methods to your Agent and call them.
5656

0 commit comments

Comments
 (0)