Skip to content

About

Agentic AI solar sales rep - qualifies, quotes, and books a survey via tool-calling with generative UI (FlowZint AI Hackathon 2026)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

30 Commits

Folders and files

Repository files navigation

SunPath Solar β€” meet Sunny, your AI solar guide

β˜€οΈ SunPath Solar

Meet Sunny β€” an agentic AI solar sales rep that qualifies, sizes, quotes, and books a survey, live in chat.

Live demo Conversion eval Demo script

Next.js React Vercel AI SDK Gemini Tailwind CSS TypeScript Tests Failover License

πŸ† FlowZint AI Hackathon 2026 Β· Sales Bot track

Not a chat box over an FAQ. An agent that takes real actions β€” and proves it sells.


TL;DR β€” Most "sales bots" answer questions. Sunny runs the funnel. It qualifies a homeowner, sizes a real system, handles objections with grounded facts, builds a quote, and books a site survey β€” through 6 tools and multi-step tool-calling, with every action streaming into the chat as a bespoke interactive card. It's measured against one number: booked surveys from genuinely qualified homeowners, via a reproducible A/B eval.

🌐 Livesunpath-beige.vercel.app β€” answers even during provider brownouts (automatic failover)
πŸ€– Agent6 typed tools Β· multi-step tool-calling Β· every action renders as generative UI
πŸ“ˆ Proofreproducible A/B conversion-lift eval β†’ /results
🧯 Reliability3-layer tool-call defense Β· 12s primary budget β†’ Groq failover β€” each defense born from a failure hit live
βœ… Tests26 unit tests pinning the economics engine and the schema hardening

Qualify ➜ Design ➜ Quote ➜ Book β€” and an honest "not a fit" when that's the truth.


πŸ“‘ Contents


πŸ” Why this exists

Residential solar is a high-consideration, high-ticket sale. The bottleneck is rarely the panels β€” it's the funnel:

Stage Where deals die
Qualification Reps waste hours on renters, tiny bills, and people who won't move β€” or worse, pressure a bad-fit homeowner and burn trust.
Education Buyers don't understand sizing, incentives, or payback, so they stall.
Objections "Too expensive," "what about my roof," "I'm moving" β€” answered inconsistently, often with made-up numbers.
Conversion The single highest-value action β€” booking a site survey β€” gets lost in a thread of Q&A.

A generic FAQ chatbot answers questions. It doesn't qualify, it doesn't size, it doesn't quote, and it almost never closes. SunPath's thesis: the win is an agent that drives the funnel end-to-end while staying honest β€” and can prove it lifts conversion.


⚑ What makes it agentic (not a chat wrapper)

flowchart LR
    A["πŸ—£οΈ Plain-English<br/>homeowner message"] --> B["🧠 Sunny reasons<br/>over a sales methodology"]
    B --> C{"Decide an action"}
    C -->|"qualify"| T1["scoreLead"]
    C -->|"size"| T2["recommendSystem"]
    C -->|"incentives"| T3["lookupIncentives"]
    C -->|"quote"| T4["generateQuote"]
    C -->|"close"| T5["bookSurvey"]
    C -->|"record"| T6["logToCRM"]
    T1 & T2 & T3 & T4 & T5 & T6 --> D["πŸ“¦ Structured result"]
    D --> E["🎴 Streams in as a<br/>live interactive card"]
    D --> B
    E --> F["Funnel rail advances:<br/>Qualify β†’ Design β†’ Quote β†’ Book"]
Loading

Three things make this an agent, not a wrapper:

  1. It acts. Tools have side effects (a quote is generated, a survey is booked, the CRM is updated) β€” not just retrieval.
  2. It chains. One user turn can fire several tools in sequence (scoreLead β†’ recommendSystem β†’ reply) via multi-step tool-calling (stopWhen: stepCountIs(10)).
  3. It renders itself. Each tool result streams into the UI as a purpose-built component β€” the agent's reasoning becomes a tangible artifact.

πŸ— System architecture

flowchart TB
    subgraph Client["πŸ–₯️  Browser β€” Next.js 16 Β· React 19"]
        UI["Chat UI<br/>useChat + DefaultChatTransport"]
        Cards["Generative-UI cards<br/>score Β· system Β· incentives Β· quote Β· booking"]
        Rail["Funnel rail<br/>Qualify β†’ Design β†’ Quote β†’ Book"]
    end

    subgraph Server["⚑  Route Handler β€” app/api/chat"]
        Stream["streamText( )<br/>multi-step: stopWhen stepCountIs(10)"]
        Tools["6 agentic tools<br/>Zod-typed input + execute( )"]
    end

    subgraph KB["πŸ“š  Knowledge base β€” lib/"]
        Catalog["Catalog Β· incentives<br/>financing Β· objection playbook"]
        Econ["Economics engine<br/>sizing Β· ITC Β· payback Β· 25-yr savings"]
    end

    Model["🧠  Gemini Flash β€” auto-failover β†’ Groq<br/>(env-swap β†’ Claude Opus 4.8)"]

    UI -->|"UIMessage stream"| Stream
    Stream <-->|"reason Β· generate"| Model
    Stream <-->|"tool calls / results"| Tools
    Tools --> Catalog
    Tools --> Econ
    Stream -.->|"streamed tool parts"| Cards
    Cards --> Rail
Loading

Separation of concerns is deliberate: the model decides what to do, the tools decide how (and enforce the rules), the knowledge base owns the facts, and the UI turns each action into something a homeowner can see and trust. Swapping the model touches exactly one line.


πŸ€– How the agent works (a real turn)

A genuine exchange, captured from the running app:

sequenceDiagram
    actor H as 🏠 Homeowner
    participant UI as Chat UI
    participant S as Sunny (agent)
    participant T as Tools
    participant G as Gemini

    H->>UI: "I own my home in CA, bill ~$260/mo, want solar this year"
    UI->>S: stream request (system prompt + history)
    S->>G: reason
    G-->>S: tool call Β· scoreLead(homeowner, 260, CA)
    S->>T: execute scoreLead
    T-->>S: { score: 83, tier: "hot", qualified: true }
    Note over UI: 🟒 Lead-score gauge streams in (83/100, "Hot lead")
    S->>G: continue (multi-step)
    G-->>S: tool call Β· recommendSystem(260, CA)
    S->>T: execute recommendSystem
    T-->>S: { SunPath Whole-Home, net $23,700, 9.6-yr payback, $2,464/yr }
    Note over UI: β˜€οΈ System card streams in (grounded numbers)
    S-->>H: "Whole-Home, ~$23.7k net after the $10.8k ITC… payback ~9.6 yrs"
    S->>H: "Cash, loan, or lease? I can put together a quote."
Loading

Note what happened: from one plain-English sentence, the agent extracted { homeowner, bill, state }, scored the lead, sized a system with real economics, and drove toward a quote β€” two tool calls, two cards, one coherent reply.


🧰 The 6 tools

Every tool is a typed function (Zod input schema + execute) the model can call. The names below are exactly what the model sees.

Tool Purpose Renders as
🎯 scoreLead BANT-style qualification β†’ 0–100 score, tier, what's still missing Animated score gauge
β˜€οΈ recommendSystem Picks the right package for the bill + computes full economics System card (net price Β· payback Β· yr-1 savings)
πŸ’Έ lookupIncentives Federal ITC (30%) + state-specific programs Incentives card
πŸ“„ generateQuote Formal quote with a price waterfall + financing + monthly estimate Quote card (25-yr savings hero)
πŸ“… bookSurvey Books the on-site survey β€” the conversion Booking confirmation
πŸ—ƒοΈ logToCRM Records the lead + pipeline stage System log line

Tools are the security and honesty boundary: the model can ask for a price, but only recommendSystem / generateQuote can produce one β€” and they read it from the knowledge base, never invent it.


πŸ” The sales funnel as a state machine

stateDiagram-v2
    [*] --> Qualify
    Qualify --> Design: scoreLead passes
    Qualify --> Exit: not a fit, honest exit
    Design --> Quote: recommendSystem + lookupIncentives
    Quote --> Book: generateQuote, interested
    Book --> Logged: bookSurvey + logToCRM
    Logged --> [*]
    Exit --> [*]
Loading

The Exit path is a feature, not a bug. Sunny is scored on booked surveys from well-fit homeowners β€” so a polite "solar won't pay off for you yet" is a success, and the eval rewards it.


🎴 Generative UI β€” the agent renders itself

This is the showpiece. In most chatbots, a tool call is invisible plumbing. Here, the AI SDK v7 UI message stream carries typed tool parts, and the client maps each to a bespoke React component (with Motion entrance animations):

flowchart LR
    TR["Tool result<br/>(typed JSON)"] --> P["UI message part<br/>type: tool-&lt;name&gt;, state: output-available"]
    P --> D{"Dispatcher<br/>components/tool-cards.tsx"}
    D -->|scoreLead| C1["⏱️ Score gauge"]
    D -->|recommendSystem| C2["β˜€οΈ System card"]
    D -->|lookupIncentives| C3["πŸ’Έ Incentives"]
    D -->|generateQuote| C4["πŸ“„ Quote waterfall"]
    D -->|bookSurvey| C5["βœ… Booking"]
    D -->|logToCRM| C6["πŸ—ƒοΈ CRM log"]
    D -->|"input-available"| SK["✨ Live skeleton"]
Loading

The homeowner doesn't read about a quote β€” they watch the quote assemble itself, line by line, with a 25-year-savings number that animates in. That tangibility is the difference between "a chatbot told me" and "I saw my numbers."


πŸ›‘ Trust by construction (no hallucinated numbers)

The fastest way to lose a high-ticket sale is a number that turns out to be wrong. SunPath makes that structurally hard:

flowchart LR
    M["🧠 Model wants to<br/>state a price / saving / incentive"] --> G{Grounding gate}
    G -->|"must call a tool"| T["Tool reads lib/solar-data.ts<br/>+ economics engine"]
    T -->|"exact, reproducible figures"| M
    G -.->|"❌ blocked by system prompt"| X["invented numbers"]
    OBJ["Homeowner objection"] --> PB["Approved objection playbook<br/>(7 grounded rebuttals)"]
    PB --> M
Loading
  • Numbers come from the catalog + economics engine (gross β†’ βˆ’ITC β†’ βˆ’state = net; payback = net Γ· annual savings; 25-yr savings with rate inflation). Same inputs β†’ same outputs, every time.
  • Objections are answered from an approved playbook of 7 grounded rebuttals (cost, payback, roof, moving, aesthetics, reliability, maintenance) β€” not improvised.
  • Honesty is a hard rule: the system prompt forbids inventing figures, over-promising utility approval, or pushing a bad-fit homeowner.

🧯 Reliability engineering

Free-tier LLM infrastructure fails in real, observed ways. Every row below is a failure we actually hit while building β€” each one became a shipped defense plus a regression test, not a disclaimer:

Failure we hit (for real) Defense in the code
Gemini free tier: 503 β€” model experiencing high demand, mid-conversation Automatic provider failover (lib/model.ts): the call transparently retries on Groq before any tokens stream β€” the homeowner just gets an answer
A congested primary stalled long enough to eat the route's whole 60s window β€” killing the turn even though the backup was healthy 12-second start budget: the primary races a timer on every call; miss it and the fallback serves. Worst-case time-to-first-token is bounded
429 RESOURCE_EXHAUSTED (daily quota) Quota-aware error UX: the route maps 429s to friendly, in-character copy and the chat UI surfaces it with a retry β€” never a raw stack trace
Models emit null, "240", or free text where schemas expected enums/numbers (crashed two eval runs) Nullable-everything tool schemas β€” .nullish(), z.coerce.number(), fallback ids β€” a tool-input validation crash is now structurally impossible
Models call tools before collecting prerequisites (sizing with no bill, booking with no contact) Needs-info steering: the tool returns { needsInfo, message } so the agent asks the homeowner and retries β€” the turn is guided, not killed
gpt-oss garbled a tool name: logToCRM<|channel|>commentary β†’ NoSuchToolError Tool-call repair hook strips the token leak and re-targets the real tool; genuinely unknown names still fail loudly
Token-per-day caps abort long eval runs Resumable eval: every conversation checkpoints to disk, re-runs skip finished work, and retries honor the provider's try again in Xs hint
flowchart LR
    R["Chat request"] --> P["Primary model<br/>(Gemini, 12s start budget)"]
    P -->|"streams"| OK["Reply streams to the homeowner"]
    P -->|"429 / 5xx / 401 / 403<br/>or budget exceeded"| F["Groq gpt-oss-120b<br/>(fallback)"]
    F -->|"streams"| OK
    F -.->|"also down"| E["Friendly, quota-aware<br/>error + retry in the UI"]
Loading

Verified live β€” not just written:

  • πŸ”‘ Blanked the Google key (surfaces as 403 PERMISSION_DENIED) β†’ failover served the reply.
  • 🌩️ During a real Gemini brownout, a dead-primary request completed via Groq in 1.9 seconds end-to-end.
  • πŸ›°οΈ The production deployment rode out that same brownout serving real traffic from the fallback β€” invisibly to users.

Failover chain: primary (SUNPATH_PROVIDER, default Gemini) β†’ Groq gpt-oss-120b whenever GROQ_API_KEY is set. Kill switch: SUNPATH_FAILOVER=0. 26 unit tests (npm test) pin the economics engine and every schema-hardening lesson above.


πŸ“ˆ Does it actually sell? The conversion-lift eval

Claims are cheap. eval/run.ts is a controlled A/B experiment that measures whether the agent converts better than a baseline FAQ bot.

flowchart LR
    P["16 simulated leads<br/>eval/personas.ts<br/>(ground-truth: qualified?)"]
    P --> AG["Arm A β€” Sunny<br/>agent + 6 tools + methodology"]
    P --> BL["Arm B β€” Baseline<br/>plain FAQ bot, no tools"]
    AG --> CV["Same lead-simulator drives both<br/>identical discerning-buyer protocol"]
    BL --> CV
    CV --> MET["Metrics per arm:<br/>β€’ completed bookings among qualified leads<br/>β€’ stated willingness (for contrast)<br/>β€’ false-push rate (unqualified)<br/>β€’ qualification accuracy"]
    MET --> OUT["eval/results.json β†’ live /results dashboard"]
Loading

What counts as a conversion β€” completed bookings, not compliments. A pilot run scored lead-stated willingness and the metric saturated: a polite FAQ bot hit 100% willingness while being unable to book anything. So the headline metric counts bookings that exist: for Sunny, a verified bookSurvey tool execution (appointment created, name + contact captured); for the baseline, explicit agreement plus a contact captured in-chat β€” it can still convert, it just has to do real funnel work. Willingness is still recorded per arm and shown alongside, because the saturation itself is a finding.

Why the design is fair: both arms use the same model and the same lead-simulator, with one identical discerning-buyer protocol β€” leads book only after concrete case-specific numbers, their concern addressed, and a proposed next step, and they hand over contact info when agreeing. The only variable is the rep. The 16 personas carry a ground-truth qualified flag (incl. a renter and a tiny-bill household), so we score not just did it book but did it book the right people.

Run it:

npm run eval        # β†’ writes eval/results.json, surfaced at /results

It outputs the shape below (run it for live numbers):

{
  "metric":   "completed-booking-v2: …",
  "agentic":  { "convQualifiedPct": __, "willingQualifiedPct": __, "falsePushPct": __, "qualAccuracyPct": __ },
  "baseline": { "convQualifiedPct": __, "willingQualifiedPct": __, "falsePushPct": __, "qualAccuracyPct": __ },
  "liftPoints": __, "relativeLiftPct": __
}

♻️ Built to survive free tiers: the run is resumable β€” every finished conversation checkpoints to eval/.eval-cache.json, so a quota interruption resumes instead of restarting, and retries honor the provider's try again in Xs hint. The harness is provider-agnostic (AGENT_PROVIDER / LEAD_PROVIDER / AGENT_MODEL / LEAD_MODEL), so the full 32-conversation A/B runs free on Groq; PERSONA_LIMIT supports smaller smoke runs.


🧱 Tech stack & why each choice

Every dependency is bleeding-edge on purpose β€” and chosen for a reason, not novelty.

Layer Choice Why
Framework Next.js 16 (App Router, Turbopack) Β· React 19.2 Streaming-native route handlers; Server Components; one runtime for API + UI
Agent runtime Vercel AI SDK v7 (streamText, stopWhen: stepCountIs, convertToModelMessages) First-class multi-step tool-calling + provider-agnostic (swap models in 1 line)
Generative UI AI SDK UI message stream β†’ typed tool-* parts β†’ React Tool calls become interactive components, not invisible plumbing
Model Gemini Flash Β· auto-failover β†’ Groq gpt-oss-120b Β· env-swap β†’ Claude Opus 4.8 Strong tool-calling at zero cost, resilient to free-tier outages, trivially upgraded
Schemas Zod 4 Typed tool inputs the model must satisfy; doubles as runtime validation
Styling Tailwind v4 (@theme) + Motion 12 A custom design system, not a component library; tasteful, GPU-friendly motion
Icons / type lucide-react Β· Fraunces display + Geist Distinctive, non-generic visual identity

Note for reviewers: the codebase was written against the installed type definitions (AI SDK v7, Next 16, Zod 4 differ materially from older majors) β€” not from memory. It builds clean on the first try (npm run build).


πŸ—‚ Project structure

sunpath/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/chat/route.ts      # the agent loop β€” streamText + tools + multi-step
β”‚   β”œβ”€β”€ page.tsx               # the chat experience (+ measured-lift badge)
β”‚   β”œβ”€β”€ opengraph-image.tsx    # generated social share card (next/og)
β”‚   └── results/page.tsx       # conversion-lift dashboard (reads eval/results.json)
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ chat.tsx               # useChat client Β· message + tool-part rendering Β· funnel rail
β”‚   β”œβ”€β”€ tool-cards.tsx         # generative UI β€” one bespoke card per tool
β”‚   β”œβ”€β”€ ticker-number.tsx      # count-up numerals (score, savings) β€” reduced-motion aware
β”‚   β”œβ”€β”€ stage-rail.tsx         # Qualify β†’ Design β†’ Quote β†’ Book progress
β”‚   └── atmosphere.tsx         # starfield dusk + solar-glow backdrop
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ agent-prompt.ts        # Sunny's system prompt (composed from the KB)
β”‚   β”œβ”€β”€ model.ts               # provider selection + automatic failover chain
β”‚   β”œβ”€β”€ tools.ts               # the 6 agent tools (hardened Zod schemas + execute)
β”‚   β”œβ”€β”€ tools.test.ts          # regression tests for the schema hardening
β”‚   β”œβ”€β”€ solar-data.ts          # catalog Β· incentives Β· financing Β· objections Β· economics
β”‚   β”œβ”€β”€ solar-data.test.ts     # economics engine unit tests
β”‚   β”œβ”€β”€ tool-types.ts          # shared types mirroring tool outputs
β”‚   └── utils.ts               # formatting + cn()
β”œβ”€β”€ eval/
β”‚   β”œβ”€β”€ personas.ts            # 16 simulated leads (ground-truth qualified flag)
β”‚   └── run.ts                 # the conversion-lift harness (resumable, provider-agnostic)
└── DEMO.md                    # shot-for-shot demo-video script

πŸš€ Quickstart

# 1. Install
npm install

# 2. Add a model key (free β€” Google AI Studio: https://aistudio.google.com/apikey)
cp .env.example .env.local      # paste your key as GOOGLE_GENERATIVE_AI_API_KEY

# 3. Run
npm run dev                     # β†’ http://localhost:3000

# 4. (optional) run the test suite β€” economics engine + tool-schema hardening
npm test

# 5. (optional) generate the conversion-lift numbers β€” free on Groq (console.groq.com)
#    add GROQ_API_KEY to .env.local, then:
AGENT_PROVIDER=groq LEAD_PROVIDER=groq LEAD_MODEL=llama-3.3-70b-versatile npm run eval

Build: npm run build. The app needs GOOGLE_GENERATIVE_AI_API_KEY (default provider); adding GROQ_API_KEY enables automatic failover.


☁️ Deployment

GitHub-linked Vercel import (auto-redeploys on push):

  1. vercel.com/new β†’ import this repo.
  2. Framework auto-detects Next.js β€” keep defaults.
  3. Add env vars: GOOGLE_GENERATIVE_AI_API_KEY (primary model) and, optionally, GROQ_API_KEY (turns on automatic failover). Keys are not in the repo, by design.
  4. Deploy β†’ public URL in ~90s.

🎯 How it maps to the rubric

Criterion Weight How SunPath earns it
Model Innovation 30% Genuine multi-step agentic tool-use + generative UI β€” the agent acts and renders itself, not a Q&A wrapper
Real-World Applicability 25% A measurable business outcome (booking lift) on a real funnel, grounded in defensible economics
Technical Architecture 25% Clean separation (agent / tools / data / UI / eval), typed end-to-end, public repo, builds clean on a 2026 stack
Documentation 20% This README + a shot-for-shot demo script + a self-explanatory /results dashboard + a reproducible eval

🎨 Design system β€” "Twilight Energy"

A deliberate, non-generic aesthetic β€” no Inter, no purple-on-white:

  • Canvas: deep dusk sky with a warm solar glow rising from the horizon, drifting energy rings, a fine grain overlay.
  • Type: Fraunces (optical display serif) against Geist β€” warmth + precision.
  • Accent: a sun/ember gradient; a single cool sky tone; a leaf green reserved for savings.
  • Motion: staggered card entrances, an animating score ring, a celebratory booking check β€” high-impact moments, prefers-reduced-motion respected.

πŸ›£ Roadmap

  • Publish the headline conversion-lift number on /results (full A/B run in progress β€” the harness is resumable)
  • Shot-for-shot demo script (DEMO.md) β€” video recording next
  • Final demo on Claude Opus 4.8 (already wired β€” SUNPATH_PROVIDER=anthropic)
  • Bilingual (AR/EN) toggle β€” the agent already replies in the user's language
  • Voice input (Web Speech) for a hands-free funnel
  • Real CRM / calendar integration behind the logToCRM / bookSurvey tools

πŸ“„ Disclaimer & license

SunPath Solar is a fictional installer. The company, catalog, and customers are invented; all figures are realistic US-market estimates used to keep the demo honest, and are confirmed at survey in the narrative. Nothing here is solar financial advice.

Licensed under the MIT License β€” see LICENSE.

Built for the FlowZint AI Hackathon 2026 Β· Sales Bot track

About

Agentic AI solar sales rep - qualifies, quotes, and books a survey via tool-calling with generative UI (FlowZint AI Hackathon 2026)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages