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 deploywrangler devAll workers expose the same REST API:
Returns information about the agent.
Health check endpoint.
Send a message and receive a response.
curl -X POST https://your-worker.workers.dev/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello!"}'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- No persistent storage (PGLite not available in Workers)
- Runtime is initialized per-request
- For persistent state, use Cloudflare Durable Objects
For production deployments:
- Use the TypeScript worker for the best elizaOS integration
- Use Cloudflare KV or Durable Objects for conversation state
- Set proper rate limits in your wrangler.toml
- Monitor with Cloudflare Analytics
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);