packages/examples/cloudflare/README.md
Deploy elizaOS agents as serverless functions on Cloudflare Workers.
| Worker | Language | Full Runtime | Notes |
|---|---|---|---|
| TypeScript | TypeScript | Yes | Uses full elizaOS runtime (recommended) |
The TypeScript worker uses the canonical elizaOS implementation pattern:
// Create runtime with plugins
const runtime = new AgentRuntime({
character,
plugins: [openaiPlugin],
});
await runtime.initialize();
// Process messages through the message service
await runtime.messageService?.handleMessage(runtime, messageMemory, callback);
# Install dependencies
bun install
# Configure environment
cp wrangler.toml.example wrangler.toml
# Edit wrangler.toml and add your OPENAI_API_KEY
# Deploy
wrangler deploy
wrangler dev
All workers expose the same REST API:
GET /Returns information about the agent.
GET /healthHealth check endpoint.
POST /chatSend a message and receive a response.
curl -X POST https://your-worker.workers.dev/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello!"}'
POST /chat/stream (TypeScript only)Send a message and receive a streaming response.
Configure these in your wrangler.toml:
[vars]
CHARACTER_NAME = "Eliza"
CHARACTER_BIO = "A helpful AI assistant"
[[secrets]]
OPENAI_API_KEY = "your-key" # Use wrangler secret put OPENAI_API_KEY
For production deployments:
All workers should follow this pattern (where runtime is available):
// 1. Create runtime with plugins
const runtime = new AgentRuntime({
character,
plugins: [openaiPlugin],
});
// 2. Initialize
await runtime.initialize();
// 3. Ensure connection
await runtime.ensureConnection({
entityId: userId,
roomId,
worldId,
userName: "User",
source: "cloudflare",
channelId: "worker-chat",
type: ChannelType.API,
});
// 4. Create message memory
const messageMemory = createMessageMemory({
id: uuidv4(),
entityId: userId,
roomId,
content: { text: message, source: "cloudflare_worker" },
});
// 5. Process through message service
await runtime.messageService?.handleMessage(runtime, messageMemory, callback);