# Sonar

Personal project exploring multi-agent orchestration. The use case is sales-call review; the actual point was learning Anthropic tool use, prompt caching, and persisted agent state end to end.

- Status: live
- Role: Solo — design, engineering, deployment
- Period: Sep 2025 – Present
- Stack: Next.js 16, TypeScript, Claude Sonnet 4.6, Claude Haiku 4.5, Groq Whisper Large v3, Tavily, Supabase Storage, PostgreSQL + pgvector, Prisma, Stripe, Resend, Tailwind v4, shadcn/ui
- Links: [Live](https://sonar.picoral.me) · [Repo](https://github.com/feRpicoral/sonar)
- Canonical: https://picoral.me/projects/sonar

## What it does

A sales rep uploads a call recording. About twenty seconds later, Sonar returns:

1. Research on the prospect's company (Tavily + Claude Haiku 4.5)
2. Structured analysis of the call — topics, pain points, objections, action items, sentiment (Claude Sonnet 4.6)
3. A recommended next step with talking points and urgency (Claude Sonnet 4.6)
4. A follow-up email draft with bracketed citations linking back to transcript segments (Claude Sonnet 4.6)

_The workspace dashboard: leads, calls, and agent runs at a glance._

The reviewer sees a split-view UI: email on the left, transcript on the right. Hovering a citation highlights the matching segment. The reviewer can approve, edit the body in place, or regenerate the writer with feedback. Regeneration reuses the prior research, analysis, and strategy state; only the writer runs again.

_Approve & send: every claim in the draft links to the transcript segment it came from._

## Why I built it

Not a product — a personal project. I wanted one codebase that exercised the modern AI stack end to end: multi-agent orchestration with persistent state, real audio handling, structured tool use, prompt caching, and the multi-tenant B2B shape. Sales-call review was the domain because the workflow is genuinely linear-with-rollback, which is the sweet spot for agent graphs.

## How it works

### Multi-agent orchestration

- Five sequential nodes: transcription, then research, analysis, strategy, and writer.
- Every agent node returns structured output via Anthropic tool use + a Zod schema. No free-text outputs.
- Each step writes an `AgentRunStep` row. The run pauses at `AWAITING_APPROVAL` after the writer step.
- Anthropic prompt caching is enabled on system messages — ~70% input-token reduction on repeat runs.
- Writer regeneration reuses upstream state.
- Background execution via Next.js 16's `after()` route handler (`maxDuration = 300`).

_The run viewer: each node reports status live; the run pauses for approval after the writer._

### Audio processing

- Drag-drop upload goes browser to Supabase Storage via signed URL. The server is not in the upload path.
- Groq Whisper Large v3 transcribes with segment-level timestamps.
- MIME type and 100 MB cap enforced both on the server action and bucket policy.
- The writer receives transcript segments tagged with bracketed indices; citations reference those indices.
- The split-view UI scrolls the cited segment into view on hover.

### Multi-tenant B2B

Workspaces, roles (`OWNER`, `ADMIN`, `MEMBER`), invites, API keys, audit log, Stripe billing, and delivery tracking through Resend. Three isolation layers — Postgres row-level scoping, application-layer guards on every server action, and Supabase Storage bucket policies keyed by workspace ID.

## Status

Live at [sonar.picoral.me](https://sonar.picoral.me). The agent pipeline, workspace tenancy, and follow-up delivery are working end to end; a Loom walkthrough is next.

## Questions

### What is Sonar?

Sonar is a multi-agent AI workspace for sales teams. A rep uploads a recorded sales call; about twenty seconds later they have prospect research, a structured call analysis, a recommended next step, and a follow-up email draft with citations linking each claim back to a specific transcript segment.

### How does Sonar's multi-agent orchestration work?

A five-node run — transcription, then four Claude agent nodes for research, analysis, strategy, and writer — each returning structured output through Anthropic tool use with Zod schemas. Every step writes an AgentRunStep row to Postgres; the run pauses at AWAITING_APPROVAL after the writer step for human review. The writer can be regenerated with reviewer feedback without re-running the upstream nodes.

### Why does Sonar use Anthropic prompt caching?

System messages are cached on every node. On repeat runs against the same workspace, this cuts input tokens roughly 70%, which compounds into latency and cost wins as the corpus of workspace context grows.
