Copy
Ask AI
"""
Local Reasoning
===============
Demonstrates this reasoning cookbook example.
"""
from agno.agent import Agent
from agno.models.ollama import Ollama
from rich.console import Console
# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
def run_example() -> None:
console = Console()
# Test task
task = "What is 23 × 47? Show your step-by-step reasoning."
console.rule("[bold cyan]Local Reasoning with Ollama[/bold cyan]")
# Test with QwQ (Alibaba's reasoning model)
console.print("\n[bold blue]QwQ:32B (Alibaba Reasoning Model)[/bold blue]")
console.print("[dim]Running locally with complete privacy...[/dim]\n")
try:
agent_qwq = Agent(
model=Ollama(id="qwq:32b"),
markdown=True,
)
agent_qwq.print_response(task, stream=True, show_full_reasoning=True)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
console.print(
"[yellow]Make sure Ollama is running and qwq:32b is installed:[/yellow]"
)
console.print(" ollama pull qwq:32b")
# Test with DeepSeek-R1:8B (smaller, faster)
console.print("\n[bold green]DeepSeek-R1:8B (Smaller, Faster)[/bold green]")
console.print("[dim]Running locally with complete privacy...[/dim]\n")
try:
agent_deepseek = Agent(
model=Ollama(id="deepseek-r1:8b"),
markdown=True,
)
agent_deepseek.print_response(task, stream=True, show_full_reasoning=True)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
console.print(
"[yellow]Make sure Ollama is running and deepseek-r1:8b is installed:[/yellow]"
)
console.print(" ollama pull deepseek-r1:8b")
# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
run_example()
Run the Example
Copy
Ask AI
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/10_reasoning/models/ollama
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
python local_reasoning.py