You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/agents/api-reference/store-and-sync-state.mdx
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -281,4 +281,3 @@ export class ReasoningAgent extends Agent<Env> {
281
281
</TypeScriptExample>
282
282
283
283
This works because each instance of an Agent has its _own_ database, the state stored in that database is private to that Agent: whether it's acting on behalf of a single user, a room or channel, or a deep research tool. By default, you don't have to manage contention or reach out over the network to a centralized database to retrieve and store state.
This quick start tutorial will have you build a basic Agent that can generate code based on user questions. It will show you how the Agent SDK works, how to handle requests, store and sync state from within the Agent itself, and how to route to and call Agents from your Workers code.
12
12
13
-
14
13
### Prerequisites
15
14
16
-
TODO
15
+
<Renderfile="prereqs"product="workers" />
17
16
18
-
### Fetch the quick start project
17
+
### Setup the Agent
19
18
20
19
You can fetch the quick start project using the following command:
This will create a new directory called `agents-quick-start`, ask you a few basic questions, and install the necessary dependencies.
25
26
@@ -36,6 +37,8 @@ TODO
36
37
37
38
### Run your Agent
38
39
40
+
OK, it's time to run your first Agent!
41
+
39
42
You can run your Agent locally, which can be useful during development when iterating and/or when testing your Agent's functionality. To run your Agent locally, use the following command:
40
43
41
44
```sh
@@ -54,12 +57,21 @@ Starting local server...
54
57
[wrangler:inf] Ready on http://localhost:8787
55
58
```
56
59
57
-
This will
58
-
60
+
Your Agent is now running locally on your machine, and ready to communicate with the outside world. Leave this server running so we can talk to your Agent in the next step.
59
61
60
62
### Communicate with your Agent
61
63
62
-
The example Agent in this quick start project exposes both HTTP and WebSocket endpoints
64
+
Let's communicate with your Agent and have it run a simple task.
65
+
66
+
The example Agent in this quick start project exposes both HTTP and WebSocket endpoints, and so we'll use [`wscat`](https://github.com/websockets/wscat) as a command-line WebSocket client to communicate with our Agent's chat endpoint.
67
+
68
+
Install `wscat`:
69
+
70
+
```sh
71
+
npm install -g wscat
72
+
```
73
+
74
+
Run `wscat` and connect to an instance of your Agent (running locally). Remember that each Agent can have many _instances_, each able to interact with users, tools and other APIs independently, as well as store state specific to that instance.
63
75
64
76
```sh
65
77
# The code in this project will automatically create a new Agent on-the-fly when
In the `agents-quick-start` we use the `routeAgentRequest` helper to automatically handle routing to existing and creating new Agent instances on-the-fly.
88
+
89
+
If you open up `src/index.ts`,
90
+
91
+
<TypeScriptExamplefilename="src/index.ts">
92
+
93
+
```ts
94
+
exportdefault {
95
+
async fetch(request, env, ctx) {
96
+
// Built-in Agent routing (recommended to start with)
97
+
// routeAgentRequest routes HTTP requests and/or WebSocket connections to a specific Agent instance
98
+
// Expects requests are of the format /agents/:agent/:name
99
+
//
100
+
// - :agent is the kebab-case of your Agent class name - e.g. MyAgent becomes my-agent
101
+
// - :name is provided by the incoming client and names the unique instance of the Agent. NOTE: If an Agent doesn't exist by that name, one will be created on-the-fly.
You can learn about more ways to call into your Agents, as well as how to add authentication in front of your Agents, by reviewing [documentation on Calling Agents](/agents/api-reference/calling-agents/).
110
+
73
111
### Deploy your Agent
74
112
113
+
OK, we've:
75
114
115
+
1. Learned how the `Agent` class works and how to define our own Agents using the Agents SDK.
116
+
2. Run our Agent locally and communicated with it.
117
+
3. Reviewed how routing to an Agent works, including how Agents are created and retrieved.
118
+
119
+
Let's deploy our Agent
76
120
77
121
### Extend the Agent
78
122
79
-
TODO
123
+
TODO;
124
+
125
+
- AI SDK
126
+
127
+
128
+
<TypeScriptExample>
129
+
130
+
```ts
131
+
asyncaiSDKChat() {
132
+
133
+
134
+
}
135
+
```
136
+
137
+
</TypeScriptExample>
138
+
139
+
### Optional: Clean-up
140
+
141
+
TODO: delete
80
142
81
143
### Next steps
82
144
83
-
TODO
145
+
What's next?
146
+
147
+
* Deploy the [Agents SDK starter app](/agents/getting-started/build-a-chat-agent/): a fully-functioning AI Agent with a React front-end, tool calling, and state sync that is built on the Agents SDK.
148
+
* Review the [Agents API reference](/agents/api-reference/creating-agents/) and the APIs exposed by the Agents SDK.
149
+
* Learn more [using WebSockets](/agents/api-reference/websockets/) to build interactive Agents and stream data back from your Agent.
150
+
*[Orchestrate asynchronous workflows](/agents/api-reference/run-workflows) from your Agent by combining the `agents-sdk` and [Workflows](/workflows).
0 commit comments