Skip to content
reaatechREAATECH

Files · OpenRouter Agent Mesh for SMB Workflow Automation

50 (0 binary, 273.0 kB total)attempt 2

README.md·3900 B·markdown
markdown
# OpenRouter Agent Mesh for SMB Workflow Automation
 
Coordinate multiple specialist AI agents across teams using a single low-cost routing layer with built-in observability and spend controls.
 
## Problem
 
Small businesses struggle to adopt multi-agent AI because orchestrating different models and services reliably—without runaway costs or fragile handoffs—is beyond their in-house engineering capacity.
 
## Solution
 
This mesh aggregates OpenAI, Anthropic, and other OpenRouter models behind a unified routing fabric built on `@reaatech/agent-mesh` and its classifier/confidence components. Incoming tasks are classified, confidence-checked, and dispatched to the right specialist agent, with session memory and budget enforcement preventing duplicate work and surprise bills. `@reaatech/agent-mesh-observability` feeds metrics straight into Langfuse, while `@reaatech/agent-handoff-protocol` ensures standardised agent-to-agent communication. The mesh registry lets SMBs plug in new agents without redeploying the core.
 
## Core Features
 
- Multi-agent classification and routing (Gemini Flash via Vertex AI)
- Spending controls with auto-downgrade
- Langfuse observability
- Admin registry with hot-reload
- Session state persistence
- Agent handoff protocol
 
## Architecture
 
```
Express Server
    |
    v
POST /api/mesh
    |
    v
Session Middleware  -->  Firestore (sessions)
    |
    v
Classifier (Gemini Flash / Vertex AI)
    |
    v
Confidence Gate
    |
    v
Budget Check  -->  Budget Engine
    |
    v
Router Dispatch  -->  OpenRouter / MCP Agents
    |
    v
Session Update  -->  Firestore
    |
    v
Observability  -->  Langfuse
```
 
## Installation
 
```bash
git clone <repo>
cd openrouter-agent-mesh-for-smb-workflow-automation
pnpm install
cp .env.example .env
# Fill in your API keys
pnpm dev
```
 
## Environment Variables
 
| Variable | Required | Description |
|----------|----------|-------------|
| OPENROUTER_API_KEY | Yes | OpenRouter API key |
| GOOGLE_CLOUD_PROJECT | Yes | GCP project for Vertex AI |
| GOOGLE_CLOUD_LOCATION | Yes | Vertex AI region |
| GOOGLE_GENAI_USE_VERTEXAI | Yes | Route @google/genai to Vertex |
| GOOGLE_APPLICATION_CREDENTIALS | Local | Service account JSON path |
| LANGFUSE_PUBLIC_KEY | Yes | Langfuse public key |
| LANGFUSE_SECRET_KEY | Yes | Langfuse secret key |
| LANGFUSE_HOST | Yes | Langfuse host URL |
| AGENT_REGISTRY_PATH | Yes | Directory for agent YAML files |
| BUDGET_LIMIT_USD | No | Monthly budget per user (default: 100) |
| CONFIDENCE_THRESHOLD_DEFAULT | No | Global fallback threshold (default: 0.85) |
| PORT | No | Express port (default: 3000) |
 
## API Endpoints
 
### POST /api/mesh
 
Body: `{ "text": "...", "userId": "...", "sessionId?": "..." }`
 
Response: `{ "content": "...", "workflow_complete": true, "sessionId": "...", "agentId": "...", "budgetRemaining": 99.5 }`
 
### GET /health
 
Response: `{ "status": "ok", "uptime": 123, "registryLoaded": true, "agentCount": 3 }`
 
### Admin Registry
 
- `GET /admin/registry` - list agents
- `POST /admin/registry` - add agent (YAML body)
- `PUT /admin/registry/:id` - update agent
- `DELETE /admin/registry/:id` - remove agent
 
## Example
 
```bash
curl -X POST http://localhost:3000/api/mesh \
  -H 'Content-Type: application/json' \
  -d '{"text":"Reset my password","userId":"user-1"}'
```
 
## Adding Agents
 
Create a YAML file in `AGENT_REGISTRY_PATH`:
 
```yaml
agent_id: "my-agent"
display_name: "My Agent"
description: "Handles specific domain tasks"
endpoint: "http://localhost:8081"
type: mcp
is_default: false
confidence_threshold: 0.7
clarification_required: false
examples:
  - "Example query 1"
```
 
Or use `POST /admin/registry` with the YAML content.
 
## Testing
 
```bash
pnpm test
```
 
## External Docs
 
- [OpenRouter](https://openrouter.ai/)
- [Langfuse](https://langfuse.com/)
- [REAA Agent Mesh](https://www.npmjs.com/package/@reaatech/agent-mesh)