Files · LangChain Reliability Suite for SMB Support Agents with Auto-Runbooks
84 (1 binary, 650.2 kB total)attempt 1
README.md·3572 B·markdown
markdown
# LangChain Reliability Suite for SMB Support Agents with Auto-Runbooks
> Keep SMB AI support agents operational 24/7 with circuit breakers, idempotent workflows, automatic API key rotation, and self‑generating runbooks.
A reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build production-grade AI reliability layers with the `@reaatech/*` package family and LangChain.
## Architecture
This project layers five reliability patterns on top of a LangChain-powered LLM agent:
- **Circuit Breaker** (`@reaatech/circuit-breaker-agents`) — wraps the primary LLM provider call; on excessive failures, automatically falls back to a secondary provider (Anthropic). Health endpoint exposes circuit state.
- **Idempotency Middleware** (`@reaatech/idempotency-middleware`) — prevents duplicate LLM side effects by caching responses keyed to an `Idempotency-Key` header, backed by a DynamoDB storage adapter.
- **Session Continuity** (`@reaatech/session-continuity-storage-dynamodb`) — persists conversation state to DynamoDB so agent sessions survive restarts and handoffs.
- **Secret Rotation** (`@reaatech/secret-rotation-core`) — a Temporal workflow rotates OpenAI and Anthropic API keys daily without downtime.
- **Auto-Runbooks** (`@reaatech/agent-runbook`) — when a circuit breaker opens, the system analyzes failure logs and generates a structured runbook describing root cause, mitigation steps, and rollback procedures.
## API Routes
| Route | Method | Description |
|---|---|---|
| `/api/health` | GET | System health: active provider, circuit state, uptime, metrics |
| `/api/chat` | POST | Send a message; rate-limited and idempotency-guarded |
| `/api/rotate` | POST | Trigger manual API key rotation |
| `/api/runbooks` | GET | List generated runbooks |
| `/api/runbooks/[id]` | GET | Get a specific runbook |
| `/api/sessions` | POST | Create a new conversation session |
| `/api/sessions/[id]/messages` | GET/POST | Retrieve or append session messages |
## Running locally
```bash
pnpm install
pnpm test # vitest run with coverage
pnpm typecheck # TypeScript type checking
pnpm lint # ESLint
pnpm dev # next dev
```
## Environment
Copy `.env.example` to `.env` and fill in your API keys. Required:
- `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` — LLM providers (primary + fallback)
- `AWS_REGION` — DynamoDB region
- `DYNAMODB_SESSIONS_TABLE` / `DYNAMODB_IDEMPOTENCY_TABLE` — DynamoDB table names
- `UPSTASH_REDIS_URL` / `UPSTASH_REDIS_TOKEN` — rate limiting
- `TEMPORAL_HOST` — Temporal server for the rotation workflow
## Project layout
```
app/ Next.js App Router pages + API routes
src/
lib/ types, config, error classes
services/ ReliableChain, session-store, rotation-service, runbook-generator
middleware/ idempotency middleware, rate limiter
workflows/ Temporal workflow + activities
tests/ vitest suite (87 tests)
packages/ API references for every dependency
```
## Built with
- **Next.js 16** (App Router) — framework
- **LangChain** — LLM abstraction layer
- **5 REAA packages** — circuit-breaker-agents, idempotency-middleware, session-continuity-storage-dynamodb, agent-runbook, secret-rotation-core
- **Temporal.io** — durable workflow orchestration
- **Upstash** — Redis-backed rate limiting
- **AWS DynamoDB** — session + idempotency storage
- **Vitest** — test runner with 90%+ coverage
## License
MIT — see [LICENSE](./LICENSE).