Skip to content
rgallegocodePublic

About

Bot de Telegram inspirado en Jose Luis Cava para novedades diarias de la bolsa.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Cava Bot logo

📈 Cava Agent — AI Financial Analyst Agent

CI Daily bulletin

Python smolagents Gradio Groq GitHub Actions

🚀 Try the live demo · 🇪🇸 Leer en español

Cava Agent chat demo: the agent calls its market tools and answers whether the S&P 500 is in a bull or bear market

The agent plans, calls its tools (Yahoo Finance, SMA50/SMA200 trend, news) and answers with real data.


🇬🇧 English

Cava Agent is an autonomous AI agent that works as a daily financial analyst, with the blunt style of the Spanish economist José Luis Cava (and his famous "las maldades" of the market).

It was built as the Unit 1 project of the Hugging Face Agents Course, starting from the course's First_agent_template and evolving my previous project, a fixed LLM pipeline, into a real agent.

From pipeline to agent

v1 – Cava Bot (legacy/cava_bot.py) v2 – Cava Agent
Control flow Hard-coded: fetch news → fetch prices → 1 prompt The LLM plans and decides which tools to call (ReAct loop: Thought → Code → Observation)
Interaction Only a daily Telegram message Interactive chat (Gradio) and the daily Telegram bulletin
Weather Generated by the LLM (unverified) Real data from Open-Meteo
Bull / Bear LLM opinion Computed: price vs. SMA50/SMA200, golden/death cross, drawdown
Assets 3 fixed tickers Any Yahoo Finance ticker, any period
LLM Gemini only Pluggable via LiteLLM: Qwen3.8 27B on Groq (default), Gemini or Qwen2.5-Coder-32B (HF Inference)

Language by design

The codebase, tests, tooling and docs are in English. The persona is deliberately Spanish: the agent replies in the user's language (ask in English, get English), while the daily Telegram bulletin is published in Spanish for its Spanish-speaking audience, keeping Cava's trademark expressions such as "las maldades".

Architecture

flowchart LR
    U[User · Gradio chat] --> A
    C[GitHub Actions cron 07:00 UTC] -->|daily task| A
    subgraph A[smolagents CodeAgent]
        direction TB
        T[Thought] --> K[Python code] --> O[Observation] --> T
    end
    A --> M{{LLM: Qwen3.8 27B on Groq / Gemini / Qwen2.5}}
    A --> T1[get_market_snapshot / get_asset_quote<br/>Yahoo Finance]
    A --> T2[assess_market_trend<br/>SMA50 · SMA200]
    A --> T3[get_financial_news<br/>NewsAPI]
    A --> T4[get_weather<br/>Open-Meteo]
    A --> T5[web_search / visit_webpage<br/>DuckDuckGo]
    A -->|final_answer| R[Answer in chat]
    A -->|final_answer| TG[Telegram bulletin]
Loading

Tools

Tool What it does Source
get_market_snapshot Close, daily and 1-week change of MSCI World (URTH), Vanguard EM (VWO) and Bitcoin Yahoo Finance
get_asset_quote Close, daily and period change for any ticker (^GSPC, ^IBEX, AAPL, EURUSD=X…) Yahoo Finance
assess_market_trend Bull / Bear / sideways classification from SMA50/SMA200 and 52-week drawdown Yahoo Finance
get_financial_news Most popular headlines of the last 24h for a topic NewsAPI
get_weather Current weather and today's min/max for a city Open-Meteo
get_current_time_in_timezone Local time in any timezone pytz
web_search / visit_webpage Web search and page reading as a fallback DuckDuckGo

The Telegram sender is not exposed as a tool: the chat UI is meant to be shared and anyone with access to the chat could use it to send messages.

Project structure

app.py               # entry point: build_agent() + Gradio chat UI
agent.py             # model selection, tools and prompts → CodeAgent
daily_bulletin.py    # daily task for the cron job → Telegram (DRY_RUN=1 prints it)
prompts.yaml         # smolagents prompts + Cava persona
tools/               # custom tools
telegram_client.py   # Telegram Bot API client
tests/               # pytest suite (tools, agent, rate limiter, bulletin) — no network or API keys needed
scripts/             # deploy_space.py: publishes the demo to Hugging Face Spaces
legacy/cava_bot.py   # v1 (pipeline version)

Run locally

git clone https://github.com/rgallegocode/cava-bot.git
cd cava-bot
pip install -r requirements-dev.txt gradio

cp .env.example .env         # fill in your keys (.env is git-ignored)

python app.py                          # chat UI
DRY_RUN=1 python daily_bulletin.py     # print today's bulletin
pytest && ruff check .                 # tests + lint
Variable Used by Description
MODEL_PROVIDER all groq (default), gemini or hf
GROQ_API_KEY groq model console.groq.com key
HF_TOKEN hf model Hugging Face token (only for MODEL_PROVIDER=hf)
GEMINI_API_KEY gemini model Google AI Studio key (only for MODEL_PROVIDER=gemini)
NEWS_API_KEY get_financial_news newsapi.org key
TELEGRAM_TOKEN, CHAT_ID daily_bulletin.py Telegram bot and chat

CI/CD (GitHub Actions)

flowchart LR
    P[git push] --> CI[CI: ruff + pytest<br/>Python 3.10 · 3.11 · 3.12]
    CI -->|green| D[Deploy: Hugging Face Space<br/>live demo]
    CR[cron 07:00 UTC] --> B[Daily bulletin → Telegram]
Loading
  • .github/workflows/ci.yml: lint and the test suite on every push and pull request, on three Python versions.
  • .github/workflows/deploy_space.yml: when CI passes on main, scripts/deploy_space.py publishes the chat to the Hugging Face Space, creating it and setting its secrets if needed.
  • .github/workflows/main.yml: every day at 07:00 UTC the agent researches the market and posts the bulletin to Telegram: a market report from Monday to Friday, and on weekends (markets closed) a preview of the news that can move Monday's open. API keys are stored as GitHub Secrets; run it manually with dry run to see the bulletin in the job log without sending it.

Disclaimer: Cava Agent output is for informational purposes only and does not constitute financial advice.

📸 Cava Agent in action

Chat: every reasoning step is visible Daily bulletin posted to Telegram
Expanded agent steps showing the Python code and tool calls behind an answer Daily Telegram bulletin in Spanish: weather, 24h news summary, market 'maldades' and bull/bear forecast
Expand a step to see the code the agent wrote and what each tool returned. Generated every morning by the same agent from a GitHub Actions cron: weather, 24h news, Cava's "maldades" and a bull/bear call computed from SMA50/SMA200.

🇪🇸 Español

Cava Agent es un agente de IA autónomo que actúa como analista financiero diario con el estilo directo del economista José Luis Cava y sus famosas "maldades" del mercado.

Es el proyecto de la Unidad 1 del Hugging Face Agents Course: parte del First_agent_template del curso y convierte mi proyecto anterior, un pipeline fijo con un LLM, en un agente de verdad.

🚀 Prueba la demo en directo · 📸 Capturas del chat y del boletín de Telegram

Qué cambia respecto a la v1

  • El LLM decide: un CodeAgent de smolagents razona en ciclos Pensamiento → Código → Observación y elige qué herramientas usar según la pregunta.
  • Chat interactivo (Gradio), además del boletín diario en Telegram, que ahora también genera el agente.
  • Cero datos inventados: el tiempo sale de Open-Meteo y el Bull/Bear se calcula con las medias móviles de 50 y 200 sesiones, ya no es una opinión del LLM.
  • Cualquier activo: cualquier ticker de Yahoo Finance y cualquier periodo.
  • Calidad: tests automáticos con pytest y CI en GitHub Actions; cada push que pasa los tests se despliega solo en la demo.
  • LLM intercambiable: Qwen3.8 27B en Groq (por defecto), Gemini o Qwen2.5-Coder-32B (HF Inference) con la variable MODEL_PROVIDER.

Preguntas de ejemplo

  • "Dame el resumen del mercado de hoy y las maldades de la jornada"
  • "¿Estamos en bull o bear market con el S&P 500?"
  • "¿Cómo ha ido Bitcoin el último mes y qué noticias lo explican?"

La arquitectura, las herramientas y las instrucciones de instalación están en la sección en inglés.

Aviso legal: el contenido generado por Cava Agent es informativo y no constituye asesoramiento financiero.

About

Bot de Telegram inspirado en Jose Luis Cava para novedades diarias de la bolsa.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages