0

Ollama Cookbook

Install Ollama and pull a model:

Example · مثال

Content

Ollama Cookbook

Note: Fork and clone this repository if needed

Setup

1. Install Ollama

Install Ollama and pull a model:

ollama pull llama3.1:8b

2. Create and activate a virtual environment

python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate

3. Install libraries

pip install -U ollama agno

4. (Optional) Export your OLLAMA_API_KEY for Ollama Cloud

export OLLAMA_API_KEY=***

---

Chat API Examples

The chat/ folder contains examples using the native Ollama Chat API.

Basic Usage

python cookbook/90_models/ollama/chat/basic.py

Tools and Structured Output

# Tool use
python cookbook/90_models/ollama/chat/tool_use.py

# Structured output
python cookbook/90_models/ollama/chat/structured_output.py

Storage and Memory

# Database storage
python cookbook/90_models/ollama/chat/db.py

# Knowledge base
python cookbook/90_models/ollama/chat/knowledge.py

# Memory
python cookbook/90_models/ollama/chat/memory.py

Vision

# Pull vision model first
ollama pull llama3.2-vision

python cookbook/90_models/ollama/chat/image_agent.py

Model Demos

python cookbook/90_models/ollama/chat/demo_deepseek_r1.py
python cookbook/90_models/ollama/chat/demo_qwen.py
python cookbook/90_models/ollama/chat/demo_phi4.py

---

Responses API Examples

The responses/ folder contains examples using the OpenAI-compatible Responses API (requires Ollama v0.13.3+).

Basic Usage

# Basic
python cookbook/90_models/ollama/responses/basic.py

Tools and Structured Output

# Tool use
python cookbook/90_models/ollama/responses/tool_use.py

# Structured output
python cookbook/90_models/ollama/responses/structured_output.py

Source and license

Source
Agno
Original
agno-agi/agno/cookbook/90_models/ollama
License
Apache-2.0