LiteLLM Reasoning Agent Example

Stream DeepSeek V4 Flash reasoning content through the LiteLLM SDK.

Use reasoning models through LiteLLM. The reasoning_content from the model response is extracted and displayed.

DeepSeek announced retirement of deepseek-chat and deepseek-reasoner after July 24, 2026. The current instructions use deepseek/deepseek-v4-flash; the historical R1 label below does not describe this replacement. See the provider release notice.

reasoning_agent.py
"""
LiteLLM Reasoning Agent Example

This example demonstrates using reasoning models through LiteLLM.
The reasoning_content from the model response is extracted and displayed.

Supported reasoning models through LiteLLM:
- deepseek/deepseek-reasoner (DeepSeek R1)
"""

from agno.agent import Agent
from agno.models.litellm import LiteLLM

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

task = "9.11 and 9.9 -- which is bigger?"

# Using DeepSeek R1 through LiteLLM
agent = Agent(
    model=LiteLLM(
        id="deepseek/deepseek-reasoner",
    ),
    markdown=True,
)

agent.print_response(task, stream=True, stream_events=True, show_reasoning=True)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno litellm

Set your DeepSeek credentials

Use a DeepSeek API key with access to V4 Flash. The LiteLLM SDK calls the provider directly. An existing LITELLM_API_KEY overrides provider-specific credentials, so clear it for this example.

unset LITELLM_API_KEY
export DEEPSEEK_API_KEY="your_provider_api_key_here"

Use the current reasoning model

Replace id="deepseek/deepseek-reasoner" with id="deepseek/deepseek-v4-flash". V4 uses thinking mode by default; Agno reads the provider's reasoning_content and the existing display options show it.

Run the example

Save the code above as reasoning_agent.py, then run:

python reasoning_agent.py

Full source: cookbook/90_models/litellm/reasoning_agent.py