> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Building Your First Agent

> Guide to building, running, and debugging a minimal Google ADK agent using agent.py, __init__.py, and .env with examples for local execution and web inspection.

It's still Thursday.

A minute ago you ran:

```bash theme={null}
$ adk create my_agent
Created my_agent/.env
Created my_agent/__init__.py
Created my_agent/agent.py
```

Those three files are your entire agent. Below we walk through each file, explain what it does, and show how to run and debug the agent locally.

## What ADK expects: the three files

| File | Purpose | Example / Notes |
| - | - | - |
| `agent.py` | Contains the agent definition. ADK looks for a single variable named `root_agent`. | See the minimal example below. |
| `__init__.py` | Makes the folder a Python package so ADK can import it by name. | `from . import agent` |
| `.env` | Stores `GOOGLE_API_KEY` so you don't need to export it every shell session. Do not commit this file to git. | Example contents shown below. |

## agent.py — the heart of your agent

ADK expects a variable named `root_agent` in `agent.py`. The loader imports your package and looks specifically for that exact variable name. Do not rename it.

Minimal example:

```python theme={null}
from google.adk.agents import LlmAgent

root_agent = LlmAgent(
    model="gemini-flash-latest",
    name="my_agent",
    description="A helpful assistant.",
    instruction="Answer the user's questions.",
)
```

Always keep the variable named `root_agent`. If you rename it, ADK will not find your agent.

If you accidentally rename the variable, ADK fails to load the agent. For example:

```python theme={null}
from google.adk.agents import LlmAgent

support_agent = LlmAgent(
    model="gemini-flash-latest",
    name="my_agent",
    description="A helpful assistant.",
    instruction="Answer the user's questions.",
)
```

Running ADK after renaming produces:

```bash theme={null}
$ adk run my_agent
Error: No root_agent found in my_agent
```

## **init**.py — make the folder importable

`__init__.py` contains a single import so ADK can import the package by folder name. You will rarely need to edit this file.

```python theme={null}
from . import agent
```

## .env — store your API key locally

Put your `GOOGLE_API_KEY` in the `.env` file so you don't have to re-export it every time:

```env theme={null}
GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY_HERE
```

Never commit `.env` to version control. It contains your API key and must remain secret.

If you prefer to set the key for a single run without modifying `.env`, pass it inline:

```bash theme={null}
GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY_HERE adk run my_agent
```

## Running the agent locally

Start an interactive chat session with:

```bash theme={null}
$ adk run my_agent
Running agent my_agent, type exit to exit.
```

A typical terminal conversation looks like:

```bash theme={null}
[user]: hello
[my_agent]: Hi! How can I help you today?
[user]: Where's my order?
[my_agent]: Sorry, I don't have access to order information. Please contact the store where you placed your order.
[user]: exit
```

This behavior is expected for the minimal agent: it can reply but has no domain context (for example, order data), so responses are generic.

## Inspecting what the agent does: ADK Web

When you want visibility into the agent's internal behavior (useful for debugging why it suggested a refund, which model was called, or which tools ran), run:

```bash theme={null}
$ adk web
```

ADK Web opens a local development UI in your browser with two main panels:

* Chat: interact with the agent like the terminal session.
* Trace: a detailed execution trace showing which model was invoked, inputs and outputs, and — once you add tools — which tools ran and their results.

This trace is essential when debugging complex agents or investigating unexpected behavior.

![A dark-themed UI mockup titled "ADK Web" showing side-by-side Chat and Trace panels. The Chat shows "You: Where's my order?" and "Agent: Sorry, I don't have access to order information," while the Trace lists the model and input/output details.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Fundamentals-of-Google-ADK/Building-Your-First-Agent/adk-web-chat-trace-ui-mockup.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=a9d4e4a443ffa20ed570194c40b593fb)

## Next steps

Now that you can create, run, and inspect a minimal agent, the next step is to expand `agent.py` field-by-field: add domain context, integrate tools or data sources, and configure the model behavior so the agent can act on real information.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/1d143913-38fb-4a53-8976-041e503dbf12/lesson/33dfa8e2-b7e7-4e16-a57c-c2bb9b8b6f81)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.