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

# Adding Tools to the Agent

> Explains how to add callable tools to an agent so LLMs can access live data, outlining tool structure, the think act observe loop, and safety design practices

You gave the agent a role, a set of rules, and a voice so it can talk—but it still couldn't act.

Try asking it where order A1001 is. The model has never seen your live orders, so it has exactly two honest options: admit it can't check the order, or guess. A confident, polished guess in perfect customer-service English is exactly what makes support bots dangerous.

```text theme={null}
Role: Support assistant for a store.

Rules:
1. Keep replies short.
2. Never invent order details.
3. No order number? Ask for one.
4. Refunds go to a human.

Tone: friendly, clear, patient.

$ adk run my_agent
[user]: Where's order A1001?
[my_agent]: I can't check orders yet.
[my_agent]: It shipped yesterday!
```

Today we change that. You hand the agent its first set of tools.

One hard rule sits underneath everything: a language model can only produce text. Its knowledge froze the day its training finished, and it can't touch your database, a calculator, or the internet. A tool fixes that — it is a callable function the agent can use to do things the model cannot do alone: check live data, run a calculation, or call an external API.

![A dark infographic titled "What a Tool Is" showing a text-only model (frozen at training) sending output to a tool icon. The tool then branches to examples like "Your database," "A calculator," and "The internet."](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Fundamentals-of-Google-ADK/Adding-Tools-to-the-Agent/frozen-text-only-model-tool-infographic.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=f2873fbae3a612d85c8d0aa3b79ba13d)

In ADK, a tool is just a plain Python function. Below are two simple examples: one to look up an order and another to return the store's hours.

```python theme={null}
def get_order_status(order_id: str) -> dict:
    """Look up where an order is by its ID."""
    order = ORDERS.get(order_id)
    if order is None:
        return {"status": "error", "message": "not found"}
    return {"status": "success", "order": order}


def get_store_hours() -> dict:
    """Return the store's hours for each day."""
    return {"status": "success", "hours": STORE_HOURS}
```

Why this shape matters:

* Consistent return format: each tool returns a dictionary with a `status` field rather than a freeform string. That lets the agent distinguish success, failure, and other states programmatically.
* Schema from docstrings + signature: ADK builds the tool schema from the function signature and the docstring only. The model never sees your function body—only the name, parameter types, and the docstring are used to describe the tool.
* Type hints are important. `order_id: str` tells the model the argument should be text and reduces argument-format errors when the agent calls the tool.

Write docstrings as if you're explaining the function to a novice. The docstring is the only description the model will ever read.

How tools are wired into an agent

* When you create the agent, pass the function objects (not their return values) to the `LlmAgent` constructor via the `tools` field.
* The system prompt passed to the model is adjusted to list the available tools and their schemas, but the model still decides whether and when to call them.
* The agent uses a think-act-observe loop when it needs external data.

Four-step think-act-observe loop

1. Reason: the model reads the user message and the available tool schemas and decides whether a tool is needed.
2. Call the tool: the model emits a structured request naming the tool and its arguments (for example, `get_order_status` with `order_id="A1001"`). ADK catches that request and runs your real function.
3. Observe: ADK sends the actual return value from your function back to the model as an observation.
4. Respond: the model reads the observation and either calls another tool or writes the final answer.

This same think-act-observe-repeat loop can run multiple times during one user interaction.

![A schematic titled "Four Steps" showing four labeled boxes (1 Reasons, 2 Calls the tool, 3 Observes, 4 Responds) connected by arrows. Below it is a workflow diagram showing interactions between "You," "The model," "ADK," and "Your function" with bidirectional arrows.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Fundamentals-of-Google-ADK/Adding-Tools-to-the-Agent/four-steps-reasons-calls-observes-responds.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=a56bdfb4b9f860ad8a6a1e45d5c5be43)

Example multi-tool run

* User: "Where's order A1001? Open on Sunday?"
* Agent decides both tools are required: first to check the order, then to check hours.
* Console output example:

```bash theme={null}
$ adk run my_agent
[user]: Where's order A1001? Open on Sunday?
→ needs both tools
→ get_order_status(order_id="A1001")
{"status": "success", "order": {"shipped": "July 11", "carrier": "UPS"}}
→ get_store_hours()
{"status": "success", "hours": {"Sat": "9 am-4 pm", "Sun": "closed"}}
```

What this enables (and what still needs work)

* Today, two of the most common inbox questions—"Where's my order?" and "What are your working hours?"—can return real, live answers from lookups.
* Other flows still need more tooling and safeguards: "Why was I charged twice?" requires an invoice lookup and reconciliation tool; "Cancel my order" needs a safe cancellation flow that can pause for human approval and audit.

Design and safety reminders

| Aspect | Why it matters | Example / Note |
| - | - | - |
| Return format | Enables programmatic handling of success/failure | Use `{"status": "success", "order": {...}}` or `{"status": "error", "message": "not found"}` |
| Docstrings & signatures | ADK uses them to build tool schemas | Keep parameter types clear (e.g., `order_id: str`) |
| Least privilege | Tools should only return data required for the agent's task | Avoid returning full PII unless necessary |
| Human-in-the-loop | Some actions must be escalated or require approval | Refunds and destructive changes should route to humans |

Avoid exposing sensitive data through tools. Design tool outputs to provide only the fields needed for the agent's reply, and ensure destructive operations require explicit human approval.

Step back: many automation problems are best solved by multiple agents and a routing layer. As agents and tools proliferate, you’ll organize them into a graph where specialized agents call each other and share tools safely.

Links and references

* ADK documentation: [https://developers.google.com/ai/develop/adk](https://developers.google.com/ai/develop/adk)
* Design patterns for tool-enabled agents: [https://arxiv.org/abs/2306.XXXXX](https://arxiv.org/abs/2306.XXXXX)
* Best practices for safe tool design: [https://www.owasp.org/](https://www.owasp.org/)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/1d143913-38fb-4a53-8976-041e503dbf12/lesson/7640eee0-94ba-4bce-9430-82b9342517c4)

> [card] [Practice Lab](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/1d143913-38fb-4a53-8976-041e503dbf12/lesson/1b349ea4-ea7f-439a-9e25-edb7c0093cd1)


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