Files · Mistral AI Lead Intake for Marketo Lead Qualification & Routing
70 (1 binary, 578.8 kB total)attempt 2
README.md·3211 B·markdown
markdown
# Mistral AI Lead Intake for Marketo Lead Qualification & Routing
> Automatically qualify and route Marketo leads using AI, ensuring high-intent prospects reach the right rep instantly.
A tutorialized reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build production-grade AI systems with the `@reaatech/*` package family.
## Problem
Marketing-qualified leads from Marketo often sit unworked because they are not scored or routed quickly, especially in lean SMB teams.
## Pipeline architecture
1. Marketo sends a lead-creation webhook to `app/api/webhooks/marketo/route.ts`
2. HMAC-SHA1 signature verification + Zod validation in `src/api/marketo/webhook.ts`
3. Event normalization via `@reaatech/webhook-relay-core` `NormalizedEvent` shape
4. Mistral-powered lead enrichment via `@reaatech/agent-mesh` schemas in `src/agents/qualifier.ts`
5. Confidence-based routing via `@reaatech/confidence-router` in `src/lib/router.ts`
6. Session state for follow-ups via `@reaatech/session-continuity` in `src/lib/session.ts`
7. Budget enforcement + cost telemetry via `@reaatech/agent-budget-engine` / `@reaatech/llm-cost-telemetry` in `src/lib/cost.ts`
8. LLM response caching via `@reaatech/llm-cache` in `src/lib/cache.ts`
9. Enriched lead write-back to Marketo REST API via `src/api/marketo/client.ts`
## Environment variables
| Variable | Description |
|---|---|
| `NODE_ENV` | Runtime environment (`development`) |
| `MISTRAL_API_KEY` | Mistral AI API key for lead enrichment |
| `MARKETO_CLIENT_ID` | Marketo REST API client ID |
| `MARKETO_CLIENT_SECRET` | Marketo REST API client secret |
| `MARKETO_BASE_URL` | Marketo instance base URL (e.g. `https://your-instance.mktorest.com`) |
| `MARKETO_WEBHOOK_SECRET` | HMAC secret for webhook signature verification |
| `LANGFUSE_PUBLIC_KEY` | Langfuse public key for observability |
| `LANGFUSE_SECRET_KEY` | Langfuse secret key for observability |
| `LANGFUSE_BASE_URL` | Langfuse base URL (e.g. `https://cloud.langfuse.com`) |
| `LLM_CACHE_EMBEDDING_API_KEY` | OpenAI API key for LLM cache embeddings |
| `DEFAULT_DAILY_BUDGET` | Default daily budget in USD (`5.0`) |
## Quick Start
```bash
pnpm install
cp .env.example .env # fill in your keys
pnpm dev
```
## Test commands
```bash
pnpm test # vitest run with coverage
pnpm typecheck # TypeScript type-checking
pnpm lint # lint with banned-pattern enforcement
```
## REAA packages
| Package | Role |
|---|---|
| `@reaatech/webhook-relay-core` | Normalized event types and config loaders for webhook ingestion |
| `@reaatech/agent-mesh` | Typed schemas for agent requests, context packets, and confidence decisions |
| `@reaatech/confidence-router` | Threshold-based routing decisions (ROUTE / CLARIFY / FALLBACK) |
| `@reaatech/session-continuity` | Session state management for multi-turn lead follow-ups |
| `@reaatech/llm-cost-telemetry` | Cost-span generation and cost calculation from token usage |
| `@reaatech/agent-budget-engine` | Budget controller with soft/hard caps and policy evaluation |
| `@reaatech/llm-cache` | Embedding-based LLM response cache with similarity search |
## License
MIT -- see [LICENSE](./LICENSE).