0

Ollama Provider

Ollama Provider explains the local layer of MTPX with practical guidance for building inspectable, tool-using agents.

Ol
Ollama Provider
Chapter 037ProvidersLocalIndex
01Orientation

Ollama Provider belongs to the providers track. The page breaks the idea into responsibilities, implementation rules, failure modes, and the signals you should expose in a product UI.

Use this when

Use this when you need to understand how ollama provider affects a real MTPX agent before you wire it into an application.

  • What ollama provider owns in the runtime.
  • How it connects to planning, tool execution, events, providers, or storage.
  • What to log, test, and expose to users when this layer is active.
  • Common mistakes that make agent systems hard to inspect.
02 / syntax starter
from mtp import Agent
from mtp.providers import Groq

agent = Agent.MTPAgent(
    provider=Groq(model="llama-3.3-70b-versatile"),
    tools=tools,
)
03 / manual

Read the system

The complete source manual—syntax, examples, linked references, edge cases, and implementation notes.

Documentation index ↗

Ollama runs open-source models locally. No cloud API key required. Supports tool calling, streaming, and thinking/reasoning traces.

Install

bashpip install "mtpx[ollama]"

Or install the SDK directly:

bashpip install ollama

Setup

  1. Install Ollama from ollama.com
  2. Pull a model:
bash   ollama pull qwen3:1.7b
  1. Verify the server is running:
bash   ollama list

No API key is required for local usage. For secured remote hosts, set OLLAMA_API_KEY in your .env file.

Quick Start

pythonfrom mtp import Agent
from mtp.providers import Ollama

# No API key needed for local Ollama
provider = Ollama(model="qwen3:1.7b")
tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools)

reply = agent.run_loop("What is 25 * 4 + 10?")
print(reply)

Parameters

ParameterTypeDefaultDescription
modelstr"qwen3"Ollama model name (must be pulled first)
hoststr | NoneNoneOllama server URL (default: http://localhost:11434)
api_keystr | NoneNoneOptional API key for secured hosts (falls back to OLLAMA_API_KEY env var)
optionsdict | NoneNoneOllama-specific options (e.g., {"temperature": 0, "num_ctx": 4096})
formatdict | str | NoneNoneOutput format constraint (e.g., "json" or a JSON schema dict)
keep_alivefloat | str | NoneNoneHow long to keep model in memory (e.g., "5m", 300)
thinkbool | NoneNoneEnable thinking/reasoning traces (for models that support it)
clientAny | NoneNonePre-configured ollama.Client instance

Capabilities

CapabilityValue
Tool callingYes
Parallel tool callsYes
Input modalitiestext, image
StreamingYes (both stream_next_action and finalize_stream)
Usage metricsRich
Reasoning metadataYes (when think=True)
Native asyncNo (uses thread fallback)
  • qwen3:1.7b — Lightweight, fast, good tool calling
  • qwen3:4b — Better quality, still fast
  • qwen3:8b — Strong tool calling
  • llama3.2:3b — Good general purpose
  • mistral:7b — Solid alternative
  • deepseek-r1:1.5b — Reasoning model with thinking traces

Thinking/Reasoning

Enable thinking traces for models that support it:

pythonprovider = Ollama(
    model="qwen3:1.7b",
    think=True,
    options={"temperature": 0},
)

When think=True, the provider:

  • Captures thinking tokens from the model
  • Surfaces them in action_meta["reasoning"]
  • Reports supports_reasoning_metadata=True in capabilities

Streaming

Ollama supports both planning and finalization streaming:

pythonfor event in agent.run_loop_events(
    "Calculate 25 * 4",
    max_rounds=2,
    stream_final=True,
):
    print(event)

Full Example

pythonfrom mtp import Agent
from mtp.providers import Ollama

provider = Ollama(
    model="qwen3:1.7b",
    host="http://localhost:11434",
    think=True,
    options={"temperature": 0},
)

tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools, debug_mode=True)

reply = agent.run_loop(
    "Calculate (25 * 4) + 10",
    max_rounds=3,
)
print(reply)

Troubleshooting

  • Model not found: Run ollama pull <model> first.
  • Connection refused: Ensure Ollama is running (ollama serve).
  • No tool calls: Use a model that supports tool calling (Qwen 3, Llama 3.2+).
  • Slow first request: Model loading into memory takes time on first call.

Source

src/mtp/providers/ollama_provider.py

01

Read

Understand where Ollama Provider sits in the agent loop before adding abstractions.

02

Wire

Connect the smallest useful provider, registry, store, or event stream first.

03

Observe

Expose events, logs, results, and failure states while the runtime is still moving.

04

Harden

Add policy, tests, retries, and audit traces after the behavior is visible.

Next docOpenAI Provider