Skip to content
reaatechREAATECH

Files · Cohere Agent Mesh for Multi-Channel Customer Support Triage

68 (1 binary, 706.9 kB total)attempt 1

README.md·4627 B·markdown
markdown
# Cohere Agent Mesh for Multi-Channel Customer Support Triage
 
This recipe demonstrates a production-grade customer support triage pipeline that ingests tickets from email, chat, and social media, classifies intent via Cohere, gates routing by confidence, dispatches to specialist agents via MCP, and tracks per-channel costs.
 
**Pipeline:** Ticket ingestion → Cohere intent classification → Confidence-gated routing (via `@reaatech/agent-mesh-confidence` with fallback via `@reaatech/confidence-router-core`) → Specialist agent dispatch (via `@reaatech/agent-mesh-router` MCP) → Per-channel cost tracking (via `@reaatech/llm-cost-telemetry`).
 
## REAA Packages (5)
 
| Package | Role |
|---|---|
| `@reaatech/agent-mesh-confidence` | Classifies confidence level of Cohere intent predictions and gates routing decisions |
| `@reaatech/confidence-router-core` | Provides deterministic fallback routing when confidence is below threshold |
| `@reaatech/agent-mesh-router` | MCP-based dispatcher that routes tickets to the correct specialist agent endpoint |
| `@reaatech/llm-cost-telemetry` | Tracks per-channel LLM token usage and computes cost per interaction |
| `@reaatech/agent-mesh` | Core domain types, Zod validation schemas, and environment configuration for the agent-mesh ecosystem |
 
## Third-Party Packages
 
- **cohere-ai** — Cohere API client for intent classification
- **express** — HTTP server for the triage API endpoint
- **mastra** — Agent orchestration framework for managing specialist agents
- **uuid** — Generates unique ticket and interaction IDs
- **zod** — Request body validation and schema definition
- **dotenv** — Loads environment variables from `.env`
 
## API Endpoint
 
### `POST /api/v1/tickets`
 
Ingest a support ticket for triage and routing.
 
**Request body:**
```json
{
  "channel": "email",
  "customer_id": "cust-123",
  "message": "I want to return a defective item I bought last week",
  "metadata": {}
}
```
 
| Field | Type | Description |
|---|---|---|
| `channel` | string | `email`, `chat`, or `social_media` |
| `customer_id` | string | Unique identifier for the customer |
| `message` | string | The support ticket text content |
| `metadata` | object | Optional additional context |
 
**Response (200):**
```json
{
  "ticketId": "uuid",
  "action": "route",
  "agentId": "returns",
  "content": "processed successfully",
  "clarificationQuestion": null,
  "costUsd": 0.0042
}
```
 
| Field | Type | Description |
|---|---|---|
| `ticketId` | string | Generated ticket UUID |
| `action` | string | Routing action: `route`, `clarify`, or `fallback` |
| `agentId` | string | The specialist agent the ticket was routed to |
| `content` | string | The response content from the agent |
| `clarificationQuestion` | string? | Clarification question when action is `clarify` |
| `costUsd` | number | Estimated LLM cost for this interaction in USD |
 
**Response (400):** Validation error from zod schema.
 
## Specialist Agents
 
| Agent | Endpoint | Responsibility |
|---|---|---|
| **Returns** | `AGENT_RETURNS_ENDPOINT` (`http://localhost:4001`) | Handles product returns, refunds, and exchanges |
| **Billing** | `AGENT_BILLING_ENDPOINT` (`http://localhost:4002`) | Handles invoice disputes, payment failures, and billing inquiries |
| **Technical Support** | `AGENT_TECHNICAL_SUPPORT_ENDPOINT` (`http://localhost:4003`) | Handles troubleshooting, configuration help, and bug reports |
 
## Environment Variables
 
| Variable | Default | Description |
|---|---|---|
| `NODE_ENV` | `development` | Runtime environment |
| `PORT` | `3001` | HTTP server port |
| `COHERE_API_KEY` | — | Cohere API key for intent classification |
| `COHERE_MODEL` | `command-a-03-2025` | Cohere model ID |
| `MCP_REQUEST_TIMEOUT_MS` | `30000` | Timeout in ms for MCP agent requests |
| `MCP_MAX_RETRIES` | `3` | Max retry count for failed MCP requests |
| `ENABLE_CLARIFICATION` | `true` | Whether to request clarification on low-confidence tickets |
| `DEFAULT_DAILY_BUDGET` | `100.0` | Daily cost budget cap before routing is paused |
| `AGENT_RETURNS_ENDPOINT` | `http://localhost:4001` | Returns specialist agent URL |
| `AGENT_BILLING_ENDPOINT` | `http://localhost:4002` | Billing specialist agent URL |
| `AGENT_TECHNICAL_SUPPORT_ENDPOINT` | `http://localhost:4003` | Technical support specialist agent URL |
 
## Getting Started
 
```bash
# Install dependencies
pnpm install
 
# Configure environment (edit .env with your Cohere API key)
cp .env.example .env
 
# Start the triage server
pnpm dev
```
 
## Running Tests
 
```bash
pnpm test
```
 
## License
 
MIT — see [LICENSE](./LICENSE).