Show Agent Reasoning on WhatsApp
Run an OpenAI finance agent with ReasoningTools and YFinance on WhatsApp with visible reasoning.
Enable the WhatsApp interface's show_reasoning option. The interface sends available reasoning content as a separate formatted message before sending the Agent's final response.
"""
Show Agent Reasoning on WhatsApp
================================
Enable the WhatsApp interface's show_reasoning option. The interface sends
available reasoning content as a separate formatted message before sending the
Agent's final response.
Prerequisites: OPENAI_API_KEY and the four WHATSAPP_* credentials in README.md
Run: .venvs/demo/bin/python cookbook/05_agent_os/19_whatsapp/reasoning_agent.py
Try: Ask for a concise comparison of two public companies
"""
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS
from agno.os.interfaces.whatsapp import Whatsapp
from agno.tools.reasoning import ReasoningTools
from agno.tools.yfinance import YFinanceTools
# ---------------------------------------------------------------------------
# Create the Reasoning WhatsApp AgentOS
# ---------------------------------------------------------------------------
db = SqliteDb(
id="whatsapp-reasoning-db",
db_file="tmp/whatsapp_reasoning.db",
)
finance_agent = Agent(
id="whatsapp-reasoning-agent",
name="WhatsApp Reasoning Agent",
model=OpenAIResponses(id="gpt-5.5"),
db=db,
tools=[
ReasoningTools(add_instructions=True),
YFinanceTools(),
],
instructions=[
"Compare the requested companies using current financial data.",
"Keep reasoning focused and the final answer concise for WhatsApp.",
],
add_datetime_to_context=True,
)
agent_os = AgentOS(
id="whatsapp-reasoning-os",
description="An AgentOS that exposes reasoning through WhatsApp messages.",
agents=[finance_agent],
interfaces=[
Whatsapp(
agent=finance_agent,
show_reasoning=True,
)
],
)
app = agent_os.get_app()
# ---------------------------------------------------------------------------
# Run the Reasoning WhatsApp Server
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent_os.serve(app=app)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[os]" openai yfinanceExport environment variables
export OPENAI_API_KEY="your_openai_api_key_here"
export WHATSAPP_ACCESS_TOKEN="your_whatsapp_access_token_here"
export WHATSAPP_APP_SECRET="your_whatsapp_app_secret_here"
export WHATSAPP_PHONE_NUMBER_ID="your_whatsapp_phone_number_id_here"
export WHATSAPP_VERIFY_TOKEN="your_whatsapp_verify_token_here"Expose the server
Install ngrok and start a tunnel in another terminal. Keep it running and copy its public HTTPS URL:
ngrok http 7777Run the example
Save the code above as reasoning_agent.py, then run:
python reasoning_agent.pyRegister the webhook
Keep AgentOS and ngrok running. Follow WhatsApp setup: set the callback to https://<your-ngrok-url>/whatsapp/webhook, use the same WHATSAPP_VERIFY_TOKEN, and subscribe to the messages field. Add and verify a test recipient when using Meta's test phone number, then message the bot.
Full source: cookbook/05_agent_os/19_whatsapp/reasoning_agent.py