Content
# AgentFlow
**A visual multi-agent workflow builder powered by Claude.**
AgentFlow lets you design, execute, and observe AI agent pipelines on an interactive canvas — without writing infrastructure code. Connect agents, define conditions, attach tools, and watch them collaborate in real time.
[](LICENSE)
[](https://python.org)
[](https://nodejs.org)
[](https://fastapi.tiangolo.com)
[](https://react.dev)
---
## What it does
| Feature | Description |
|---|---|
| **Visual canvas** | Drag-and-drop agents, draw connections, set conditions |
| **Real LLM execution** | Each node calls Claude or GPT-4 with shared state context |
| **Planner mode** | A Planner agent dynamically decides which workers to call and in what order |
| **MCP tools** | Agents use api_fetch, sql_query, file_tool and more via Model Context Protocol |
| **Conditional routing** | Edges evaluate JS expressions against live state — retry loops, branching, skip |
| **Observability** | Step-by-step logs, execution replay, live state viewer, metrics dashboard |
| **Test runner** | Inject test inputs, define assertions, see expected vs actual |
| **Self-optimizing** | LLM analyses each agent's performance and suggests prompt and model improvements |
| **Marketplace** | 6 prebuilt templates and import/export JSON workflows |
---
## Quick Start — One command
```bash
git clone https://github.com/YOUR_USERNAME/agentflow.git
cd agentflow
./deploy.sh
```
The script asks whether you want Docker or manual mode, prompts for your Anthropic API key, and sets everything up automatically.
**With Docker (recommended):**
```bash
./deploy.sh docker # installs deps, builds, starts everything
./deploy.sh stop # stop all services
./deploy.sh logs # view live logs
./deploy.sh reset # wipe data and start fresh
```
**Without Docker (manual):**
```bash
./deploy.sh manual # installs PostgreSQL + Redis if needed, starts both servers
./deploy.sh stop # stop all services
```
**Open in browser:**
- App: http://localhost:3000 (Docker) or http://localhost:5173 (manual)
- API docs: http://localhost:8000/api/docs
> **Note:** You need an [Anthropic API key](https://console.anthropic.com) — the script will ask for it.
---
## Manual Setup (without the script)
<details>
<summary>Click to expand manual setup instructions</summary>
### Prerequisites
- Python 3.11 or 3.12 (not 3.13)
- Node.js 18 LTS or 20 LTS
- PostgreSQL 14+, Redis 6+
### Backend
```bash
cd backend
python3.12 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # fill in your API keys
alembic upgrade head
uvicorn app.main:app --reload --port 8000
```
### Frontend
```bash
cd frontend
npm install
cp .env.example .env # set VITE_API_BASE_URL=http://localhost:8000
npm run dev
```
</details>
---
## Environment Variables
### Backend (`backend/.env`)
| Variable | Required | Description |
|---|---|---|
| `DATABASE_URL` | Yes | `postgresql+asyncpg://user:pass@localhost/flowforge` |
| `DATABASE_SYNC_URL` | Yes | `postgresql+psycopg2://user:pass@localhost/flowforge` |
| `REDIS_URL` | Yes | `redis://localhost:6379/0` |
| `ANTHROPIC_API_KEY` | Yes | Anthropic API key |
| `OPENAI_API_KEY` | No | OpenAI key (optional fallback) |
| `JWT_SECRET_KEY` | Yes | 64-char random hex — see below |
| `LLM_DEFAULT_MODEL` | No | Default: `claude-sonnet-4-5` |
| `FRONTEND_URL` | No | For CORS in production |
Generate a secure JWT key:
```bash
python -c "import secrets; print(secrets.token_hex(64))"
```
### Frontend (`frontend/.env`)
| Variable | Description |
|---|---|
| `VITE_API_BASE_URL` | Backend URL (default: `http://localhost:8000`) |
| `VITE_ANTHROPIC_API_KEY` | Optional — for direct browser LLM calls during development |
---
## Architecture
```
Browser (React + TypeScript + React Flow)
Canvas ──► useAgentFlow hook ──► executionEngine.ts ──► LLM calls
plannerEngine.ts ──► LLM calls
│
│ HTTP REST
▼
FastAPI Backend (Python 3.12)
/api/workflows ──► PostgreSQL (SQLAlchemy + asyncpg)
/api/execute ──► flow_engine.py (Kahn parallel algorithm)
/api/mcp ──► MCP client pool (stdio subprocess)
/api/llm ──► LLM router (Anthropic + OpenAI)
/api/auth ──► JWT + bcrypt + RBAC
/api/optimizer ──► Agent performance + LLM analysis
/api/triggers ──► Webhook + API triggers
MCP Server subprocess
api_call, api_fetch, db_query, sql_query, file_tool, db_list_tables
PostgreSQL Redis
workflows runtime state
execution_runs session cache
```
---
## Agent Roles
| Role | Purpose |
|---|---|
| **Orchestrator** | Coordinates a static graph of agents |
| **Planner** | Dynamically generates an execution plan at runtime |
| **Worker** | Executes a specific task assigned by the Planner |
| **Evaluator** | Validates outputs, scores quality, triggers revisions |
| **Researcher** | Gathers and synthesises information |
| **Coder** | Writes, reviews, or analyses code |
| **Reviewer** | Validates and approves outputs |
| **Custom** | User-defined role |
---
## How Execution Works
### Static graph mode
Agents execute in topological order. Parallel tiers run concurrently. Loopback edges fire until condition fails or max iterations is reached.
### Planner mode (dynamic)
1. **Planner** runs first — reads the goal, produces a JSON execution plan
2. **Workers** execute in dependency order (parallel where deps allow)
3. **Evaluator** scores output 0-100 — if score < 75 and iterations remain, sends feedback and workers re-run
### State protocol
Every agent reads from and writes to a shared `FlowState` dictionary. Agents write results using this format at the end of their response:
```
## STATE_UPDATES
score: 85
reviewer:approved: true
research:findings: Found 3 relevant papers on...
```
The engine parses these blocks and merges them into shared state before routing to the next node.
---
## MCP Tools
Built-in MCP server with 6 tools:
| Tool | Category | Description |
|---|---|---|
| `api_call` | HTTP | POST/PUT/PATCH with JSON body |
| `api_fetch` | HTTP | GET request, returns parsed JSON |
| `db_query` | Database | Read-only SELECT via SQLite |
| `sql_query` | Database | Full SQL on configured database |
| `db_list_tables` | Database | List available tables |
| `file_tool` | File | read / write / list / exists operations |
### Adding an external MCP server
No code changes needed:
```bash
curl -X POST http://localhost:8000/api/mcp/servers/ \
-H "Content-Type: application/json" \
-d '{
"name": "filesystem",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
}'
```
Or use the Tool Registry UI and click **+ Add server**.
---
## Prebuilt Templates
| Template | Agents | Description |
|---|---|---|
| PDF Summarizer | 5 | Extract, chunk, summarise, review |
| Reasoning Loop | 5 | Propose, challenge, synthesise, validate with retry |
| API Data Analyzer | 6 | Plan, fetch, validate, analyse, report, review |
| Supplier Risk Analysis | 6 | Financial, operational, compliance research, score, recommend |
| Code Review Pipeline | 5 | Security, style, test coverage, PR summary |
| Research Report Writer | 6 | 3 parallel researchers, compose, editorial review |
Load any template: click **✦ AI Generate** then the **Templates** tab.
---
## API Reference
Full interactive docs at **http://localhost:8000/api/docs**
Key endpoints:
```
POST /api/generate-workflow Generate workflow from natural language
POST /api/execute/ Execute a canvas workflow
POST /api/execute/workflow/{id} Execute a saved workflow headlessly
GET /api/workflows/ List saved workflows
POST /api/workflows/ Save a workflow
GET /api/mcp/registry List all available tools
POST /api/mcp/servers/ Register a new MCP server
GET /api/mcp/servers/{name}/tools List tools from a server
POST /api/auth/register Register a new user
POST /api/auth/login Login and get JWT token
GET /api/auth/me Current user info
POST /api/triggers/ Create webhook/API/cron trigger
POST /api/triggers/webhook/{id} Public webhook endpoint
POST /api/test-suites/ Create a multi-test-case suite
POST /api/test-suites/{id}/run Run all test cases
POST /api/hallucination/check Heuristic hallucination detection
GET /api/optimizer/metrics All agent performance metrics
POST /api/optimizer/analyse/{id} LLM analysis and suggestions
```
---
## Known Limitations
Planned for v1.1:
1. **Auth not enforced on all routes** — JWT auth exists but most routes are still open. For production, add `Depends(get_current_user)` to each router endpoint.
2. **In-memory storage** — users, triggers, and test suites are stored in Python dicts and lost on restart. A database migration for these tables is planned.
3. **Frontend API key exposure** — `VITE_ANTHROPIC_API_KEY` is bundled into the browser JavaScript. For production, route all LLM calls through the backend and remove this variable.
4. **No automated tests** — pytest and Vitest setup is on the roadmap.
---
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions, code style, and PR guidelines.
---
## Changelog
See [CHANGELOG.md](CHANGELOG.md) for the full release history and roadmap.
---
## License
[MIT](LICENSE) — Copyright 2025 Manoj Velayudhannair
Connection Info
You Might Also Like
No recommendations available