Files · Anthropic Lead Intake for Clio Small Law Firm Client Qualification
69 (1 binary, 629.7 kB total)attempt 1
README.md·4232 B·markdown
markdown
# Anthropic Lead Intake for Clio Small Law Firm Client Qualification
> Qualify potential clients, capture case details, and create matters in Clio via conversational intake, saving attorneys hours of screening time.
Small law firms miss leads after hours, spend time manually qualifying inquiries, and struggle to convert website visitors into booked consultations. This recipe demonstrates an AI-powered conversational lead intake agent that solves this problem.
## How it works
1. A webhook receives chat messages from potential clients.
2. The **confidence-router** triages each message into high-confidence legal intent (ROUTE), ambiguous intent requiring clarifying questions (CLARIFY), or low-confidence intent (FALLBACK).
3. High-confidence leads go through **structured extraction** via Claude Sonnet, with `@reaatech/structured-repair-core` cleaning malformed LLM outputs.
4. Extracted client data passes to **agent-handoff** to select the appropriate practice-area agent (family law, personal injury, criminal defense, etc.).
5. The **Clio REST API** creates contacts and matters under OAuth2 authentication.
6. An **idempotency middleware** prevents duplicate matter creation on retry.
7. All LLM calls are tracked via `@reaatech/llm-cost-telemetry` with daily budget enforcement.
8. **Langfuse** observability spans are exported for every conversation turn.
## Getting started
```bash
pnpm install
pnpm typecheck
pnpm test
```
Then copy `.env.example` to `.env`, fill in the required values, and start the server:
```bash
pnpm dev
```
Or run the Express webhook server directly:
```bash
node --import tsx src/server.ts
```
## Environment variables
| Variable | Required | Description |
|----------|----------|-------------|
| `ANTHROPIC_API_KEY` | Yes | Anthropic Claude API key |
| `CLIO_CLIENT_ID` | Yes | Clio OAuth2 client ID |
| `CLIO_CLIENT_SECRET` | Yes | Clio OAuth2 client secret |
| `CLIO_ACCOUNT_ID` | Yes | Clio account ID |
| `AWS_REGION` | No (default: us-east-1) | AWS region for DynamoDB |
| `DYNAMODB_TABLE_NAME` | No (default: sessions) | DynamoDB table for session storage |
| `LANGFUSE_SECRET_KEY` | No | Langfuse observability secret key |
| `LANGFUSE_PUBLIC_KEY` | No | Langfuse observability public key |
| `LANGFUSE_HOST` | No (default: https://cloud.langfuse.com) | Langfuse host URL |
| `PORT` | No (default: 3001) | Express server port |
| `DEFAULT_DAILY_BUDGET` | No (default: 5.00) | Daily LLM spend budget in USD |
## Project structure
```
src/
lib/
types.ts Shared type definitions
config.ts Environment configuration with Zod validation
clio-client.ts Clio REST API client (OAuth2, contacts, matters)
llm-service.ts Anthropic Claude service (classify, extract, clarify)
lead-classifier.ts Confidence-router wrapper for intent classification
agent-router.ts Capability-based practice area routing
session-manager.ts Session continuity with DynamoDB storage
output-repair.ts Structured LLM output repair
telemetry.ts Langfuse observability + cost tracking
idempotency.ts Idempotency middleware for duplicate prevention
webhook/
clio-intake.ts Express webhook handler (main entry point)
server.ts Express server entry
index.ts Barrel exports
tests/
lib/ Unit tests for all service modules
webhook/ Webhook handler tests
integration/ End-to-end flow tests
```
## REAA packages
| Package | Role |
|---------|------|
| `@reaatech/confidence-router` | Intent classification threshold engine |
| `@reaatech/confidence-router-core` | Core types and DecisionEngine |
| `@reaatech/agent-handoff` | Handoff protocol types and utilities |
| `@reaatech/agent-handoff-routing` | Capability-based practice area routing |
| `@reaatech/structured-repair-core` | Zod-driven LLM output repair pipeline |
| `@reaatech/session-continuity` | Multi-turn conversation session manager |
| `@reaatech/session-continuity-storage-dynamodb` | DynamoDB storage adapter |
| `@reaatech/llm-cost-telemetry` | Cost tracking and budget enforcement |
## License
MIT — see [LICENSE](./LICENSE).