> ## 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.

# Understanding the Agent Anatomy

> Explains AI agent anatomy, key configuration fields, crafting system prompts, adding tools for order support, and testing best practices to ensure helpful, consistent agent behavior.

You just built your first AI agent.

It runs, answers questions in the terminal, and the ADK Web dashboard shows what it does under the hood. But when you ask a customer question like "Where's my order?" the agent may reply with something unhelpful:

```bash theme={null}
$ adk run my_agent
Running agent my_agent, type exit to exit.
[user]: hello
[my_agent]: Hi! How can I help you today?
[user]: exit
[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.
```

That response is correct given the agent's configuration: it has no instruction or tooling to fetch order data. To fix this, open your agent definition (`agent.py`) and update the agent's system prompt (instruction) and add any necessary connectors or tools that let it access order information.

Below is the simplest LLM agent definition you'll typically see in ADK. It wires a name, model, description, and a system prompt (instruction):

```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.",
)
```

Key fields explained

| Field | Purpose | Notes / Example |
| - | - | - |
| `model` | Selects which language model performs reasoning. | Change this string (e.g., `gemini-flash-latest`) to swap the agent's "brain". Consider latency, cost, and capability tradeoffs. |
| `name` | The agent's runtime identifier (required). | Must be a valid Python identifier (letters, digits, underscores). The runtime uses this to route messages and reference agents. |
| `description` | Short, single-line summary of the agent's role. | Optional for single-agent setups; important in multi-agent systems so coordinators can choose the right agent. |
| `instruction` | The system prompt that defines role, constraints, and expected behavior. | The most important field for predictable behavior: tell the agent which tools to use, what to ask, and how to format responses. |

How ADK builds model input

ADK composes model input by stacking three contexts:

1. The system prompt (`instruction`) — your explicit rules and role.
2. The conversation history — prior user and agent turns.
3. The new user message — the latest question or instruction.

The model receives the full stack and generates the next response based on that combined context.

![A diagram titled "The Stack" showing a shopper's message (envelope) feeding into the model's input (new message, conversation history, system prompt) and then into a chip icon labeled the model (gemini-flash-latest). It illustrates the flow of user input and context into an AI model.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Fundamentals-of-Google-ADK/Understanding-the-Agent-Anatomy/stack-message-context-gemini-flash.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=5f000cd6555f66e80036d812a1ee362c)

That’s the agent anatomy: a model that performs reasoning, a name the runtime uses, an optional description for routing, and an instruction that determines behavior. If your agent should answer order-related questions, the system prompt must instruct it how to handle those queries and what tools (APIs) to use.

Example: a focused system prompt for order support

* Ask for an order ID when missing.
* Use an orders API or tool when available.
* Respond concisely and politely with the latest order status.
* If no order data is available, explain what information is needed and how to provide it.

Here is a simple, concrete `instruction` that implements the above:

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

root_agent = LlmAgent(
    model="gemini-flash-latest",
    name="my_agent",
    description="A helpful assistant that answers order and support questions.",
    instruction=(
        "You are a customer support assistant. When a user asks about an order, "
        "first request the order ID if it is not provided. If you have access to "
        "an orders API or a tool, call it to retrieve the current order status and "
        "reply with a concise, polite status update. If you do not have access to "
        "order data, tell the user exactly which details you need (for example, "
        "order ID, email, or phone number) and how they can provide them."
    ),
)
```

Best practices for system prompts

Keep system prompts focused, explicit, and actionable. Prefer short instructions that state: which tools to use, what to ask from users, and how to format responses. Avoid overly long or speculative rules—clarity yields consistent agent behavior.

Next steps: add tools and test

1. Add any required tooling (orders API connector, database access, or an internal tool) and register it with the agent runtime so the agent can call it.
2. Re-run the agent and simulate the "Where's my order?" flow. Expected behaviors:
   * If the user did not provide an order ID, the agent asks for it.
   * If the agent has access to order data, it calls the orders tool and returns a helpful status.
   * If the agent lacks access, it explains what the user must provide and how.
3. Iterate on the `instruction` to refine phrasing, response format, or required checks (e.g., privacy, authentication).

Troubleshooting checklist

| Symptom | Likely cause | Remedy |
| - | - | - |
| Agent replies it lacks order data | No tool or API configured | Add an orders API connector and allow the agent to call it |
| Agent asks irrelevant clarifying questions | Instruction is vague | Make the `instruction` explicit about required fields (e.g., "always ask for order ID") |
| Agent gives inconsistent output | Overly long or conflicting rules | Simplify and prioritize instructions; use examples if needed |

Further reading

* [ADK agents](https://notes.kodekloud.com/docs/agents) — agent configuration and registration
* [ADK Web](https://notes.kodekloud.com/docs/adk-web) — dashboard and debugging tools

After making the prompt and tooling changes, re-run your agent. It should now either request the missing order ID or call the orders API and return a useful status instead of the generic "I don't have access" message.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/1d143913-38fb-4a53-8976-041e503dbf12/lesson/b1171915-af79-4c0f-b4b5-737c8a7e4758)


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