Skip to content

Commit 0dfe4ad

Browse files
committed
Cleaning up beginners' guide for Agents docs
1 parent fa7eb46 commit 0dfe4ad

File tree

3 files changed

+80
-77
lines changed

3 files changed

+80
-77
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Get started
3+
pcx_content_type: get-started
4+
sidebar:
5+
order: 2
6+
---
7+
8+
import { Render, PackageManagers, WranglerConfig, TypeScriptExample, Steps } from "~/components";
9+
10+
## Use the starter template
11+
12+
To use the Agent starter template and create your first Agent with the Agents SDK:
13+
14+
<Steps>
15+
1. Create a new project using the `agents-starter` template.
16+
```sh
17+
# install it
18+
npm create cloudflare@latest agents-starter -- --template=cloudflare/agents-starter
19+
```
20+
2. Deploy the project.
21+
22+
```sh
23+
#deploy it
24+
npx wrangler@latest deploy
25+
```
26+
</Steps>
27+
28+
## Manually create an Agent
29+
30+
1. Install the `agents` package directly into an existing project:
31+
32+
```sh
33+
npm i agents
34+
```
35+
36+
2. Define your first Agent by creating a class that extends the `Agent` class:
37+
38+
<TypeScriptExample>
39+
40+
```ts
41+
import { Agent, AgentNamespace } from "agents";
42+
43+
export class MyAgent extends Agent {
44+
// Define methods on the Agent:
45+
// https://developers.cloudflare.com/agents/api-reference/agents-api/
46+
//
47+
// Every Agent has built in state via this.setState and this.sql
48+
// Built-in scheduling via this.schedule
49+
// Agents support WebSockets, HTTP requests, state synchronization and
50+
// can run for seconds, minutes or hours: as long as the tasks need.
51+
}
52+
```
53+
54+
</TypeScriptExample>
55+
56+
3. Add the [Durable Objects](/durable-objects/) binding to your wrangler file:
57+
58+
<WranglerConfig>
59+
```toml
60+
[[durable_objects.bindings]]
61+
name = "MyAgent"
62+
class_name = "MyAgent"
63+
64+
[[migrations]]
65+
tag = "v1"
66+
new_sqlite_classes = ["MyAgent"]
67+
68+
```
69+
</WranglerConfig>
70+
71+
Dive into the [Agent SDK reference](/agents/api-reference/agents-api/) to learn more about how to use the Agents SDK package and defining an `Agent`.

src/content/docs/agents/getting-started/testing-your-agent.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Because Agents run on Cloudflare Workers and Durable Objects, they can be tested
1111

1212
## Writing and running tests
1313

14-
### Setup
14+
### 1. Setup your environment
1515

1616
:::note
1717

@@ -42,7 +42,7 @@ export default defineWorkersConfig({
4242
});
4343
```
4444

45-
### Add the Agent configuration
45+
### 2. Add the Agent configuration
4646

4747
Add a `durableObjects` configuration to `vitest.config.js` with the name of your Agent class:
4848

@@ -65,7 +65,7 @@ export default defineWorkersConfig({
6565
});
6666
```
6767

68-
### Write a test
68+
### 3. Write a test
6969

7070
:::note
7171

@@ -110,7 +110,7 @@ describe("make a request to my Agent", () => {
110110
});
111111
```
112112

113-
### Run tests
113+
### 4. Run tests
114114

115115
Running tests is done using the `vitest` CLI:
116116

src/content/docs/agents/index.mdx

Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Build Agents on Cloudflare
2+
title: Cloudflare Agents
33

44
pcx_content_type: overview
55
tags:
@@ -11,81 +11,13 @@ head:
1111
content: Agents
1212
---
1313

14-
import {
15-
CardGrid,
16-
Description,
17-
Feature,
18-
LinkButton,
19-
LinkTitleCard,
20-
PackageManagers,
21-
Plan,
22-
RelatedProduct,
23-
Render,
24-
TabItem,
25-
Tabs,
26-
TypeScriptExample,
27-
WranglerConfig,
28-
} from "~/components";
14+
import { CardGrid, Description, Feature, LinkButton, LinkTitleCard, PackageManagers, Plan, RelatedProduct, Render, TabItem, Tabs, TypeScriptExample, WranglerConfig } from "~/components";
2915

3016
The Agents SDK enables you to build and deploy AI-powered agents that can autonomously perform tasks, communicate with clients in real time, call AI models, persist state, schedule tasks, run asynchronous workflows, browse the web, query data from your database, support human-in-the-loop interactions, and [a lot more](/agents/api-reference/).
3117

32-
### Ship your first Agent
18+
Try [building a chat agent](https://github.com/cloudflare/agents-starter).
3319

34-
To use the Agent starter template and create your first Agent with the Agents SDK:
35-
36-
```sh
37-
# install it
38-
npm create cloudflare@latest agents-starter -- --template=cloudflare/agents-starter
39-
# and deploy it
40-
npx wrangler@latest deploy
41-
```
42-
43-
Head to the guide on [building a chat agent](/agents/getting-started/build-a-chat-agent) to learn how the starter project is built and how to use it as a foundation for your own agents.
44-
45-
If you're already building on [Workers](/workers/), you can install the `agents` package directly into an existing project:
46-
47-
```sh
48-
npm i agents
49-
```
50-
51-
And then define your first Agent by creating a class that extends the `Agent` class:
52-
53-
<TypeScriptExample>
54-
55-
```ts
56-
import { Agent, AgentNamespace } from "agents";
57-
58-
export class MyAgent extends Agent {
59-
// Define methods on the Agent:
60-
// https://developers.cloudflare.com/agents/api-reference/agents-api/
61-
//
62-
// Every Agent has built in state via this.setState and this.sql
63-
// Built-in scheduling via this.schedule
64-
// Agents support WebSockets, HTTP requests, state synchronization and
65-
// can run for seconds, minutes or hours: as long as the tasks need.
66-
}
67-
```
68-
69-
</TypeScriptExample>
70-
71-
Lastly, add the [Durable Objects](/durable-objects/) binding to your wrangler file:
72-
73-
<WranglerConfig>
74-
```toml
75-
[[durable_objects.bindings]]
76-
name = "MyAgent"
77-
class_name = "MyAgent"
78-
79-
[[migrations]]
80-
tag = "v1"
81-
new_sqlite_classes = ["MyAgent"]
82-
83-
```
84-
</WranglerConfig>
85-
86-
Dive into the [Agent SDK reference](/agents/api-reference/agents-api/) to learn more about how to use the Agents SDK package and defining an `Agent`.
87-
88-
### Why build agents on Cloudflare?
20+
## Why build agents on Cloudflare?
8921

9022
We built the Agents SDK with a few things in mind:
9123

@@ -97,7 +29,7 @@ Agents built with Agents SDK can be deployed directly to Cloudflare and run on t
9729

9830
---
9931

100-
### Build on the Cloudflare Platform
32+
## Build on the Cloudflare Platform
10133

10234
<RelatedProduct header="Workers" href="/workers/" product="workers">
10335

0 commit comments

Comments
 (0)