The AgroIA Telegram bot brings the full power of the RAG knowledge base into a chat interface optimised for use in the field. Instead of opening a browser dashboard, you can query lot scores, review NDVI history, and ask agronomic questions directly from your phone using large tap-friendly buttons. The bot runs in polling mode and connects to the same PostgreSQL database and Ollama models as the Streamlit dashboard, so every lot analysed by the pipeline is immediately available through chat.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sdarionicolas-boop/AgroIA-RAG/llms.txt
Use this file to discover all available pages before exploring further.
Setup
The bot requires a valid Telegram bot token set inconfig/.env. If you have not yet created a bot, use @BotFather on Telegram to generate a token, then add it to your environment file:
Starting the bot
- Bot only
- Full stack
Start only the Telegram bot in polling mode:
Available commands
The bot registers the following slash commands. All commands are also accessible through the persistent keyboard that appears after/start.
| Command | Description |
|---|---|
/start | Displays the welcome message and activates the persistent quick-action keyboard |
/ayuda | Shows a concise usage guide explaining the button layout and how to select a lot |
/lotes | Lists all lots currently in the database as an inline button menu for one-tap selection |
/lote | Shows which lot is currently active in your session |
/historial | Prints the year-by-year historical table (NDVI, heat stress, score) for the active lot |
| Button | Equivalent action |
|---|---|
| 📋 Mis Lotes | /lotes — show the inline lot selector |
| 🚜 Lote Activo | /lote — show the current session lot |
| 📊 Ver Historial | /historial — print the historical table |
| ❓ Ayuda | /ayuda — show the usage guide |
Selecting a lot
Tap 📋 Mis Lotes or send/lotes to display an inline button grid with all available lots. Tap a lot name to set it as your active lot for the session. The bot confirms the selection:
Viewing historical data
With a lot selected, tap 📊 Ver Historial or send/historial. The bot retrieves the lote_historial table records and formats them as a monospace table:
Natural language queries
Any message that is not a command or keyboard button is interpreted as a question for the RAG agent. The bot extracts the lot context from the message automatically using two strategies:- Explicit mention — if the message contains
lote NOMBREorlote: NOMBRE, the bot sets that lot as active for the query. - Session lot — if no lot is mentioned, the bot uses the lot set in your current session.
The bot shares the exact same RAG engine as the Streamlit dashboard — both call
src/rag/core.py::consultar_agente(). Responses are generated by gemma3:4b via Ollama and may take 15–70 seconds depending on your hardware. The bot sends a “Consultando…” message immediately so you know the request is being processed.Troubleshooting
Bot starts but does not respond to messages
Bot starts but does not respond to messages
Verify the token in
config/.env is correct and that you are messaging the right bot username. Also check logs/telegram_bot.log for authentication errors from the Telegram API.'No hay lotes cargados' when running /lotes
'No hay lotes cargados' when running /lotes
The database has no ingested lots. Run the pipeline on at least one shapefile (
python start.py --pipeline) or ingest data through the FastAPI endpoint before using the bot.RAG responses are very slow or time out
RAG responses are very slow or time out
Response time depends on the Ollama model.
gemma3:4b typically takes 14–71 seconds on CPU. Ensure Ollama is running (ollama serve) and that the gemma3:4b model is pulled (ollama pull gemma3:4b). The bot does not have a hard timeout, so it will eventually respond even on slow hardware.Lote from session is no longer found
Lote from session is no longer found
If a lot is deleted from the database while you have it as your active session lot, the bot detects the mismatch on the next query and clears the session automatically, prompting you to select a new lot.