Files · Anthropic Multi-Agent Handoff for Clio SMB Legal Case Management
83 (1 binary, 831.7 kB total)attempt 2
README.md·3524 B·markdown
markdown
# Anthropic Multi-Agent Handoff for Clio SMB Legal Case Management
> A multi‑agent system that triages client messages, drafts initial legal responses, and updates Clio case records with automation.
A tutorialized reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build production-grade AI systems with the `@reaatech/*` package family. This recipe uses `@reaatech/agent-mesh` for orchestration, `@reaatech/agent-handoff` for agent-to-agent handoffs, `@reaatech/agent-handoff-routing` for capability-based routing, and `@reaatech/agent-budget-engine` for LLM spend tracking.
## Architecture
```
Incoming message → Webhook (/api/webhooks/incoming-message)
→ Triage Agent (classifies intent via Claude Haiku)
→ Drafting Agent (drafts reply via Claude Sonnet, stores in Clio)
→ Case Agent (summarizes conversation, updates Clio matter status)
→ Budget Engine tracks all LLM spend
→ Background Worker monitors handoff events via LangGraph
```
Three agents are registered in the `@reaatech/agent-handoff-routing` AgentRegistry:
- **triage-agent**: Classifies intent (billing, consultation, document_review, case_update, general)
- **drafting-agent**: Generates legal reply drafts using Claude and creates Clio documents
- **case-agent**: Summarizes conversations and updates Clio case records
## Prerequisites
- Node.js >= 22
- pnpm >= 10
- An [Anthropic API key](https://platform.claude.com/settings/keys)
- A [Clio](https://app.clio.com) account with OAuth2 credentials
- A [Langfuse](https://langfuse.com) account (optional, for observability)
## Setup
```bash
pnpm install
cp .env.example .env
# Fill in your API keys and OAuth credentials
pnpm test # vitest run with coverage
pnpm dev # next dev
```
## API Endpoints
| Method | Path | Description |
|--------|------|-------------|
| POST | `/api/webhooks/incoming-message` | Receive a client message; triggers triage → handoff → response pipeline |
| GET | `/api/webhooks/incoming-message` | Health check returning service status |
| POST | `/api/agents/triage` | Classify a message and route to the appropriate agent |
| POST | `/api/agents/draft` | Draft a legal response and create a Clio document |
| POST | `/api/agents/case` | Summarize conversation and update Clio case status |
### Usage Example
```bash
curl -X POST http://localhost:3000/api/webhooks/incoming-message \
-H "Content-Type: application/json" \
-d '{
"session_id": "session-123",
"raw_input": "I need help with my bill from last month",
"employee_id": "emp-001"
}'
```
## Environment Variables
See `.env.example` for all required variables. Key ones:
- `ANTHROPIC_API_KEY` — Claude API key
- `CLIO_CLIENT_ID` / `CLIO_CLIENT_SECRET` / `CLIO_REFRESH_TOKEN` — Clio OAuth2
- `LANGFUSE_SECRET_KEY` / `LANGFUSE_PUBLIC_KEY` — Langfuse observability
## Project layout
```
app/ Next.js App Router pages + API routes
src/
agents/ Agent implementations (triage, drafting, case)
lib/ Shared utilities (Anthropic client, handoff router, agent registry, instrumentation)
services/ Business logic (Clio API, budget engine, handoff orchestration, background worker)
types/ TypeScript types and Zod schemas
tests/ vitest suite (mirrors src/)
packages/ API references for every dependency
DEV_PLAN.md build plan for this recipe
```
## License
MIT — see [LICENSE](./LICENSE).