Agentic flow which provides ideal month to sow the crop as per mandi prices and weather forecast
# 🌾 Farmer Crop Advisor — LangGraph Agentic Workflow
An agentic workflow that helps Maharashtra farmers decide **which month to sow** a crop,
by combining:
- **Open-Meteo** historical climate normals + 16-day forecast (free, no key)
- **yfinance** commodity futures prices — global benchmarks (CBOT/ICE) that Indian mandi prices track
- **Azure OpenAI** (managed identity) for reasoning
- **Follow-up chat** on the same checkpointed thread, so the farmer can ask clarifying
questions without re-running the analysis or re-fetching APIs
State is persisted per-user-per-session via **LangGraph `SqliteSaver`** checkpoints,
keyed by `thread_id = user_id:session_id`.
## Architecture
```mermaid
flowchart TD
Start([START]) --> Router{has prior recommendation?}
Router -- no --> Intake[intake validate inputs geocode district ]
Router -- yes follow-up --> Chat[chat answer using cached context ]
Intake -->|error| EndErr([END])
Intake -->|ok| Weather[weather Open-Meteo history + forecast ]
Intake -->|ok| Price[price yfinance commodity futures ]
Weather --> Synthesize[synthesize Azure OpenAI recommendation + comparison table ]
Price --> Synthesize
Synthesize --> End1([END])
Chat --> End2([END])
subgraph Persistence
Checkpoint[(SqliteSaver data/checkpoints.sqlite thread_id = user:session)]
end
Synthesize -.snapshot.-> Checkpoint
Chat -.snapshot.-> Checkpoint
Checkpoint -.resume.-> Router
```
### Flow in plain words
1. **First run on a thread:** form input → `intake` → fan out to `weather` + `price`
in parallel → `synthesize` combines everything into a recommendation with a
comparison table of alternative sowing months.
2. **Every subsequent invocation on the same thread:** the entry router sees a
recommendation already exists, and routes the new `HumanMessage` straight to
`chat`. The chat node reuses the cached `farmer` / `weather_data` / `price_data`
/ `recommendation` from the checkpoint — **no API re-calls**, no re-analysis.
3. **`SqliteSaver`** writes a state snapsho …