---
title: "Running Local Models in ADK with Ollama and LiteLLM"
date: "2026-11-25T08:40:00+07:00"
description: "Pointing ADK agents at Ollama-hosted open models — the ollama_chat provider requirement, OLLAMA_API_BASE, model choice, and what local inference changes about your agent."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/adk-ollama-local-models-litellm-integration.jpg"
alt: "Laptop running Ollama connected to an ADK agent with local model weights"
tags: ['google-adk', 'ollama', 'local-models', 'litellm', 'privacy', 'python']
---

There are three good reasons to run an agent's model locally: data never leaves the machine, cost per token drops to hardware cost, and no provider rate limit can throttle you. Ollama is the most popular way to do it — a single binary that pulls and serves open weights with an OpenAI-compatible API. ADK connects to it through the same LiteLLM layer used for Claude and OpenAI, with a few specifics that trip up everyone the first time.

This post gets an ADK agent running on Ollama, then covers what *actually changes* in your agent when the model lives on your own GPU.

## The two requirements people miss

ADK's Ollama integration has two non-obvious rules:

1. **Use the `ollama_chat` provider.** LiteLLM offers `ollama/` (completion-style) and `ollama_chat/` (chat-style) prefixes. Agent workloads — multi-turn messages, tool calls — need the chat variant. `ollama/model` can appear to work until the first tool call breaks.
2. **Set `OLLAMA_API_BASE`.** Ollama listens on `http://localhost:11434` by default; LiteLLM reads the endpoint from this environment variable (or you pass `api_base` explicitly).

```bash
export OLLAMA_API_BASE=http://localhost:11434
# for a server on the LAN:
# export OLLAMA_API_BASE=http://gpu-box.internal:11434
```

## Getting a model and verifying it

```bash
ollama pull llama3.2          # general assistant, small
ollama pull qwen2.5-coder:14b # code-oriented
ollama list                   # what's installed
```

Sanity-check the endpoint before involving ADK:

```bash
curl http://localhost:11434/api/tags            # installed models
curl http://localhost:11434/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"llama3.2","messages":[{"role":"user","content":"hi"}]}'
```

If that second call works, the remaining problems are in your agent — not connectivity.

## Connecting the ADK agent

```python
from google.adk.agents import Agent
from google.adk.models.litellm import LiteLlm

local_agent = Agent(
    model=LiteLlm(
        model="ollama_chat/llama3.2",
        api_base="http://localhost:11434",   # explicit beats implicit
    ),
    name="local_assistant",
    instruction=ASSISTANT_INSTRUCTION,
    tools=[lookup_docs, summarize],
    output_schema=Answer,                    # parse defensively — see below
)
```

Notes on the wiring:

- **`ollama_chat/` prefix is mandatory** for chat/tool-calling behavior.
- **`api_base` inline** removes a class of "works locally, fails in the container" bugs — the env var travels inconsistently across deployment environments.
- **Tools must be declared in a format your local model supports.** Tool calling quality varies sharply across open models; a model that ignores tool schemas will silently degrade your agent.

## What actually changes when the model is local

### 1. Model choice matters more

Ollama hosts many models; they are not interchangeable. For ADK agents, prioritize:

- **Tool-calling support** — test it before committing (below).
- **Context window** — small models with 4–8k windows overflow fast when [tool results and history accumulate](/blog/adk-max-output-tokens-truncation-strategies).
- **Instruction following** — weaker than frontier models; expect to tighten prompts, add examples, and narrow task scope.

### 2. Structured output becomes prompt-enforced

Gemini constrains responses at the API level; Ollama models generally rely on the prompt plus parsing. Keep the [Pydantic output_schema](/blog/adk-pydantic-response-schema-structured-outputs) as documentation and a validation layer, but wrap parsing defensively and treat failures as retriable — the pattern from [graceful fallbacks](/blog/adk-agent-exceptions-graceful-fallback).

### 3. Throughput is a hardware problem now

Provider rate limits vanish and are replaced by your GPU:

- **Concurrency:** one 14B model saturates a single consumer GPU at a handful of concurrent streams. Bound agent concurrency to match (`ADK_TRIGGER_MAX_CONCURRENT` for triggers; your queue depth elsewhere).
- **Latency profile:** first token arrives after weights load and the prompt processes — long prompts on big models mean multi-second TTFT. Warm the model at startup for interactive surfaces.
- **Batching:** Ollama batches requests under load; individual latency rises as queue depth grows. Size your [queue and worker pool](/blog/adk-headless-background-agents-async-queues) to the hardware, not to cloud habits.

### 4. Ops replaces subscriptions

- **Updates are deliberate:** `ollama pull` new weights, run your eval suite, then switch — model changes are deployments now.
- **Observability shifts:** provider dashboards don't exist; log tokens/sec, queue depth, and Ollama's own metrics.
- **Fallbacks change shape:** your failover chain might be local → cloud (see [LiteLLM third-party models](/blog/adk-litellm-third-party-models-claude-openai-mistral)) rather than cloud → cloud.

## A realistic hybrid

Most teams shouldn't go 100% local. The stable pattern: **local for what must stay local or is high-volume and simple; cloud for what needs depth.**

```python
def model_for(task: str, data_class: str) -> LiteLlm:
    if data_class == "restricted":            # never leaves the machine
        return LiteLlm(model="ollama_chat/llama3.2",
                       api_base="http://localhost:11434")
    if task in {"classify", "extract", "redact"}:   # simple + high volume
        return LiteLlm(model="ollama_chat/qwen2.5-coder:14b",
                       api_base="http://localhost:11434")
    return LiteLlm(model="anthropic/claude-sonnet-4")   # depth on demand
```

Routing policy and its evaluation are covered in [dynamic model routing](/blog/adk-dynamic-model-routing-task-complexity); the placement above follows the same complexity-and-risk logic.

## Checklist before shipping

- [ ] `ollama_chat/` prefix confirmed — tool calls actually fire
- [ ] `OLLAMA_API_BASE` / `api_base` set explicitly in every environment
- [ ] Tool-calling tested end-to-end with your real tool schemas
- [ ] Context window sized for your longest realistic conversation
- [ ] Structured output parsing wrapped with validation + retry
- [ ] Concurrency bounded to GPU reality; queue in front for bursts
- [ ] Eval suite run against the exact model tag you're deploying
- [ ] Failover path to cloud defined and tested for when the box dies

## Where to go next

If local inference needs to scale beyond one box — higher throughput, OpenAI-compatible endpoints for multiple services — the next step is [self-hosted inference with vLLM](/blog/adk-vllm-endpoints-low-latency-self-hosted-inference). For the cloud-side half of a hybrid setup, see [LiteLLM third-party models](/blog/adk-litellm-third-party-models-claude-openai-mistral).

## References

- [Ollama for ADK agents](https://adk.dev/agents/models/ollama/)
- [LiteLLM connector](https://adk.dev/agents/models/litellm/)
- [Ollama](https://ollama.com/)
- [LiteLLM documentation](https://docs.litellm.ai/)
- [google/adk-python](https://github.com/google/adk-python)
