agents 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -12
- package/dist/{agent-tool-types-Btk9ETS-.d.ts → agent-tool-types-CzGGB-20.d.ts} +403 -115
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-UuScsJg3.d.ts → agent-tools-zR2d5uij.d.ts} +2 -2
- package/dist/agent-tools.d.ts +24 -8
- package/dist/agent-tools.js +14 -6
- package/dist/agent-tools.js.map +1 -1
- package/dist/browser/ai.d.ts +5 -3
- package/dist/browser/ai.js +86 -7
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/tanstack-ai.js +13 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +31 -2
- package/dist/chat/index.js +57 -2
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +5 -179
- package/dist/chat/react.js +18 -555
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/transport.d.ts +10 -0
- package/dist/chat/transport.js +2 -0
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/cloudflare-BduZwmYK.js +204 -0
- package/dist/cloudflare-BduZwmYK.js.map +1 -0
- package/dist/{connector-v2M1zlZp.d.ts → connector-CkQD4MK3.d.ts} +20 -3
- package/dist/{connector-KEJnl6e5.js → connector-CptFKzRh.js} +158 -40
- package/dist/connector-CptFKzRh.js.map +1 -0
- package/dist/{handler-stateless-8hQN_kC3.js → handler-stateless-CIkKPETH.js} +20 -69
- package/dist/handler-stateless-CIkKPETH.js.map +1 -0
- package/dist/index.d.ts +21 -11
- package/dist/index.js +31 -21
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +20 -20
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +32 -98
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/observability/ai/index.d.ts +10 -131
- package/dist/observability/ai/index.js +209 -444
- package/dist/observability/ai/index.js.map +1 -1
- package/dist/{wire-types-CU9rLoeS.js → protocol-Dqc2MQxo.js} +2 -46
- package/dist/protocol-Dqc2MQxo.js.map +1 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +5 -8
- package/dist/react.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sub-routing.d.ts +18 -6
- package/dist/sub-routing.js +92 -2
- package/dist/sub-routing.js.map +1 -1
- package/dist/wire-types-CnMt6_HR.js +47 -0
- package/dist/wire-types-CnMt6_HR.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +22 -22
- package/dist/ws-chat-transport-CIoOBbO7.js +561 -0
- package/dist/ws-chat-transport-CIoOBbO7.js.map +1 -0
- package/dist/ws-chat-transport-UNRIS2xl.d.ts +184 -0
- package/docs/adding-to-existing-project.md +4 -2
- package/docs/agent-class.md +1 -1
- package/docs/agent-tools.md +29 -0
- package/docs/browse-the-web.md +16 -1
- package/docs/chat-agents.md +3 -1
- package/docs/client-sdk.md +12 -8
- package/docs/configuration.md +7 -1
- package/docs/cross-domain-authentication.md +7 -35
- package/docs/email.md +2 -13
- package/docs/human-in-the-loop.md +15 -12
- package/docs/long-running-agents.md +11 -11
- package/docs/mcp-client.md +1 -1
- package/docs/mcp-servers.md +7 -1
- package/docs/mcp-transports.md +18 -12
- package/docs/migration-to-ai-sdk-v5.md +2 -2
- package/docs/migration-to-ai-sdk-v6.md +5 -1
- package/docs/observability.md +24 -67
- package/docs/routing.md +27 -0
- package/docs/sub-agents.md +47 -2
- package/docs/webhooks.md +109 -136
- package/docs/workflows.md +9 -1
- package/package.json +19 -10
- package/dist/cloudflare-BldFV0Pa.js +0 -117
- package/dist/cloudflare-BldFV0Pa.js.map +0 -1
- package/dist/connector-KEJnl6e5.js.map +0 -1
- package/dist/handler-stateless-8hQN_kC3.js.map +0 -1
- package/dist/wire-types-CU9rLoeS.js.map +0 -1
- package/dist/workflow-types-Baz_PO5v.d.ts +0 -280
package/README.md
CHANGED
|
@@ -16,6 +16,11 @@ Or add to an existing project:
|
|
|
16
16
|
npm install agents
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
The examples below use `@callable()` decorators. Vite projects must extend
|
|
20
|
+
`agents/tsconfig` and add the `agents/vite` plugin; other bundlers must support
|
|
21
|
+
TC39 decorators (`2023-11`). See
|
|
22
|
+
[Adding Agents to an Existing Project](../../docs/agents/adding-to-existing-project.md#4-configure-typescript-and-vite).
|
|
23
|
+
|
|
19
24
|
---
|
|
20
25
|
|
|
21
26
|
## Why Agents, Why Now
|
|
@@ -44,7 +49,7 @@ A counter agent with real-time state sync and callable methods:
|
|
|
44
49
|
// server.ts
|
|
45
50
|
import { Agent, callable } from "agents";
|
|
46
51
|
|
|
47
|
-
type State = { count: number };
|
|
52
|
+
export type State = { count: number };
|
|
48
53
|
|
|
49
54
|
export class CounterAgent extends Agent<Env, State> {
|
|
50
55
|
initialState: State = { count: 0 };
|
|
@@ -67,11 +72,12 @@ export class CounterAgent extends Agent<Env, State> {
|
|
|
67
72
|
// client.tsx
|
|
68
73
|
import { useAgent } from "agents/react";
|
|
69
74
|
import { useState } from "react";
|
|
75
|
+
import type { CounterAgent, State } from "./server";
|
|
70
76
|
|
|
71
77
|
function Counter() {
|
|
72
78
|
const [count, setCount] = useState(0);
|
|
73
79
|
|
|
74
|
-
const agent = useAgent<State>({
|
|
80
|
+
const agent = useAgent<CounterAgent, State>({
|
|
75
81
|
agent: "counter-agent",
|
|
76
82
|
name: "my-counter",
|
|
77
83
|
onStateUpdate: (state) => setCount(state.count)
|
|
@@ -120,8 +126,12 @@ Platform Observability · Cross-domain auth · Resumable streams
|
|
|
120
126
|
State persists across requests and syncs to all connected clients:
|
|
121
127
|
|
|
122
128
|
```typescript
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
import { Agent, callable, type Connection } from "agents";
|
|
130
|
+
|
|
131
|
+
type State = { items: string[] };
|
|
132
|
+
|
|
133
|
+
export class MyAgent extends Agent<Env, State> {
|
|
134
|
+
initialState: State = { items: [] };
|
|
125
135
|
|
|
126
136
|
@callable()
|
|
127
137
|
addItem(item: string) {
|
|
@@ -262,6 +272,29 @@ export class Assistant extends Think<Env> {
|
|
|
262
272
|
}
|
|
263
273
|
```
|
|
264
274
|
|
|
275
|
+
`inputSchema` accepts schemas supported by the AI SDK, including Zod, Standard
|
|
276
|
+
JSON Schema-compatible schemas, raw JSON Schema through `jsonSchema()`, and
|
|
277
|
+
schemas exposed through AI SDK adapters. For example, use `@ai-sdk/valibot` v2
|
|
278
|
+
with AI SDK 6 or v3 with AI SDK 7:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { valibotSchema } from "@ai-sdk/valibot";
|
|
282
|
+
import * as v from "valibot";
|
|
283
|
+
|
|
284
|
+
const researchInput = valibotSchema(
|
|
285
|
+
v.object({ query: v.pipe(v.string(), v.minLength(3)) })
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
agentTool(Researcher, {
|
|
289
|
+
description: "Research one topic in depth.",
|
|
290
|
+
inputSchema: researchInput
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Tool inputs need model-facing JSON Schema in addition to runtime validation. A
|
|
295
|
+
validation-only Standard Schema is therefore insufficient; use its Standard
|
|
296
|
+
JSON Schema extension or an AI SDK adapter.
|
|
297
|
+
|
|
265
298
|
For deterministic fan-out, call `this.runAgentTool(Researcher, { input })`
|
|
266
299
|
directly. Parent recovery reconciles stale child rows after restarts and marks
|
|
267
300
|
unrecoverable runs `interrupted` instead of hanging. In React, use
|
|
@@ -294,7 +327,9 @@ async onClose(connection: Connection) {
|
|
|
294
327
|
Agents can receive and respond to emails:
|
|
295
328
|
|
|
296
329
|
```typescript
|
|
297
|
-
|
|
330
|
+
import type { AgentEmail } from "agents/email";
|
|
331
|
+
|
|
332
|
+
async onEmail(email: AgentEmail) {
|
|
298
333
|
const from = email.from;
|
|
299
334
|
const subject = email.headers.get("subject");
|
|
300
335
|
// Process incoming email
|
|
@@ -392,15 +427,18 @@ For AI-powered chat experiences with persistent conversations, streaming respons
|
|
|
392
427
|
|
|
393
428
|
```typescript
|
|
394
429
|
import { AIChatAgent } from "@cloudflare/ai-chat";
|
|
430
|
+
import { createWorkersAI } from "workers-ai-provider";
|
|
431
|
+
import { convertToModelMessages, streamText } from "ai";
|
|
395
432
|
|
|
396
433
|
export class ChatAgent extends AIChatAgent<Env> {
|
|
397
|
-
async onChatMessage(
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
onFinish
|
|
434
|
+
async onChatMessage() {
|
|
435
|
+
const workersai = createWorkersAI({ binding: this.env.AI });
|
|
436
|
+
const result = streamText({
|
|
437
|
+
model: workersai("@cf/moonshotai/kimi-k2.7-code"),
|
|
438
|
+
messages: await convertToModelMessages(this.messages)
|
|
403
439
|
});
|
|
440
|
+
|
|
441
|
+
return result.toUIMessageStreamResponse();
|
|
404
442
|
}
|
|
405
443
|
}
|
|
406
444
|
```
|
|
@@ -409,7 +447,7 @@ export class ChatAgent extends AIChatAgent<Env> {
|
|
|
409
447
|
// Client
|
|
410
448
|
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
411
449
|
|
|
412
|
-
const { messages,
|
|
450
|
+
const { messages, sendMessage } = useAgentChat({
|
|
413
451
|
agent: useAgent({ agent: "chat-agent" })
|
|
414
452
|
});
|
|
415
453
|
```
|