Ollama Reasoning Model DeepSeek

Pair a local Llama 3.2 agent with DeepSeek-R1 on Ollama as its reasoning model.

reasoning_model_deepseek.py
"""
Reasoning Model Deepseek
========================

Demonstrates this reasoning cookbook example.
"""

from agno.agent import Agent
from agno.models.ollama.chat import Ollama


# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
def run_example() -> None:
    agent = Agent(
        model=Ollama(id="llama3.2:latest"),
        reasoning_model=Ollama(id="deepseek-r1:14b", options={"num_predict": 4096}),
    )
    agent.print_response(
        "Solve the trolley problem. Evaluate multiple ethical frameworks. "
        "Include an ASCII diagram of your solution.",
        stream=True,
    )


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    run_example()

Local routing and visible thinking

Add host="http://localhost:11434", api_key=None to every Ollama(...) constructor in the saved program, and clear OLLAMA_API_KEY using the setup step below in both the model-pull and Python terminals. These settings select the local server explicitly; a cloud key otherwise changes Agno's default host.

The current adapter does not copy Ollama's separate message.thinking field into Agno's reasoning output. A separate Ollama reasoning stage can therefore pass its answer text as a fallback. The model may still think internally even when Agno displays no reasoning content. Local model inference describes where the model call runs; it does not by itself disable Agno telemetry or prove that every part of an application stays offline. See telemetry.

Run the Example

Set up your virtual environment

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

Install dependencies

uv pip install -U agno ollama

Select the local Ollama server

In the shell used for the pull commands and Python example, clear a previous cloud key and point native clients and embeddings at your local server:

unset OLLAMA_API_KEY
export OLLAMA_HOST="http://localhost:11434"

Without this reset, OLLAMA_API_KEY makes Agno's default Ollama model route to https://ollama.com even when OLLAMA_HOST points locally. Keep a local Ollama server running for the following steps.

Prepare Ollama

Install and start Ollama, then pull the models used by this example:

ollama pull deepseek-r1:14b
ollama pull llama3.2:latest

Run the example

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

python reasoning_model_deepseek.py

Full source: cookbook/10_reasoning/models/ollama/reasoning_model_deepseek.py