Build Custom Agent (LEGACY)
DEPRECATED - This guide describes building agents for the legacy multi-agent system that was removed in December 2024.
DEPRECATION NOTICE: This document describes building custom agents for the legacy multi-agent routing system which was removed in December 2024. The system now uses a single
CloudflareChatAgentwith built-in tools. To extend functionality, create new tools instead of new agents. See custom-tools.md for current approach.
Legacy Documentation
TL;DR (Historical): Extend BaseAgent. Add class/bind in shared-agents. bun run deploy:shared-agents. Test via Telegram!
📋 Prerequisites
- Getting Started ->
- Deployed:
bun run deploy:shared-agents
🛠️ Step 1: Create Agent
In packages/cloudflare-agent/src/agents/:
Export in index.ts:
🔗 Step 2: Bind DO
In apps/shared-agents/wrangler.toml:
🚀 Step 3: Deploy & Test
Router auto-routes "weather" queries.
Test Telegram: "What's Hanoi weather?"
Expect: "Weather: 28°C sunny"
🔄 Agent Flow
🎯 Quiz
Q: Bind new DO where?
A: shared-agents/wrangler.toml ✅
Pro Tip: Add pattern /weather/i in router for fast route.
Custom Durable Objects
TL;DR: class MyAgent extends Agent<MyEnv, MyState>. handle(ctx). agentRegistry.register({name:'my-agent',...}). Import agents/index.ts. ✅ Routed.
Extend Base
From base-agent.ts:
Register
In agents/my-agent.ts:
Import agents/my-agent.ts in agents/index.ts.
Router Auto-Uses
Registry builds classification prompt dynamically registry.ts.
Quiz: Registration where? A: agentRegistry.register() ✅
Pro Tip ✅: Priority 100 for HITL.
🚀 Next
Telegram Setup -> Build now: Add WeatherAgent! {{t('agent.live')}}