Skip to content

Commit ffeeff3

Browse files
elithrarOxyjun
authored andcommitted
agents: update nav + add quickstart (#20339)
* commit * sidebar ordering * name * add API reference * fix intro * store and sync state * SDK ref * initial state * fix MDX syntax * improve API ref * fix broken link * re-title * updates * fix frontmatter * calling agents * updates * quickstart * agents * update * updates * fix * SSE * sse * auth * add redirect * ok * unique partial * headers * agents docs * updates * more * agents-sdk -> agents * changelog headers / order * fix image name * import Badge * fix * IMAGE COMPONENT * fixed image * reorder * update * update API ref * update * update * \n * fix example * ok * Fix * example linting * fix * fix * date * fix * fix * ok * reference * update * fix changelog * fix typo * ok * ok * icon * ok * k * Apply suggestions from code review Co-authored-by: Jun Lee <[email protected]> * agents -> agents-sdk elsewhere --------- Co-authored-by: Jun Lee <[email protected]>
1 parent 33da23e commit ffeeff3

29 files changed

+1655
-288
lines changed

public/_redirects

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@
9898

9999
# agents
100100
/agents/build/prompts/ /workers/get-started/prompting/ 301
101+
/agents/examples/browse-the-web/ /agents/api-reference/browse-the-web/ 301
102+
/agents/examples/manage-and-sync-state/ /agents/api-reference/store-and-sync-state/ 301
103+
/agents/examples/rag/ /agents/api-reference/rag/ 301
104+
/agents/examples/run-workflows/ /agents/api-reference/run-workflows/ 301
105+
/agents/examples/schedule-tasks/ /agents/api-reference/schedule-tasks/ 301
106+
/agents/examples/using-ai-models/ /agents/api-reference/using-ai-models/ 301
107+
/agents/examples/websockets/ /agents/api-reference/websockets/ 301
108+
/agents/examples/sdk/ /agents/api-reference/agents-api/ 301
109+
/agents/examples/build-mcp-server/ /agents/api-reference/build-mcp-server/ 301
101110

102111
# ai
103112
/ai/ /use-cases/ai/ 301
650 KB
Binary file not shown.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
---
2-
title: Introducing the agents-sdk
3-
description: Build and ship AI Agents on Cloudflare using the agents-sdk
2+
title: Introducing the Agents SDK
3+
description: Build and ship AI Agents on Cloudflare using the Agents SDK
44
products:
55
- agents
66
- workers
77
date: 2025-02-25T14:00:00Z
88
---
99

10-
We've released the [agents-sdk](http://blog.cloudflare.com/build-ai-agents-on-cloudflare/), a package and set of tools that help you build and ship AI Agents.
10+
We've released the [Agents SDK](http://blog.cloudflare.com/build-ai-agents-on-cloudflare/), a package and set of tools that help you build and ship AI Agents.
1111

12-
You can get up and running with a [chat-based AI Agent](https://github.com/cloudflare/agents-starter) (and deploy it to Workers) that uses the `agents-sdk`, tool calling, and state syncing with a React-based front-end by running the following command:
12+
You can get up and running with a [chat-based AI Agent](https://github.com/cloudflare/agents-starter) (and deploy it to Workers) that uses the Agents SDK, tool calling, and state syncing with a React-based front-end by running the following command:
1313

1414
```sh
1515
npm create cloudflare@latest agents-starter -- --template="cloudflare/agents-starter"
1616
# open up README.md and follow the instructions
1717
```
1818

19-
You can also add an Agent to any existing Workers application by installing the `agents-sdk` package directly
19+
You can also add an Agent to any existing Workers application by installing the `agents` package directly
2020

2121
```sh
22-
npm i agents-sdk
22+
npm i agents
2323
```
2424

2525
... and then define your first Agent:
2626

2727
```ts
28-
import { Agent } from 'agents-sdk';
28+
import { Agent } from 'agents';
2929

3030
export class YourAgent extends Agent<Env> {
3131
// Build it out
@@ -37,4 +37,4 @@ export class YourAgent extends Agent<Env> {
3737
}
3838
```
3939

40-
Head over to the [Agents documentation](/agents/) to learn more about the `agents-sdk`, the SDK APIs, as well as how to test and deploying agents to production.
40+
Head over to the [Agents documentation](/agents/) to learn more about the Agents SDK, the SDK APIs, as well as how to test and deploying agents to production.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: npm i agents
3+
description: Install the latest version of the `agents` SDK to build multi-agent applications, use the new RPC API, and visit the latest documentation updates.
4+
products:
5+
- agents
6+
- workers
7+
date: 2025-03-18T14:00:00Z
8+
---
9+
10+
import { Badge, MetaInfo, Render, TypeScriptExample } from "~/components"
11+
import { Image } from 'astro:assets';
12+
import npmAgentsAnimated from "~/assets/images/agents/npm-i-agents.apng"
13+
14+
<Image src={npmAgentsAnimated} alt="npm i agents" width="1000" height="541" />
15+
16+
#### `agents-sdk` -> `agents` <Badge text="Updated" variant="tip" size="small" />
17+
18+
📝 **We've renamed the Agents package to `agents`**!
19+
20+
If you've already been building with the Agents SDK, you can update your dependencies to use the new package name, and replace references to `agents-sdk` with `agents`:
21+
22+
```sh
23+
# Install the new package
24+
npm i agents
25+
```
26+
27+
```sh
28+
# Remove the old (deprecated) package
29+
npm uninstall agents-sdk
30+
31+
# Find instances of the old package name in your codebase
32+
grep -r 'agents-sdk' .
33+
# Replace instances of the old package name with the new one
34+
# (or use find-replace in your editor)
35+
sed -i 's/agents-sdk/agents/g' $(grep -rl 'agents-sdk' .)
36+
```
37+
38+
All future updates will be pushed to the new `agents` package, and the older package has been marked as deprecated.
39+
40+
#### Agents SDK updates <Badge text="New" variant="tip" size="small" />
41+
42+
We've added a number of big new features to the Agents SDK over the past few weeks, including:
43+
44+
- You can now set `cors: true` when using `routeAgentRequest` to return permissive default CORS headers to Agent responses.
45+
- The regular client now syncs state on the agent (just like the React version).
46+
- `useAgentChat` bug fixes for passing headers/credentials, includng properly clearing cache on unmount.
47+
- Experimental `/schedule` module with a prompt/schema for adding scheduling to your app (with evals!).
48+
- Changed the internal `zod` schema to be compatible with the limitations of Google's Gemini models by removing the discriminated union, allowing you to use Gemini models with the scheduling API.
49+
50+
We've also fixed a number of bugs with state synchronization and the React hooks.
51+
52+
<TypeScriptExample>
53+
54+
```ts
55+
// via https://github.com/cloudflare/agents/tree/main/examples/cross-domain
56+
export default {
57+
async fetch(request: Request, env: Env) {
58+
return (
59+
// Set { cors: true } to enable CORS headers.
60+
(await routeAgentRequest(request, env, { cors: true })) ||
61+
new Response("Not found", { status: 404 })
62+
);
63+
},
64+
} satisfies ExportedHandler<Env>;
65+
```
66+
67+
</TypeScriptExample>
68+
69+
#### Call Agent methods from your client code <Badge text="New" variant="tip" size="small" />
70+
71+
We've added a new [`@unstable_callable()`](/agents/api-reference/agents-api/) decorator for defining methods that can be called directly from clients. This allows you call methods from within your client code: you can call methods (with arguments) and get native JavaScript objects back.
72+
73+
<TypeScriptExample>
74+
75+
```ts
76+
// server.ts
77+
import { unstable_callable, Agent, type StreamingResponse } from "agents";
78+
import type { Env } from "../server";
79+
80+
export class Rpc extends Agent<Env> {
81+
// Use the decorator to define a callable method
82+
@unstable_callable({
83+
description: "rpc test",
84+
})
85+
async getHistory() {
86+
return this.sql`SELECT * FROM history ORDER BY created_at DESC LIMIT 10`;
87+
}
88+
}
89+
```
90+
```tsx
91+
// client.tsx
92+
const { call } = useAgent({ agent: "rpc" });
93+
94+
const fetchUserHistory = async () => {
95+
try {
96+
setLoading(true);
97+
// Call methods directly on the Agent!
98+
const result = await call("getHistory");
99+
addToast(`RPC result: ${result}`, "success");
100+
} catch (error) {
101+
addToast(`Error: ${error}`, "error");
102+
} finally {
103+
setLoading(false);
104+
}
105+
};
106+
```
107+
108+
</TypeScriptExample>
109+
110+
#### agents-starter <Badge text="Updated" variant="tip" size="small" />
111+
112+
The [`agents-starter`](https://github.com/cloudflare/agents-starter) project — a real-time, chat-based example application with tool-calling & human-in-the-loop built using the Agents SDK — has seen the following updates:
113+
114+
- Upgraded to use the latest [wrangler v4](/changelog/2025-03-13-wrangler-v4/) release.
115+
- [Workers AI](/workers-ai/) is now the default AI provider in the [`agents-starter`](https://github.com/cloudflare/agents-starter) project: this uses the new [structured outputs](/changelog/2025-02-25-json-mode/) (or "JSON mode") support now in Workers AI and the [`workers-ai-provider`](https://sdk.vercel.ai/providers/community-providers/cloudflare-workers-ai#generateobject).
116+
117+
If you're new to Agents, you can install and run the `agents-starter` project in two commands:
118+
119+
```sh
120+
# Install it
121+
$ npm create cloudflare@latest agents-starter -- --template="cloudflare/agents-starter"
122+
# Run it
123+
$ npm run start
124+
```
125+
126+
#### More documentation <Badge text="Updated" variant="tip" size="small" />
127+
128+
We've heard your feedback on the Agents SDK documentation, and we're shipping more API reference material and usage examples, including:
129+
130+
- Expanded [API reference documentation](/agents/api-reference/), covering the methods and properties exposed by the Agents SDK, as well as more usage examples.
131+
- More [Client API](/agents/api-reference/agents-api/#client-api) documentation that documents `useAgent`, `useAgentChat` and the new `@unstable_callable` RPC decorator exposed by the SDK.
132+
- New documentation on how to [call agents](/agents/api-reference/calling-agents/) and (optionally) authenticate clients before they connect to your Agents.
133+
134+
Note that the Agents SDK is continually growing: the type definitions included in the SDK will always include the latest APIs exposed by the `agents` package.
135+
136+
If you're still wondering what Agents are, [read our blog on building AI Agents on Cloudflare](https://blog.cloudflare.com/build-ai-agents-on-cloudflare/) and/or visit the [Agents documentation](/agents/) to learn more.

0 commit comments

Comments
 (0)