Build a Local AI Agent with Google ADK and Ollama

What you will build

Google's Agent Development Kit (ADK) is the open-source framework Google released in April 2025 for building tool-using agents. It ships with a dev UI, session handling, and multi-agent workflows, and it runs in Python, TypeScript, Go, Java, and Kotlin. Most examples point it at Gemini. This guide does something else: it points ADK at a model running on your own machine through Ollama, so the agent costs nothing per token and your data stays home.

By the end you will have a notes agent: ask it a question, and it searches a folder of local Markdown notes before answering. The same pattern works for any tool (a calendar, a database, a shell command) because ADK treats tools as plain Python functions.

Source: Google Agent Development Kit branding.

Prerequisites

  • Python 3.11 or later (google-adk 2.14.1 requires it)
  • Ollama installed and running
  • About 6 GB of free disk space for the model, and 16 GB of RAM if you want comfortable speeds

Step 1: Pull a model that can call tools

Not every local model can use tools, and an agent without tool support will either ignore your functions or loop forever trying to call them. The ADK docs suggest checking a model's capabilities first:

ollama pull qwen3:8b
ollama show qwen3:8b

Look for tools under Capabilities in the output. Qwen3 is a solid pick here: Microsoft's own Agent Framework docs name qwen3:4b as a reliable choice for tool calling on Ollama, and the 8B version keeps that ability with better reasoning. If you prefer a smaller download, qwen3:4b works too. Avoid Gemma 3 for this setup — it has no native function calling, and ADK needs a workaround mixin to make it behave.

Step 2: Install ADK and scaffold the project

Create a virtual environment, install ADK, and let its CLI scaffold the project:

python3 -m venv .venv
source .venv/bin/activate
pip install google-adk
adk create notes_agent

That last command creates a folder with three files: agent.py for your agent code, __init__.py, and a .env for API keys. Since the model runs locally, you can leave the .env file empty — there is no Gemini key to fill in.

Step 3: Point ADK at Ollama

ADK reaches non-Gemini models through LiteLLM, and its Ollama page shows the exact pattern. Open notes_agent/agent.py and replace the generated agent with this:

from google.adk.agents.llm_agent import Agent
from google.adk.models.lite_llm import LiteLlm

def search_notes(query: str) -> dict:
    """Searches local Markdown notes for a keyword and returns matching lines."""
    import pathlib
    hits = []
    for path in pathlib.Path("notes").glob("*.md"):
        for line in path.read_text(encoding="utf-8", errors="ignore").splitlines():
            if query.lower() in line.lower():
                hits.append(f"{path.name}: {line.strip()}")
    return {"status": "success", "matches": hits[:10]}

root_agent = Agent(
    model=LiteLlm(model="ollama_chat/qwen3:8b"),
    name="notes_agent",
    description="Answers questions using your local notes.",
    instruction=(
        "You are a research assistant. Answer from the user's local notes "
        "using the search_notes tool whenever a question could relate to them. "
        "If the notes have nothing relevant, say so instead of guessing."
    ),
    tools=[search_notes],
)

Two details here are easy to get wrong. First, the model string must start with ollama_chat, not ollama. The ADK docs warn that the plain ollama provider can cause infinite tool-call loops and dropped context. Second, ADK relies on an environment variable for the Ollama server address, so set it before you run anything:

export OLLAMA_API_BASE="http://localhost:11434"

Step 4: Add some notes to search

The tool reads *.md files from a notes folder next to your project, so create one with a couple of real entries:

mkdir notes
printf '# Project ideas\n\n- Build a plant-watering reminder with an ESP32.\n- Q3 budget review is on Friday.\n' > notes/ideas.md

Keep the notes real. A tool that only searches toy files teaches you nothing about whether the agent actually grounds its answers.

Step 5: Run it

ADK offers two ways to talk to your agent. The terminal runner is fastest for a smoke test:

adk run notes_agent

For a proper look at what the agent is doing, use the web UI instead. Run it from the parent directory that contains your notes_agent/ folder:

adk web --port 8000

Open http://localhost:8000, pick notes_agent in the top-left dropdown, and ask something your notes can answer — for example, "What did I plan to build with an ESP32?" The UI shows each tool call as it happens, so you can watch the agent search first and answer second. If it answers from the notes, the wiring works. The web UI is for development and debugging only; Google's docs say plainly not to use it in production.

Source: Google ADK documentation (adk.dev).


Step 6 (optional): Add a second agent

One agent with one tool is a start, but ADK's real strength is handing work between agents. Add a writer agent and list it as a sub-agent of the root:

writer_agent = Agent(
    model=LiteLlm(model="ollama_chat/qwen3:8b"),
    name="writer_agent",
    description="Turns research notes into a short summary.",
    instruction="You write short, plain summaries. No filler, no preamble.",
)

root_agent = Agent(
    model=LiteLlm(model="ollama_chat/qwen3:8b"),
    name="notes_agent",
    description="Researches local notes and hands findings to the writer.",
    instruction=(
        "Research the question with search_notes, then hand the findings "
        "to writer_agent for a short summary."
    ),
    tools=[search_notes],
    sub_agents=[writer_agent],
)

When the root agent decides the writer should take over, ADK transfers control through a typed transfer_to_agent call. The same structure scales to the built-in workflow agents, SequentialAgent, ParallelAgent, and LoopAgent, when a job needs fixed stages instead of model-decided routing.

Troubleshooting

  • The agent calls tools in a loop. Check the model string: it must be ollama_chat/qwen3:8b, not ollama/qwen3:8b.
  • "Connection refused" on port 11434. Ollama is not running, or OLLAMA_API_BASE points somewhere else. Run ollama list to confirm the server is up.
  • The agent ignores the tool entirely. Run ollama show qwen3:8b and confirm tools appears under Capabilities. If it does not, pick a different model.
  • Answers are slow or rambling. Small local models reason worse than hosted ones. Tighten the instruction, keep tools narrow, and prefer the 8B model over the 4B one for agentic work.

Check LiteLLM before you install

ADK depends on LiteLLM to reach Ollama, so a compromised LiteLLM is a compromised agent. On 21 October 2026, attackers hijacked LiteLLM's release pipeline and published version 1.107.0 to PyPI with credential-stealing malware; it sat there for under two hours before it was pulled. NewsCarpenter covered the incident in LiteLLM Supply Chain Attack: 1.107.0 Steals API Keys. Before you trust your install, run pip show litellm and confirm the version is not 1.107.0 — 1.106.2 was the last release confirmed clean at the time, and current releases such as 1.109.1 are clean. Pinning exact versions is the habit that keeps a hijacked release out of your environment.

Where this fits

If you have already built agents with other frameworks, ADK will feel familiar: the tool-as-function pattern is the same idea as in our smolagents and Ollama tutorial and our Pydantic AI and Ollama tutorial. What ADK adds is Google's production-minded scaffolding: sessions, evaluation, and a path to Vertex AI Agent Engine when a local agent outgrows your laptop. Start local, keep the tools narrow, and swap the model string when you are ready for a hosted brain — the agent code does not change. If you are new to running models locally at all, start with our 20-minute Ollama guide first.

Comments

Popular posts from this blog

Open-Source AI Weekly: Bonsai, GigaChat 4 Lead

Claude Claims Proof of Riemann Hypothesis After 167 Years

How to Build an AI Agent with LangGraph in 30 Minutes