Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ npm install @cloudflare/agents

```ts
import { Agent } from "@cloudflare/agents";
import openai from "openai";
import { OpenAI } from "openai";

export class MyAgent extends Agent {
async onRequest(request) {
// ... run your agentic workflow in here
// use ai sdk, langchain, direct calls to openai, anthropic, etc.
// combine with KV, D1, R2, vectorize, etc.
const llm = openai("gpt-4o");
const llm = new OpenAI({
apiKey: this.env.OPENAI_API_KEY,
});
const result = await llm.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello, world!" }],
Expand All @@ -67,7 +69,14 @@ export class MyAgent extends Agent {
"class_name": "MyAgent"
}
]
}
},
"migrations": [
{
"tag": "v1",
// Mandatory for the Agent to store state
"new_sqlite_classes": ["MyAgent"],
},
],
}
```

Expand Down