Files · Databricks Agent Mesh for Small Business Workflow Automation
79 (1 binary, 781.7 kB total)attempt 2
README.md·5646 B·markdown
markdown
# Databricks Agent Mesh for Small Business Workflow Automation
> A multi-agent routing mesh powered by Databricks models that coordinates specialized agents for order processing, customer service, and analytics for small businesses.
A tutorialized reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build production-grade AI systems with the `@reaatech/*` package family.
## What It Builds
A multi-agent orchestrator for small business workflows. The system routes incoming user requests to the most appropriate specialist agent based on intent classification:
- **Order Agent** — handles order status inquiries, creation, cancellation, and returns
- **Support Agent** — manages ticket creation, FAQ resolution, and escalation
- **Analytics Agent** — provides sales summaries, customer trends, and business metrics
## Architecture
```
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Next.js 16 │────▶│ API Route │────▶│ Agent Mesh │
│ App Router │ │ /api/mesh │ │ (REAA Router) │
└─────────────┘ └──────────────┘ └────────┬────────┘
│
┌─────────────────────────────┼─────────────────────────┐
│ │ │
┌─────▼──────┐ ┌───────▼──────┐ ┌────────▼─────┐
│ Order Agent │ │ Support Agent│ │AnalyticsAgent│
│ (Mastra) │ │ (Mastra) │ │ (Mastra) │
└─────────────┘ └──────────────┘ └──────────────┘
│ │ │
┌─────▼──────┐ ┌───────▼──────┐ ┌────────▼─────┐
│ Drizzle │ │ Drizzle │ │ Drizzle │
│ + Postgres │ │ + Postgres │ │ + Postgres │
└─────────────┘ └──────────────┘ └──────────────┘
```
The mesh uses REAA packages for routing, session management, gateway handling, and observability, backed by Databricks models via Mastra.
## Prerequisites
- Node.js 22+
- pnpm 10+
- A Databricks workspace with model serving endpoints
- PostgreSQL database
## Setup
```bash
pnpm install
```
Copy `.env.example` to `.env` and fill in your credentials:
```bash
cp .env.example .env
```
### Environment Variables
| Variable | Description |
|----------|-------------|
| `DATABRICKS_HOST` | Databricks workspace URL |
| `DATABRICKS_TOKEN` | Databricks personal access token |
| `DATABASE_URL` | PostgreSQL connection string |
| `API_KEY` | API key for mesh endpoint authentication |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | OpenTelemetry collector endpoint |
| `LANGFUSE_PUBLIC_KEY` | Langfuse public key for observability |
| `LANGFUSE_SECRET_KEY` | Langfuse secret key |
| `LANGFUSE_HOST` | Langfuse host URL |
| `SESSION_TTL_MINUTES` | Session time-to-live (default: 30) |
| `SESSION_MAX_TURNS` | Max turns per session (default: 100) |
| `MCP_REQUEST_TIMEOUT_MS` | Agent dispatch timeout (default: 30000) |
| `MCP_MAX_RETRIES` | Max retries for failed dispatches (default: 3) |
| `ENABLE_CIRCUIT_BREAKER` | Enable circuit breaker pattern |
| `RATE_LIMIT_WINDOW_MS` | Rate limit window in ms (default: 900000) |
| `RATE_LIMIT_MAX_REQUESTS` | Max requests per window (default: 100) |
| `NODE_ENV` | Environment (development/production) |
## Running
```bash
pnpm dev # start Next.js dev server
pnpm test # run tests with coverage
pnpm typecheck # TypeScript type checking
pnpm lint # ESLint validation
```
## API Reference
### `POST /api/mesh`
Routes a user request to the appropriate agent.
**Request Body:**
```json
{
"user_id": "usr_abc123",
"input": "Where is my order?"
}
```
**Response:**
```json
{
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"session_id": "660e8400-e29b-41d4-a716-446655440001",
"agent_id": "order-agent",
"response": "I found your order #123. It was shipped on March 15 and is currently in transit.",
"workflow_complete": false,
"duration_ms": 1423
}
```
## Project Layout
```
app/ Next.js App Router pages + API routes
api/mesh/route.ts POST /api/mesh — main routing endpoint
layout.tsx Root layout with font setup
page.tsx Dashboard page
src/ Application source code
lib/ Database schema and Drizzle client
mesh/ Agent registry and Zod schemas
services/ Agent implementations and session management
tests/ Vitest test suite (mirrors src/)
packages/ API references for every dependency
```
## License
MIT — see [LICENSE](./LICENSE).