
new-agent
by baglett
SKILL.md
name: new-agent description: Create a new backend agent for the Claude Assistant Platform. Use when adding a new specialized agent, scaffolding an agent, or when the user says "create agent", "add agent", "new agent", or "scaffold agent". allowed-tools: Read, Write, Edit, Glob, Grep, Bash
Create New Agent
This skill scaffolds a new specialized agent following the established patterns.
Prerequisites
Before creating an agent, gather:
- Agent name (snake_case, e.g.,
slack_agent) - Agent purpose (what domain it handles)
- MCP server URL (if connecting to external service)
Complete Steps
Step 1: Create Agent File
Create Backend/src/agents/{name}_agent.py using the template in TEMPLATE.md.
Key points:
- Use
input_dataandoutput_dataparameters forlog_tool_call()(NOTtool_input/tool_output) - Follow the pattern from existing agents like
gmail_agent.pyorgoogle_drive_agent.py
Step 2: Register in __init__.py
Add to Backend/src/agents/__init__.py:
from src.agents.{name}_agent import {Name}Agent
__all__ = [
# ... existing exports ...
"{Name}Agent",
]
Step 3: Register in main.py
Add to Backend/src/api/main.py:
- Add import at top:
from src.agents.{name}_agent import {Name}Agent
- Add registration in
lifespan()function (after other agent registrations):
# Register {Name} Agent if configured
if settings.{name}_is_configured:
{name}_agent = {Name}Agent(
api_key=settings.anthropic_api_key,
model=settings.claude_model,
mcp_url=settings.{name}_mcp_url,
)
orchestrator.register_agent({name}_agent)
logger.info(
f"Registered {Name}Agent with orchestrator "
f"(MCP: {settings.{name}_mcp_url})"
)
else:
logger.info(
"{Name} integration disabled - {Name}Agent not registered"
)
Step 4: Add Settings Configuration
Add to Backend/src/config/settings.py:
# {Name} MCP Configuration
{name}_mcp_host: str = Field(
default="{name}-mcp",
description="Hostname of the {Name} MCP server.",
)
{name}_mcp_port: int = Field(
default=808X,
description="Port of the {Name} MCP server.",
)
{name}_enabled: bool = Field(
default=False,
description="Whether {Name} integration is enabled.",
)
@property
def {name}_is_configured(self) -> bool:
"""Check if {Name} integration is configured."""
return self.{name}_enabled
@property
def {name}_mcp_url(self) -> str:
"""Get the full {Name} MCP URL."""
return f"http://{self.{name}_mcp_host}:{self.{name}_mcp_port}"
Step 5: Update Orchestrator System Prompt
Edit Backend/src/agents/orchestrator.py:
Add to the routing guidelines section:
X. **{Name} Operations** → Delegate to `{name}` agent (when available)
- {Capability 1}
- {Capability 2}
- {Capability 3}
Step 6: Add Environment Variables
Add to .env.example:
# {Name} Integration
{NAME}_ENABLED=true
{NAME}_MCP_HOST=localhost
{NAME}_MCP_PORT=808X
Add to your .env:
{NAME}_ENABLED=true
{NAME}_MCP_HOST=localhost
{NAME}_MCP_PORT=808X
Step 7: Add to Routing Database (CRITICAL!)
Insert agent into routing.agents table:
INSERT INTO routing.agents (name, display_name, description, keywords, regex_patterns, enabled, priority)
VALUES (
'{name}',
'{Name} Agent',
'{Description of what the agent does. Be specific about when to use it.}',
ARRAY['keyword1', 'keyword2', 'keyword3', ...],
ARRAY[
'\b(pattern1|pattern2)\b',
'\b(action).*(noun)\b'
],
true,
{priority} -- Lower = higher priority (github=10, todo=20, email=30, etc.)
);
Step 8: Add to AGENT_PATTERNS (Tier 1 Routing)
CRITICAL: Add regex patterns to Backend/src/services/router_service.py for fast Tier 1 routing:
AGENT_PATTERNS: dict[str, list[str]] = {
# ... existing agents ...
"{name}": [
r"\b({keyword1}|{keyword2})\b",
r"\b({action}).{0,20}({noun})\b",
# Add patterns that uniquely identify requests for this agent
],
}
Pattern Guidelines:
- Use word boundaries
\bto avoid partial matches - Use
.{0,20}for flexible word gaps (not.*which is greedy) - Test patterns with the message text before adding
- Multiple matches increase confidence
Step 9: Generate Embeddings
After adding to database, restart backend OR call:
curl -X POST http://localhost:8000/api/router/generate-embeddings
This generates vector embeddings for the hybrid router to route requests correctly.
Verification Checklist
After creation, verify:
- Agent file created at
Backend/src/agents/{name}_agent.py - Agent extends
BaseAgent -
name,description, andtoolsproperties defined - System prompt describes all available tools
- Tool definitions use JSON schema format
- Tool handlers use
input_data/output_dataparams (NOTtool_input/tool_output) - MCP URL passed via constructor
- Agent exported in
__init__.py - Agent registered in
main.pylifespan - Settings added to
settings.py - Orchestrator system prompt updated
- Environment variables added to
.env.exampleand.env - Agent inserted into
routing.agentstable - AGENT_PATTERNS updated in
router_service.py(Tier 1 routing) - Embeddings generated (check "X agents, X embeddings" in logs)
- Backend restarted and healthy
- Test routing works (use NEW message text to avoid cache)
File Locations
| File | Purpose |
|---|---|
Backend/src/agents/{name}_agent.py | Agent implementation |
Backend/src/agents/__init__.py | Agent export |
Backend/src/api/main.py | Agent registration |
Backend/src/config/settings.py | Settings configuration |
Backend/src/agents/orchestrator.py | Routing guidelines |
Backend/src/services/router_service.py | AGENT_PATTERNS for Tier 1 routing |
.env.example | Environment variable template |
.env | Environment variables |
routing.agents table | Hybrid router configuration |
Troubleshooting
"No specialized agents registered"
- The chat route was creating a new orchestrator. Fixed by using
request.app.state.orchestrator - Check that agents are registered during startup in logs
Router not routing to new agent
- Agent missing from
routing.agentsdatabase table - Embeddings not generated - call
/api/router/generate-embeddings - Check logs for "X agents, X embeddings" - numbers should match
- AGENT_PATTERNS missing - Add patterns to
router_service.pyfor Tier 1 matching
Routing to wrong agent (cached routing)
- Routing decisions are cached in Redis for 5 minutes
- During testing, use different message text to avoid cache hits
- Or refresh the router cache:
curl -X POST http://localhost:8000/api/router/refresh - Check logs for "Direct routing to 'X' (tier=Y)" to see routing decisions
"log_tool_call() got unexpected keyword argument"
- Use
input_dataandoutput_data, NOTtool_inputandtool_output
Agent not listed in orchestrator
- Check
main.pyregistration is inside the correctifblock - Verify environment variable
{NAME}_ENABLED=trueis set
Reference
- TEMPLATE.md - Full agent code template
.claude/rules/backend/agents.md- Agent patterns and anti-patternsBackend/src/agents/google_drive_agent.py- Real-world exampleBackend/src/agents/gmail_agent.py- Another example
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です