Skip to content
reaatech

Files · Cohere Reliability Suite for Xero SMB Accounting Ops

72 (1 binary, 1042.4 kB total)attempt 1

README.md·3099 B·markdown
markdown
# Cohere Reliability Suite for Xero SMB Accounting Ops
 
> Runbook automation, circuit-breaking, and session continuity for AI agents accessing Xero financial data — keeping accounting workflows resilient when APIs fail or models falter.
 
## What It Does
 
This reference solution demonstrates how to build a production-grade reliability layer for AI agents that access Xero financial data:
 
- **Session Continuity** — preserves multi-turn agent context across Xero API calls using `@reaatech/session-continuity`, so a retry after failure picks up exactly where it left off.
- **Circuit Breaking** — opens the circuit on Xero errors (429 rate-limits, connection drops) using `@reaatech/circuit-breaker-agents`, preventing cascading failures.
- **Automated Runbooks** — periodically generates operational playbooks for Xero-connected agents using `@reaatech/agent-runbook-agent`, triggered via `@trigger.dev/sdk`.
 
## Architecture
 
```
app/api/health/route.ts        GET  — circuit breaker + Xero connection status
app/api/runbook/route.ts       POST — trigger runbook generation
 
src/agent/middleware.ts         session → circuit → xero → llm pipeline
src/workflows/runbook-gen.ts    trigger.dev + AnalysisAgent runbook generation
src/xero/client.ts              Xero API wrapper with p-retry
src/lib/errors.ts               custom error classes
src/lib/llm.ts                  Cohere LLM client wrapper
src/lib/session.ts              @reaatech/session-continuity wrapper
src/lib/circuit-breaker.ts      @reaatech/circuit-breaker-agents wrapper
src/lib/singleton.ts            service container with lazy singletons
src/instrumentation.ts          Langfuse telemetry bootstrap
```
 
## Environment Variables
 
| Variable | Description |
|---|---|
| `COHERE_API_KEY` | Cohere API key (for LLM calls) |
| `XERO_CLIENT_ID` | Xero OAuth2 client ID |
| `XERO_CLIENT_SECRET` | Xero OAuth2 client secret |
| `XERO_SCOPES` | Comma-separated Xero API scopes |
| `TRIGGER_API_KEY` | Trigger.dev API key |
| `ANTHROPIC_API_KEY` | Anthropic API key (for runbook agent) |
| `LANGFUSE_PUBLIC_KEY` | Langfuse public key (telemetry) |
| `LANGFUSE_SECRET_KEY` | Langfuse secret key (telemetry) |
| `LANGFUSE_HOST` | Langfuse host URL |
 
## Getting Started
 
```bash
pnpm install
pnpm dev             # start Next.js dev server
pnpm test            # vitest run with coverage
pnpm typecheck       # TypeScript type check
pnpm lint            # ESLint
```
 
## API Endpoints
 
### GET /api/health
Returns circuit breaker state and Xero connection status.
 
### POST /api/runbook
Triggers runbook generation. Accepts `{ orgId: string; scope?: string[] }`.
 
## REAA Packages
 
| Package | Role |
|---|---|
| `@reaatech/session-continuity` | Session lifecycle management with token budget and compression |
| `@reaatech/circuit-breaker-agents` | Circuit breaker pattern with persistence adapters |
| `@reaatech/agent-runbook` | Domain types and schemas for runbook generation |
| `@reaatech/agent-runbook-agent` | AI agent factory for automated runbook analysis |
 
## License
 
MIT — see [LICENSE](./LICENSE).