Files · Perplexity Agent Mesh for SMB Competitive Intelligence
78 (1 binary, 616.9 kB total)attempt 1
README.md·4728 B·markdown
markdown
# Perplexity Agent Mesh for SMB Competitive Intelligence
> Deploy a mesh of AI agents that continuously monitors competitors, tracks market shifts, and surfaces actionable insights for your business.
Small businesses can't afford dedicated market research teams, yet they need timely competitive intelligence to stay ahead. Manual tracking of news, pricing, and product changes is overwhelming. This solution orchestrates a multi-agent mesh using LangGraph + Perplexity to automate competitive research.
## Architecture
```
User Query → MeshHub → classifierService (intent classification)
↓
ConfidenceRouter (threshold decision)
↓
agent-mesh-router dispatch
↓
┌───────────┼───────────┐
│ │ │
Competitor Price News
Tracker Monitor Summarizer
│ │ │
└───────────┼───────────┘
↓
Perplexity SDK (web-grounded search)
↓
CostGuard (spend tracking & budget enforcement)
```
- **MeshHub**: LangGraph state machine orchestrating classification, routing, and response
- **classifierService** (`@reaatech/agent-mesh-classifier`): Intent classification against agent registry
- **ConfidenceRouter** (`@reaatech/confidence-router`): Threshold-based routing decisions (ROUTE / CLARIFY / FALLBACK)
- **agent-mesh-router** (`@reaatech/agent-mesh-router`): MCP dispatch to specialist agents
- **Specialist Agents**: Competitor-tracker, price-monitor, news-summarizer with inter-agent handoff via `@reaatech/agent-handoff`
- **CostGuard**: Wraps all Perplexity API calls with `@reaatech/llm-cost-telemetry` for spend tracking and daily budget enforcement
## Setup
### Environment Variables
| Variable | Description |
|---|---|
| `PERPLEXITY_API_KEY` | Perplexity API authentication |
| `GOOGLE_CLOUD_PROJECT` | GCP project (classifier Gemini Flash) |
| `GOOGLE_CLOUD_LOCATION` | Vertex AI region (default: us-central1) |
| `GOOGLE_GENAI_USE_VERTEXAI` | Route GenAI SDK to Vertex (`true`) |
| `SESSION_TTL_MINUTES` | Session TTL (default: 30) |
| `SESSION_MAX_TURNS` | Max turns per session (default: 100) |
| `MCP_REQUEST_TIMEOUT_MS` | MCP dispatch timeout (default: 30000) |
| `MCP_MAX_RETRIES` | MCP retry count (default: 3) |
| `DEFAULT_DAILY_BUDGET` | Daily spend cap in USD (default: 5.00) |
| `NEXT_PUBLIC_APP_URL` | Public-facing app URL |
### Running
```bash
pnpm install
pnpm dev # Next.js dev server (http://localhost:3000)
pnpm test # vitest run with coverage
pnpm typecheck # TypeScript type checking
pnpm lint # ESLint
```
## API Endpoints
### `POST /api/query`
Submit a competitive intelligence query.
```json
{ "query": "What is Acme Corp doing in AI?" }
```
Response:
```json
{ "ok": true, "intel": [...], "cost": 0.05, "budgetRemaining": 4.95 }
```
### `POST /api/webhook`
Ingest external triggers (RSS, alerts, webhooks).
```json
{ "source": "slack", "payload": { "text": "new competitor entry" } }
```
### `GET /api/status`
Mesh health and metrics.
```json
{ "status": "ok", "sessionsActive": 0, "costToDate": 0.05, "agentsRegistered": ["competitor-tracker", "price-monitor", "news-summarizer"] }
```
## Agent Capabilities
| Agent | Skills | Domain |
|---|---|---|
| Competitor Tracker | competitor-tracking, market-research | competitive-intelligence |
| Price Monitor | pricing-intelligence, price-tracking | competitive-intelligence |
| News Summarizer | news-summarization, industry-analysis | competitive-intelligence |
## Packages
### REAA Foundation
- `@reaatech/agent-mesh` — Core domain types, Zod schemas, and shared constants for the agent-mesh ecosystem
- `@reaatech/agent-mesh-classifier` — Gemini Flash intent classifier with keyword-based mock fallback
- `@reaatech/agent-mesh-session` — Firestore-backed multi-turn session management
### REAA Supporting
- `@reaatech/agent-mesh-router` — MCP dispatch layer with connection pooling and circuit breakers
- `@reaatech/agent-handoff` — Agent Handoff Protocol types, typed event emitter, and retry utilities
- `@reaatech/llm-cost-telemetry` — Cost span tracking, budget configuration, and time-window arithmetic
- `@reaatech/confidence-router` — Threshold-based decision engine for classification routing
### Third-Party
- `@langchain/langgraph` — Stateful agent graph orchestration
- `perplexity-sdk` — Perplexity AI chat completions API
- `zod` — Runtime schema validation
- `nanoid` — URL-safe unique ID generation
## License
MIT — see [LICENSE](./LICENSE).