Inspiration
Every agency loses deals in the gap between "someone filled in the contact form" and "here is your proposal" — a gap measured in days of manual triage, copy writing, and follow-up. We run an AI agency ourselves and feel this friction daily. We built an agent that closes it: a lead submitted on the public form is classified, turned into a written proposal, given a delivery plan, and the client is notified — autonomously, in seconds, with every step recorded in an audit trail.
What it does
An agent pipeline that carries a lead from first contact to a delivery-ready proposal without a human in the loop. It fires automatically the moment a lead is stored — public form, webhook, any source:
- Intake — the public form validates and stores the lead.
- Classify — a fast Gemini sub-agent (gemini-3.5-flash) scores priority hot/warm/cold.
- Propose — a brain-tier Gemini sub-agent writes real overview, scope, timeline, and pricing copy grounded strictly in what the client stated.
- Plan — a delivery plan is generated: discovery → build → review → handover.
- Notify — a Telegram message goes out with the lead and its priority.
The dashboard shows all of it live, including the audit log — the agent's work is inspectable, not a black box.
How we built it
Built with Google ADK 2.7.1 (Python) — LlmAgent + FunctionTool for the agent runtime, Gemini API for the LLM (gemini-3.5-flash fast tier + brain tier for proposals), Next.js 15 (App Router, standalone output) with React 19 and TypeScript for the frontend/API, and SQLite via node:sqlite + sqlite3 for persistence — no ORM. Two runtimes in one deployable unit: Next.js serves the UI and API; a Python ADK agent runs per lead as a spawned subprocess, so model work never blocks an HTTP response. Both runtimes share one SQLite file and one append-only audit trail, and a single Edge middleware gates every protected route. Docker multi-stage deployment (Node 22 + Python venv in one image), Cloud Run ready.
Challenges we ran into
- gemini-3.5-pro does not exist. The model IDs in our original plan were plausible and wrong — verifying names against the live API before wiring them in caught it.
- .env load order bug: a sub-agent module read GEMINI_FAST_MODEL at import time, before load_dotenv() ran — env value silently ignored.
- Edge vs Node crypto: Next.js middleware runs on Edge runtime where node:crypto doesn't exist — build failed outright until we split Web Crypto HMAC for sessions and isolated scrypt in a Node-only module.
- Next.js output-file-tracing swept the SQLite database into the build — real lead data one COPY away from a public image layer. Fixed unconditionally in the Dockerfile.
- Live Gemini calls hit 503s and quota errors, crashing the pipeline mid-lead and leaving half-written rows — we made the offline heuristic the failure path for every live call.
Accomplishments that we're proud of
- Fully autonomous multi-step pipeline: one lead in, classified lead + written proposal + delivery plan + sent notification out — no operator action.
- Degrades instead of breaking: Gemini outage → deterministic fallback mid-run, lead still completes.
- Security-first: scrypt + timingSafeEqual auth, HMAC-signed sessions, per-IP rate limiting, fail-closed, append-only audit trail.
- Tests pass with no API key and no network — the product demos offline.
- It is now AI Invention's real lead pipeline in production, not a toy.
What we learned
The interesting problems were not the agent logic: model IDs must be verified against the live API, .env load order and module-level reads don't compose, Edge and Node crypto are not interchangeable, build output tracing can leak data into image layers, and a live model endpoint is never a dependency you can assume — the failure path matters as much as the happy path.
What's next for Client Onboarding Agent
- Deploy the backend to Google Cloud Run with a managed database (Cloud SQL) for retained state.
- Multi-channel notifications (email + WhatsApp) and a client-facing portal for proposal sign-off.
- Feedback loop: let clients reply to the proposal and have the agent revise it.
- Team workspace: multiple agents per account, each specialized per service line, with the audit trail as the compliance record.
Built With
- docker
- gemini-api
- google-adk
- google-cloud-run
- nextjs
- python
- react
- sqlite
- traefik
- typescript