Skip to main content

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.

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.

Setup

The bot requires a valid Telegram bot token set in config/.env. If you have not yet created a bot, use @BotFather on Telegram to generate a token, then add it to your environment file:
# config/.env
TELEGRAM_TOKEN=your_token_from_botfather
The bot will not start if TELEGRAM_TOKEN is missing or left at the placeholder value TU_TOKEN_AQUI. The launcher checks this during the prerequisite verification step and prints a warning.

Starting the bot

Start only the Telegram bot in polling mode:
python start.py --bot
When the bot is running you will see the following in the console:
🤖  Telegram  (bot)             PID 12345  log → logs/telegram_bot.log
The bot is now reachable at your bot’s Telegram username.

Available commands

The bot registers the following slash commands. All commands are also accessible through the persistent keyboard that appears after /start.
CommandDescription
/startDisplays the welcome message and activates the persistent quick-action keyboard
/ayudaShows a concise usage guide explaining the button layout and how to select a lot
/lotesLists all lots currently in the database as an inline button menu for one-tap selection
/loteShows which lot is currently active in your session
/historialPrints the year-by-year historical table (NDVI, heat stress, score) for the active lot
In addition to commands, the four keyboard buttons map to actions directly:
ButtonEquivalent 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:
✅ Lote activo: TAYPE_LOTE_001

Ahora podés:
• Ver el historial con el botón de abajo.
• Escribirme una pregunta técnica.
The active lot persists for the duration of your session. You can switch lots at any time by opening the lot list again.

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:
📊 Historial: TAYPE_LOTE_001

AÑO  NDVI  ESTRÉS  SCORE
2020  0.61   312.4h   71/100
2021  0.58   298.1h   68/100
2022  0.66   341.7h   79/100
2023  0.54   275.9h   61/100
2024  0.69   356.2h   82/100

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:
  1. Explicit mention — if the message contains lote NOMBRE or lote: NOMBRE, the bot sets that lot as active for the query.
  2. Session lot — if no lot is mentioned, the bot uses the lot set in your current session.
If neither strategy resolves a lot, the bot lists the available lots and asks you to select one first. Example interactions:
You:  ¿Cómo viene el NDVI histórico?
Bot:  ⏳ Consultando base de conocimientos...
      El lote TAYPE_LOTE_001 muestra una tendencia ascendente en NDVI
      desde 2020, con el valor más alto registrado en 2024 (0.69)...
You:  ¿Cuál fue el año con más estrés térmico en lote INTA_PIVOTE_001?
Bot:  ⏳ Consultando base de conocimientos...
      El año con mayor estrés térmico para INTA_PIVOTE_001 fue 2024,
      con 356 horas de calor acumuladas...
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

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.
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.
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.
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.

Build docs developers (and LLMs) love