Skip to content

Commit 12fad4c

Browse files
committed
update
1 parent 7d240f5 commit 12fad4c

File tree

2 files changed

+77
-11
lines changed

2 files changed

+77
-11
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,3 @@ export class ReasoningAgent extends Agent<Env> {
281281
</TypeScriptExample>
282282

283283
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.
284-

src/content/docs/agents/getting-started/quickstart.mdx

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ sidebar:
66

77
---
88

9-
import { Render, PackageManagers, WranglerConfig } from "~/components"
9+
import { Render, GitHubCode, PackageManagers, TypeScriptExample, WranglerConfig } from "~/components"
1010

1111
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.
1212

13-
1413
### Prerequisites
1514

16-
TODO
15+
<Render file="prereqs" product="workers" />
1716

18-
### Fetch the quick start project
17+
### Setup the Agent
1918

2019
You can fetch the quick start project using the following command:
2120

22-
<PackageManagers type="create" pkg="cloudflare@latest" args={"agents-quick-start", "--", "--type=agent"} />
21+
```sh
22+
npm create cloudflare@latest agents-quick-start -- --template="cloudflare/agents-quick-start"
23+
```
2324

2425
This will create a new directory called `agents-quick-start`, ask you a few basic questions, and install the necessary dependencies.
2526

@@ -36,6 +37,8 @@ TODO
3637

3738
### Run your Agent
3839

40+
OK, it's time to run your first Agent!
41+
3942
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:
4043

4144
```sh
@@ -54,12 +57,21 @@ Starting local server...
5457
[wrangler:inf] Ready on http://localhost:8787
5558
```
5659

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

6062
### Communicate with your Agent
6163

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

6476
```sh
6577
# The code in this project will automatically create a new Agent on-the-fly when
@@ -70,14 +82,69 @@ wscat --connect "ws://localhost:8787/agents/my-agent/abc123def"
7082
```
7183

7284

85+
#### Agent routing
86+
87+
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+
<TypeScriptExample filename="src/index.ts">
92+
93+
```ts
94+
export default {
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.
102+
return (await routeAgentRequest(request, env, {})) || Response.json({ msg: 'no agent here' }, { status: 404 });
103+
},
104+
} satisfies ExportedHandler<Env>
105+
```
106+
107+
</TypeScriptExample>
108+
109+
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+
73111
### Deploy your Agent
74112

113+
OK, we've:
75114

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
76120

77121
### Extend the Agent
78122

79-
TODO
123+
TODO;
124+
125+
- AI SDK
126+
127+
128+
<TypeScriptExample>
129+
130+
```ts
131+
async aiSDKChat() {
132+
133+
134+
}
135+
```
136+
137+
</TypeScriptExample>
138+
139+
### Optional: Clean-up
140+
141+
TODO: delete
80142

81143
### Next steps
82144

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

Comments
 (0)