5‑10个专业化AI智能体的部署蓝图,包含角色设计、跨智能体路由、Telegram集成以及成本高效的分层模型测试。
A production-tested template for setting up 5-10 specialized AI agents that work together as a team. Based on a real deployment running 10 agents across Telegram with cross-agent routing, model tiering, and centralized file management.
sessions_send with working session keystext
┌─────────────────────────────────────────────┐
│ USER │
│ (Telegram / Discord / WhatsApp) │
└──────────┬──────────────────────┬───────────┘
│ DM │ @mention
┌─────▼─────┐ ┌─────▼─────┐
│ CENTRAL │ │ GROUP │
│ (Coordi- │◄───────►│ CHAT │
│ nator) │ routes │ (all bots)│
└─────┬─────┘ └───────────┘
│ sessions_send
┌─────┼─────┬──────┬──────┬──────┐
▼ ▼ ▼ ▼ ▼ ▼
TECH FINANCE SALES HEALTH MKTG DATA
│ │
▼ ▼
NAS NOTION
(File Master) (DB Master)
Pick 3-10 roles based on your needs:
RoleModel TierExample TasksCoordinatorOpusRoute tasks, oversee projects, daily briefingsTech/InfraOpus/SonnetDevOps, file management, system adminFinanceSonnetInvoices, budgets, tax prep, contractsSalesHaikuLead gen, outreach scripts, deal trackingMarketingHaikuContent creation, SEO, social mediaHealthSonnetFitness tracking, meal plans, habit coachingData/NotionSonnetDatabase ops, reporting, documentationDevOpsHaikuMonitoring, alerts, uptime checksE-CommerceSonnetStore audits, product strategy, analyticsSocial/BrandExternal*Twitter/X, LinkedIn, content scheduling
*Social agents can use specialized providers like xAI/Grok for platform-native tone.
bash
# For each agent:
mkdir -p ~/.openclaw/workspace-{agentname}/memory
mkdir -p ~/.openclaw/agents/{agentname}/agent
Add each agent to openclaw.json → agents.list:
json5
{
"id": "finance",
"name": "finance",
"workspace": "~/.openclaw/workspace-finance",
"agentDir": "~/.openclaw/agents/finance/agent",
"model": "anthropic/claude-sonnet-4-5"
}
Enable cross-agent communication:
json5
{
"agentToAgent": { "enabled": true }
}
Each agent needs 4 files in their agentDir:
markdown
# IDENTITY.md
- **Name:** Atlas
- **Creature:** AI Finance & Legal Advisor
- **Vibe:** Professional, precise, trustworthy
markdown
# SOUL.md
You are Atlas. Finance & Legal specialist.
PERSONALITY:
- Professional but approachable
- Numbers-driven, always backs claims with data
- Proactively flags risks and deadlines
EXPERTISE:
- Invoice management, expense tracking
- Tax preparation and compliance
- Contract review and negotiation support
RESPONSE LENGTH:
- DEFAULT: 2-5 sentences. Telegram, not blog posts.
- Short question = short answer. "Done.", "Yes.", "Sent." are fine.
- Longer responses ONLY for: financial breakdowns, step-by-step guides, or when explicitly asked.
- No introductions. Get to the point.
- No repeating the question back.
markdown
# AGENT OPERATING SYSTEM — Atlas
## My Role
Finance & Legal. Invoices, budgets, contracts, tax.
## Cross-Agent Routing
| What | Where | How |
|------|-------|-----|
| Coordination | Central | sessions_send(sessionKey="agent:central:main", ...) |
| File Storage | Tech | sessions_send(sessionKey="agent:techops:main", ...) |
| Database/Notion | Data | sessions_send(sessionKey="agent:data:main", ...) |
| Sales Numbers | Sales | sessions_send(sessionKey="agent:sales:main", ...) |
## What I Handle
- Invoice creation and tracking
- Budget reports and forecasts
- Contract review
- Tax document preparation
## What I DON'T Handle
- File storage → Tech agent (File Master)
- Database updates → Data agent (Notion Master)
- Marketing spend analysis → Marketing agent
markdown
# USER.md
- **Name:** [Your name]
- **Timezone:** Europe/Berlin
- **Business:** [Your business]
- **Language:** English (casual)
Create a Telegram bot per agent via @BotFather, then configure:
json5
// openclaw.json
{
// CRITICAL: This prevents session collision between bots
"session": { "dmScope": "per-account-channel-peer" },
"channels": {
"telegram": {
// DO NOT put botToken here at top level — causes double responses
"accounts": {
"finance": {
"botToken": "YOUR_BOT_TOKEN",
"dmPolicy": "allowlist",
"allowFrom": ["YOUR_TELEGRAM_ID"],
"groups": {
"-YOUR_GROUP_ID": { "requireMention": true }
}
}
}
}
},
"bindings": [
{
"agentId": "finance",
"match": { "channel": "telegram", "accountId": "finance" }
}
]
}
Critical settings:
dmScope: "per-account-channel-peer" — prevents session collision between botsrequireMention: true — bots only respond when @mentioned in groupsbotToken — causes duplicate responsesaccountId matching a bindingjson5
{
"models": {
"fallbackOrder": [
"anthropic/claude-opus-4-6",
"anthropic/claude-sonnet-4-5",
"google-gemini-cli/gemini-2.5-flash",
"ollama/llama3.2:3b",
"openrouter/anthropic/claude-sonnet-4"
]
}
}
Why fallback chains matter:
json5
{
"agents": {
"defaults": {
// Heartbeats on FREE local model — saves hundreds of API calls/day
"heartbeat": { "every": "30m", "model": "ollama/llama3.2:3b" },
// Auto-prune old context to reduce token usage
"contextPruning": { "mode": "cache-ttl", "ttl": "5m" },
// Memory search with caching
"memorySearch": { "enabled": true, "cache": { "enabled": true } },
// Enable prompt caching (huge savings on Anthropic)
"models": {
"anthropic/claude-opus-4-6": { "params": { "cacheRetention": "long" } },
"anthropic/claude-sonnet-4-5": { "params": { "cacheRetention": "long" } },
"anthropic/claude-haiku-4-5": { "params": { "cacheRetention": "none" } }
}
}
}
}
Give agents persistent memory across session resets:
json5
{
"agents": {
"defaults": {
"memorySearch": {
"enabled": true,
"providers": ["local"], // local = free, no API costs
"search": { "mode": "hybrid" }, // BM25 + vector
"cache": { "enabled": true, "maxEntries": 50000 }
}
}
}
}
Agents store important context in memory/*.md files before session compaction. On next session, memory_search retrieves relevant snippets automatically.
Route ALL file operations through ONE agent:
text
Agent → sessions_send → File Master → SSH → NAS
↓
Confirmation back
Route ALL database operations through ONE agent:
text
Agent → sessions_send → DB Master → Notion API → Database
↓
Confirmation back
One central agent acts as router:
sessions_sendUser talks directly to specialist when they know what they need:
Multiple agents in one Telegram group with requireMention: true:
Agents talk to each other via sessions_send:
javascript
// From any agent's tool call:
sessions_send({
sessionKey: "agent:techops:main",
message: "Store this file on NAS: quarterly-report.pdf at /finance/reports/"
})
Session key format: agent:{agentId}:main
Important: The receiving agent processes the message in its own session with its own tools and permissions. Responses route back automatically.
TierModelMonthly Cost*Best ForPremiumOpus 4.6$$$Coordinator + Tech Lead (complex reasoning, multi-step)StandardSonnet 4.5$$Finance, Health, Data (good reasoning, cheaper)EconomyHaiku 4.5$Sales, Marketing, DevOps (simple tasks, fast)FreeOllama local$0Heartbeats, health checksExternalxAI Grok / GPTVariesSpecialized tasks (social media, research)
*With Claude subscription, most usage is covered. Haiku agents are nearly free.
Rule of thumb: Use the cheapest model that gets the job done. You can always upgrade individual agents later.
#MistakeFix1All agents on OpusUse tiering — Haiku handles 70% of tasks fine2No dmScope: per-account-channel-peerSession collision — bots share state incorrectly3No requireMention: true in groupsBots respond to every message (chaos)4Top-level botToken in telegram configCauses double responses — put tokens in accounts only5Missing agentToAgent.enabled: trueCross-agent routing silently fails6No memory flush before compactionContext lost on session reset7Multiple agents doing file ops directlyInconsistent state, race conditions8Same workspace for multiple agentsFile conflicts and memory collision9No fallback chainSingle provider outage = all agents down10Forgetting to sync agentDir ↔ workspaceConfig drift between the two locations
text
Coordinator (Opus) → Tech (Sonnet) → Sales (Haiku)
Covers 80% of needs. Add more only when a clear role gap appears.
text
Coordinator → Tech → Finance → Sales → Marketing
→ Data/Notion
text
Coordinator → Tech (File Master)
→ Finance/Legal
→ Sales
→ Marketing
→ Health/Personal
→ Data/Notion (DB Master)
→ DevOps (Monitoring)
→ E-Commerce
→ Social/Brand
Team SizeClaude SubscriptionExtra API CostsTotal3 agents~$20/mo~$0-5~$20-25/mo5 agents~$20/mo~$5-10~$25-30/mo10 agents~$20/mo~$10-20~$30-40/mo
Heartbeats on Ollama = $0. Haiku agents barely register. Prompt caching reduces costs 50-90%.
Configure session resets to prevent context overflow:
json5
{
"session": {
"maxIdleMinutes": 45,
"dailyResetUtc": "04:00"
}
}
Agents should save important context before reset:
markdown
<!-- In agent's BOOTSTRAP.md -->
## Memory Flush
Before session compaction, save key decisions, dates, and action items
to memory/*.md files using the write tool.
Q: Do all agents need their own Telegram bot?
A: Only if you want to DM them directly. Agents can work purely via sessions_send (backend-only) without a Telegram bot.
Q: Can agents share a workspace? A: No. Each agent needs its own workspace to avoid file conflicts and memory collision.
Q: What happens when context fills up?
A: OpenClaw auto-compacts sessions. Enable memory flush so agents save important context to memory/*.md before compaction.
Q: Can I mix providers (Anthropic + Google + Ollama + xAI)? A: Yes. Each agent can have a different model and provider. Use fallback chains for resilience.
Q: How do I debug cross-agent routing?
A: Check agentToAgent.enabled: true in config. Test with a simple ping:
text
sessions_send(sessionKey="agent:techops:main", message="ping — reply pong")
Q: How do I add a new agent to an existing team?
A: Create workspace + agentDir, add to agents.list, create 4 .md files, add Telegram bot (optional), add to other agents' routing tables, restart gateway.
Q: Can agents call external APIs?
A: Yes, via exec (curl/scripts) or dedicated skills. Keep API keys in .env, not in agent files.
Q: What about rate limits? A: Fallback chains handle this automatically. If Claude rate-limits, the request falls back to the next provider. Prompt caching also reduces token consumption significantly.