---
title: "Your First ADK Agent: Building a Minimal Working Agent in Under 20 Lines"
date: "2026-11-24T04:15:00+07:00"
description: "Build a working Google ADK agent in under 20 lines: one root_agent definition, a Gemini model, and two commands to run it from CLI or dev UI."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/your-first-adk-agent-minimal.jpg"
alt: "Minimal ADK agent source code next to a terminal chat session"
tags: ['google-adk', 'ai-agent', 'python', 'tutorial', 'quickstart']
---

The fastest way to understand ADK is to make the smallest possible thing work, then look at what the framework quietly does around it. In this tutorial we build a genuinely minimal agent — one module-level variable, no tools, no callbacks — and run it with the two commands you will use every day.

This is deliberately the *minimal* companion to `your-first-adk-agent-harness.md`, which builds a fuller customer-support harness with custom function tools, session callbacks and explicit use of the `Runner`. Here we touch none of that. The goal is a running agent you can read in a single glance.

## The entire core: seven lines

Create a project and open `agent.py`:

```bash
adk create my_agent
```

Replace the file contents with this — the whole agent, under 20 lines:

```python
from google.adk import Agent

root_agent = Agent(
    name="hello_adk",
    model="gemini-flash-latest",
    instruction="You are a concise assistant. Greet the user and answer briefly.",
)
```

That is the complete program. There is no `main()`, no loop, no server: `adk run` and `adk web` discover `root_agent` by name and drive it for you.

## What each argument does

| Argument | Role | Rule of thumb |
|---|---|---|
| `name` | Identity used in events, logs and the dev UI | Lowercase, stable, unique within the project |
| `model` | The Gemini model string | `gemini-flash-latest` is a good default; swap for any supported model |
| `instruction` | The system prompt for this agent | Write it like a runbook, not a conversation |
| `description` | Optional; tells *other agents* when to delegate to this one | Only needed once agents start handing off to each other |
| `tools` | Optional list of functions/agents | Omitted entirely in the minimal version |

The import in the quickstart, `from google.adk.agents.llm_agent import Agent`, and the README's shorter `from google.adk import Agent` refer to the same class: `Agent` is an alias for `LlmAgent`, the language-model-powered agent type.

## Run it in under a minute

Put your Gemini API key in `my_agent/.env`, then from the **parent directory**:

```bash
echo 'GOOGLE_API_KEY="YOUR_API_KEY"' > my_agent/.env
adk run my_agent          # chat in the terminal
adk web --port 8000       # or open the browser dev UI
```

`adk run` starts an interactive loop: you type, the `Runner` appends your message as an event, the agent answers, and the cycle repeats with full history from the session. `adk web` gives you the same agent with a graphical interface for inspecting each step — remember it is a development tool, not a production server.

The project you are running looks like this:

```text
my_agent/
    agent.py      # your 7-line agent (root_agent)
    .env          # GOOGLE_API_KEY="..."
    __init__.py   # makes the folder importable
```

A CLI session is just as small (illustrative transcript):

```text
$ adk run my_agent
Hello! What can I help you with today?

> keep it short
 Sure — ask away.
```

## What you get for free

Even with nothing but the `Agent(...)` call, ADK gives you:

- **Conversation history** — every turn is appended to a `Session` and replayed on the next call.
- **Streaming** — responses arrive as `partial=True` event chunks, not one monolithic string.
- **An inspectable event log** — `adk web` shows each event, author and state change for debugging.
- **Model portability** — switching `model="gemini-flash-latest"` to another supported model is a one-line change.
- **An evaluation entry point** — the same agent folder can be scored later with `adk eval`.

## What happens when you press Enter

Even with no explicit runtime code, ADK runs its documented event loop: the `Runner` receives your query, wraps it as an event with `author="user"`, calls `root_agent.run_async(...)`, receives the agent's yielded response event, persists it through a `SessionService`, and yields it back to your terminal. Your seven lines define *what* the agent is; the framework supplies *how* a turn executes — sessions, history, streaming and state commit come for free.

## What we deliberately left out

No tools, no callbacks, no explicit `Runner`, no session service selection. That is the point: everything above is optional machinery you add when the requirements arrive. When they do, `your-first-adk-agent-harness.md` shows the next rung — a `get_current_time`-style function tool, callbacks that intercept the lifecycle, and constructing the `Runner` yourself so your application owns the event stream instead of the CLI.

## When "minimal" stops being enough

Keep this shape while the agent only talks. Add a `tools=[...]` list the first time it must fetch data; add a `description` and sub-agents the moment two agents need to delegate to each other; construct a `Runner` yourself as soon as your application — not the CLI — has to consume the event stream. Each step is additive: none of the seven lines above has to be rewritten, only extended.

## Pitfalls at this scale

- **The variable must be named `root_agent`.** ADK looks for exactly that name in the agent module; `my_agent = Agent(...)` silently fails to load.
- **Folder name is the agent selector.** `adk web` lists agents by directory name, so keep one agent per folder.
- **No key, no turn.** Missing `GOOGLE_API_KEY` in `.env` fails on the first model call — the file lives inside the agent folder, not the shell environment.
- **Model strings are not guessed.** Use a valid Gemini model name; typos surface as provider errors, not Python errors.
- **Do not import your agent into random scripts.** Keep `agent.py` import-light so `adk` can load it without side effects.

**Takeaway:** a working ADK agent is one `root_agent = Agent(name=..., model=..., instruction=...)` assignment in a discoverable folder — everything else in the framework (tools, callbacks, sessions, Runner) is opt-in machinery you layer on only when your agent outgrows a greeting, which is exactly where `your-first-adk-agent-harness.md` picks up.

## Sources
- https://github.com/google/adk-python
- https://adk.dev/get-started/python/
- https://adk.dev/get-started/about/
- https://adk.dev/runtime/
