A modular framework for building and deploying AI agents on Cloudflare Workers with intelligent routing and MCP (Model Context Protocol) support. Now supports both JavaScript and Python implementations!
This framework enables rapid development of specialized AI agents that can work together through a router-agent pattern. The router intelligently routes questions to the most appropriate specialist agent based on keywords and patterns.
| Language | Status | Production Ready | Package Support |
|---|---|---|---|
| JavaScript | ✅ Stable | ✅ Yes | ✅ Full npm ecosystem |
| Python | ✅ Beta |
- BaseAgent - Foundation class providing common functionality (CORS, caching, AI calls, MCP server)
- RouterAgent - Specialized router that uses ToolRegistry to route questions to specialist agents
- ToolRegistry - Dynamic tool discovery and routing system with scoring
- AgentBuilder - Generates complete agent packages from JSON configuration
- Router Agent: Routes questions to specialized agents, falls back to local AI
- Specialist Agent: Focused on specific domains (e.g., vulnerabilities, threat intelligence)
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
make install-dev
# See all available commands
make helpYou can generate agents using either the traditional generator or the new cookiecutter templates:
# Install cookiecutter if not already installed
pip install cookiecutter
# Generate a JavaScript router agent
cookiecutter https://github.com/Aktoh-Cyber/cc-js-router-agent
# Generate a JavaScript specialist agent (coming soon)
cookiecutter https://github.com/Aktoh-Cyber/cc-js-specialist-agent
# Generate a Python router agent (coming soon)
cookiecutter https://github.com/Aktoh-Cyber/cc-py-router-agentmake generate-js CONFIG=generators/javascript/configs/cybersec-router.json OUTPUT=agents/my-js-agentmake generate-py CONFIG=generators/python/configs/cybersec-router.json OUTPUT=agents/my-py-agent# Generate common agents
make gen-cybersec-router # Cybersec router agent
make gen-judge-specialist # Judge specialist agent
make gen-agent-generator # Agent generator agent# Deploy any agent
make deploy-agent AGENT=agents/my-agent
# Or manually
cd agents/my-agent
export CLOUDFLARE_API_TOKEN="your-token-here"
./scripts/deploy.shagent-framework/
├── README.md # This file
├── pyproject.toml # Python project configuration (uv)
├── Makefile # Development commands
├── generators/ # Language-specific generators
│ ├── javascript/ # JavaScript/Node.js generator
│ │ ├── agent-builder.js # JS agent builder
│ │ ├── base-agent.js # JS base agent class
│ │ ├── router-agent.js # JS router implementation
│ │ ├── tool-registry.js # JS routing logic
│ │ ├── config-schema.js # Configuration validation
│ │ ├── build-agent.js # CLI build tool
│ │ └── configs/ # Example JS configurations
│ └── python/ # Python generator
│ ├── agent_builder.py # Python agent builder
│ ├── agent_framework/ # Python framework modules
│ │ ├── __init__.py
│ │ ├── base_agent.py # Python base agent class
│ │ ├── router_agent.py # Python router implementation
│ │ ├── tool_registry.py # Python routing logic
│ │ ├── generator_agent.py # Agent generator
│ │ ├── enhanced_agent_generator.py # GitHub integration
│ │ └── github_client.py # GitHub API client
│ └── configs/ # Example Python configurations
├── generated-agents/ # Auto-generated agents (GitOps)
│ ├── router-agents/ # Router agents
│ └── specialist-agents/ # Specialist agents
├── agents/ # Manual agents and examples
│ ├── agent-generator-test/ # Agent Generator deployment
│ ├── cybersec-agent/ # Example cybersec agent
│ ├── judge/ # Example judge agent
│ └── threat-intel-test/ # Example threat intel agent
├── .github/workflows/ # CI/CD automation
│ ├── deploy-agents.yml # Deploy generated agents
│ └── cleanup-agents.yml # Remove deleted agents
└── infrastructure/ # Infrastructure as Code
└── pulumi/ # Pulumi configurations
✅ Advantages:
- Full npm package ecosystem in production
- Mature Cloudflare Workers support
- Rich web framework options (Express, Hono, etc.)
- Extensive third-party integrations
- Slightly larger bundle sizes
- Callback/Promise complexity for some use cases
✅ Advantages:
- Clean, readable syntax with type hints
- Standard library rich for many use cases
- Native async/await support
- Familiar to data science/ML teams
- FFI access to all JavaScript APIs
- Beta status on Cloudflare Workers
- Third-party packages work in dev only (not production)
- Must use standard library for production deployments
Both languages use the same JSON configuration format:
{
"type": "router",
"name": "AI Router",
"description": "Routes questions to specialized agents",
"systemPrompt": "You are an AI assistant that routes questions...",
"domain": "router.example.com",
"accountId": "your-account-id",
"zoneId": "your-zone-id",
"registry": {
"tools": [
{
"id": "specialist1",
"name": "Specialist Name",
"description": "What this specialist does",
"endpoint": "https://specialist.domain.com",
"mcpTool": "tool_name",
"keywords": ["keyword1", "keyword2"],
"patterns": ["regex1", "regex2"],
"priority": 10
}
]
}
}{
"type": "specialist",
"name": "Domain Expert",
"description": "Specialized in specific domain",
"systemPrompt": "You are a specialist in...",
"domain": "specialist.example.com",
"accountId": "your-account-id",
"zoneId": "your-zone-id",
"mcpToolName": "specialist_tool",
"expertise": "domain expertise",
"keywords": ["domain", "specific", "terms"],
"patterns": ["domain-specific regex"],
"priority": 5
}- Building production applications with complex dependencies
- Need extensive third-party integrations
- Working with existing JavaScript/Node.js ecosystems
- Require mature package ecosystem support
- Team prefers Python syntax and paradigms
- Building AI/ML-focused agents
- Prototyping and development work
- Standard library meets your needs
- Want type safety with modern Python features
Agents can register themselves dynamically:
# JavaScript
POST /admin/tools
{
"tool": {
"id": "new-specialist",
"name": "New Specialist",
"endpoint": "https://new.domain.com",
"keywords": ["specialized", "terms"]
}
}# Python (same API)
import json
from js import fetch
tool_data = {
"tool": {
"id": "new-specialist",
"name": "New Specialist",
"endpoint": "https://new.domain.com",
"keywords": ["specialized", "terms"]
}
}All agents automatically expose MCP endpoints:
POST /mcp- MCP protocol endpoint- Tools list:
{"method": "tools/list"} - Tool calls:
{"method": "tools/call", "params": {...}}
- ES modules with tree shaking
- Efficient V8 execution
- npm package bundling
- Pyodide snapshot at deploy time
- FFI for JavaScript API access
- Standard library optimization
- Per Agent: ~400 lines of duplicated code
- Total for 3 agents: ~1200 lines with significant duplication
- JavaScript agents: ~70 lines of configuration (95% reduction)
- Python agents: ~65 lines of configuration (96% reduction)
- Framework: ~2000 lines total (reusable across all agents)
✅ 95%+ code reduction per new agent
✅ Consistent behavior across all agents
✅ Zero duplication of common functionality
✅ Multi-language support for team preferences
✅ Template-based generation for rapid development
✅ Centralized updates through framework
We're migrating to cookiecutter templates for better maintainability and standardization. Each template is in its own GitHub repository for easy versioning and distribution.
| Template | Repository | Status | Description |
|---|---|---|---|
| JavaScript Router | cc-js-router-agent | ✅ Ready | Router agent with intelligent routing |
| JavaScript Specialist | cc-js-specialist-agent | 🚧 In Progress | Domain-specific specialist agent |
| Python Router | cc-py-router-agent | 🚧 In Progress | Python router agent |
# Install cookiecutter
pip install cookiecutter
# Generate from template
cookiecutter https://github.com/Aktoh-Cyber/cc-js-router-agent
# Follow the prompts to configure your agent
# - project_name: Your agent's name
# - domain: Your Cloudflare domain
# - cloudflare_account_id: Your account ID (optional)
# - ai_model: AI model to use
# - etc.- Standardized Structure: Consistent project layout across all agents
- Interactive Configuration: Prompted for all required settings
- Validation: Pre-generation hooks validate inputs
- Git Integration: Automatically initializes git repository
- CI/CD Ready: GitHub Actions workflow included
- Documentation: README template with implementation notes
See MIGRATION_PLAN.md for details on the cookiecutter migration strategy.
# One-time setup
make dev-setup
# Daily development
make qa # Run format, lint, type-check, test# Copy and modify example
cp generators/python/configs/judge-specialist.json generators/python/configs/my-specialist.json
# Edit configuration for your domain# Using make commands (recommended)
make generate-py CONFIG=generators/python/configs/my-specialist.json OUTPUT=agents/my-agent
# Or directly
cd generators/python
uv run python agent_builder.py configs/my-specialist.json ../../agents/my-agent# Using make (recommended)
make deploy-agent AGENT=agents/my-agent
# Or manually
cd agents/my-agent
export CLOUDFLARE_API_TOKEN="your-token"
./scripts/deploy.sh# Quality assurance
make format # Format code
make lint # Check linting
make type-check # Type checking
make test # Run tests
# Project maintenance
make clean # Clean build artifacts
make update # Update dependencies
make info # Show project infoJavaScript Import Errors
- Check ES module syntax
- Verify file paths are correct
- Ensure dependencies are installed
Python Import Errors
- Ensure
agent_frameworkdirectory is present - Check Python syntax compatibility
- Verify FFI imports are correct for Workers environment
Deployment Failures
- Confirm API token permissions
- Check account and zone IDs
- Verify domain DNS configuration
- For Python: ensure
python_workerscompatibility flag is set
Routing Not Working
- Check keyword case sensitivity
- Test regex patterns with actual questions
- Verify MCP endpoint accessibility
- Ensure tool registry is properly configured
- Hono framework integration
- Advanced middleware support
- WebAssembly module support
- Edge-side rendering optimizations
- Production package support (when available)
- FastAPI integration for production
- Advanced typing and validation
- NumPy/Scientific computing support
- Rust generator
- Go generator
- Visual agent builder UI
- Metrics and monitoring dashboard
- Auto-scaling based on load
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Choose your language implementation
- Add tests for new functionality
- Update documentation
- Submit pull request
JavaScript
- Use ES2022+ features
- Follow ESLint configuration
- Add JSDoc comments
- Write Jest tests
Python
- Use Python 3.9+ features
- Follow Black formatting
- Add type hints
- Write pytest tests
MIT License - see LICENSE file for details
cd generators/javascript
node build-agent.js configs/judge-specialist.json ../../judge-js
cd ../../judge-js
./scripts/deploy.shcd generators/python
python3 agent_builder.py configs/cybersec-router.json ../../cybersec-py
cd ../../cybersec-py
./scripts/deploy.sh# Deploy Python specialist
cd generators/python
python3 agent_builder.py configs/judge-specialist.json ../../judge-py
# Deploy JavaScript router that uses Python specialist
cd ../javascript
node build-agent.js configs/cybersec-router.json ../../cybersec-js
# Edit cybersec-js config to point to judge-py endpoint
# Deploy both
cd ../../judge-py && ./scripts/deploy.sh
cd ../cybersec-js && ./scripts/deploy.shThe beauty of this framework: Language choice is per-agent. You can have Python specialists and JavaScript routers, or any combination that fits your team's expertise and requirements!
Multi-Language Agent Framework v2.0
Powered by: Cloudflare Workers | Workers AI | JavaScript & Python 🚀