Skip to content

Commit 2f37e7f

Browse files
committed
unique partial
1 parent 11f058c commit 2f37e7f

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ An Agent can have many (millions of) instances: each instance is a separate micr
3030

3131
Instances of an Agent are addressed by a unique identifier: that identifier (ID) can be the user ID, an email address, GitHub username, a flight ticket number, an invoice ID, or any other identifier that helps to uniquely identify the instance and for whom it is acting on behalf of.
3232

33+
<Render file="unique-agents" />
34+
3335
### Agent
3436

3537
Writing an Agent requires you to define a class that extends the `Agent` class from the `agents-sdk` package. An Agent encapsulates all of the logic for an Agent, including how clients can connect to it, how it stores state, the methods it exposes, and any error handling.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Learn how to call your Agents from Workers, including how to create Agents on-th
1414

1515
Agents are created on-the-fly and can serve multiple requests concurrently. Each Agent instance is isolated from other instances, can maintain its own state, and has a unique address.
1616

17+
<Render file="unique-agents" />
18+
1719
You can create and run an instance of an Agent directly from a Worker in one of three ways:
1820

1921
1. Using the `routeAgentRequest` helper: this will automatically map requests to an individual Agent based on the `/agents/:agent/:name` URL pattern. The value of `:agent` will be the name of your Agent class converted to `kebab-case`, and the value of `:name` will be the name of the Agent instance you want to create or retrieve.

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Inside this directory, there are a number of files, but we only need to worry ab
3939

4040
Let's take a look at how the Agent in the quick start is defined.
4141

42+
:::note[Escape hatch]
43+
44+
You can escape from the rest of this quickstart guide right here: run `npm run start` to run the code locally, open `src/index.ts` to explore the code, and run `npx wrangler@latest deploy` to deploy it your Cloudflare account.
45+
46+
The rest of this quickstart briefly steps through the code and sending requests to the Agent: if this is your first time using the Agents SDK and/or Cloudflare Workers, you'll likely want to keep reading.
47+
48+
:::
49+
4250
### Understand the Agent class
4351

4452
Open the `src/index.ts` file in your editor:
@@ -71,33 +79,23 @@ Your Agent is now running locally on your machine, and ready to communicate with
7179

7280
### Communicate with your Agent
7381

74-
Let's communicate with your Agent and have it run a simple task.
82+
Let's communicate with your Agent and have it book us a flight (well, pretend to).
7583

76-
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.
77-
78-
Install `wscat`:
79-
80-
```sh
81-
npm install -g wscat
82-
```
83-
84-
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.
85-
86-
```sh
87-
# The code in this project will automatically create a new Agent on-the-fly when
88-
# you provide a name: e.g. /agents/my-agent/foo or /agents/my-agent/user-1238139
89-
# This allows you to create as many Agents as you want, each with their own
90-
# state and able to manage their own tasks.
91-
wscat --connect "ws://localhost:8787/agents/my-agent/abc123def"
92-
```
84+
TODO:
9385

86+
- Make a request for a booking
87+
- get a response
88+
- confirm the booking
89+
- get the booked flight
9490

9591

9692
#### Agent routing
9793

9894
In the `agents-quick-start` we use the `routeAgentRequest` helper to automatically handle routing to existing and creating new Agent instances on-the-fly.
9995

100-
If you open up `src/index.ts`,
96+
If you open up `src/index.ts`, you'll see that `routeAgentRequest` handles requests to `/agents/:agent/:name` - in our case, that's `/agents/flight-agent/:name`, where name is a unique identifier for that Agent instance.
97+
98+
<Render file="unique-agents" />
10199

102100
<TypeScriptExample filename="src/index.ts">
103101

@@ -117,7 +115,7 @@ export default {
117115

118116
</TypeScriptExample>
119117

120-
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/).
118+
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 the [documentation on calling Agents](/agents/api-reference/calling-agents/).
121119

122120
### Ship to production
123121

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
{}
3+
4+
---
5+
6+
:::note
7+
8+
An instance of an Agent is globally unique: given the same name (or ID), you will always get the same instance of an agent. This means that you don't have to synchronize state across requests: if an Agent instance represents a specific user, team, channel or other entity, you can use the Agent instance to store state for that entity.
9+
10+
If the client disconnects, you can always route the client back to the exact same Agent and pick up where they left off.
11+
12+
:::

0 commit comments

Comments
 (0)