Vetiver Supply Chain Explorer
Chat-driven supply chain research for vetiver (khus). India growing regions, 12-18 month crop cycle, chemical vs organic inputs at each stage, and real UN Comtrade trade flows across 5 supply chain stages. The interactive map on the side updates as you ask.
What this proves
A public-data explorer stops being a dashboard and starts being a conversation the moment you put an LLM with tools between the user and the data. The map reacts to the questions. Tool outputs drive other UI surfaces.
How it works
Who Asked For This
A friend's family farms a few acres in India and wants to plant vetiver. The specific questions they have, like what happens in month 6 vs month 12, chemical or organic pathway, who buys the essential oil and at what premium, are answerable from public extension material and trade data. But that data is fragmented across PDFs, UN Comtrade dashboards, and state agriculture department reports.
The existing India Trade Explorer on this site proved you can take opaque trade data and make it navigable. This build is the next step: instead of making people click through filters, let them ask in plain language and have the map, data panels, and supply chain strip respond.
What It Does
- Left side: chat. Ask anything about vetiver in India, regions, cycle, inputs, trade flows.
- Right side: interactive map. When the answer is about Indian states, the map fills India with the relevant states highlighted. When the answer is about trade destinations, the map switches to world view and fills the importing or exporting countries.
- Supply chain strip. Five clickable stage cards above the map. Cultivation → Bulk oil → Formulation → Finished goods → Consumers. Click a stage, the chat asks the right question, the right HS code is queried against live UN Comtrade, and the map plus data panels update together.
- Value capture button. One click runs a two-query comparison: India's bulk essential-oil exports (HS 330129) vs France's finished-perfume exports (HS 3303), same year. The ratio is the margin stack between stages. For 2023 it is about 130x.
Under the hood: a streamText call against Gemini 2.5 Flash (via Vertex AI) with seven tools. query_growing_regions and query_crop_cycle hit curated agronomy data from ICAR-IIHR and CSIR-CIMAP. query_comtrade_trade, query_supply_chain_stage, and compare_value_capture hit the UN Comtrade public API live. highlight_map and query_global_context round it out. Tool call outputs flow back through the UIMessage stream; the React component reads the latest outputs and drives the Mapbox layers, trade tables, stage narrative panels, and the value-capture callout from them. No separate "update the map" endpoint, the model itself decides when every UI surface should change.
Why This Pattern Matters
Most "chat with your data" products treat the UI as a transcript window. The interesting pattern is when the chat drives other UI surfaces like maps, tables, stage strips, and callouts. The model is no longer just answering, it is conducting the interface.
- Tool call outputs are structured events. The map reading
tool-highlight_map.outputis the same pattern as an email client readingtool-send_email.output. - Supply chain framing comes from the HS code schema itself. Cultivation to finished goods is HS 330129 → HS 3302 → HS 3303. Each stage is a different reporter country and sometimes a different flow direction. All queryable with one typed tool.
- Live public data beats a seeded prior. First draft of this build used synthetic numbers (I guessed shares based on IFEAT reports). When I wired UN Comtrade in for real, my seed had USA exports 3x too high and missed Spain entirely. The AI is only as honest as its sources; tying the model to live data is what makes the conversation defensible.
Patterns Worth Borrowing
- Let the model decide when UI state changes. Expose a
highlight_maptool instead of writing your own intent-classification layer. - Render tool outputs, not just text. Data panels tied to tool calls give the user something to act on and a natural next question.
- Keep the caveats visible. HS 330129 bundles vetiver with a few other essential oils. HS 3303 bundles every fragrance, so the 130x value capture ratio is a ceiling, not a vetiver-specific truth. The UI says so. The model is instructed to say so.
- Public data has seams. UN Comtrade's
partner2dimension is wildly different between HS chapters. Essential oils returns one total row per partner. Perfumes returns 5 to 6 regional breakdown rows per partner. The client-side dedupe has to handle both.
Get new builds, breakdowns, and useful AI updates.