BUILD · 5 MIN READ
Build with Google’s Agent Development Kit
Define a root agent and a Python function tool, then run it with ADK.
Jump to a section 9 sections
EXAMPLE USE CASE
Create an ADK order-support project
You want an agent that the ADK development runner can discover and invoke with a function tool.
- Input
- A sample_agent Python package exposing root_agent and a question about A104.
- Expected output
- A Gemini response grounded in lookup_order and the packed fixture.
- Success check: Run adk from the package parent, inspect the tool event, then test a missing identifier.
- Try a failure: A missing __init__.py or root_agent must be diagnosed as project discovery, not a model failure.
Example scope: A real Google ADK integration. Session storage and user authorization must be supplied separately.
Resolve the real user and pass a bounded task to the SDK.
The runtime manages the loop or explicit state transitions; it does not replace resource authorization.
invokeTo 03 · Configured modelvalidatedTo 04 · Allowed toolscompleteTo 06 · Verified answerKeep provider credentials on the server and select a model supported by the API account.
The example exposes a local fixture. A real tool must check the authenticated user and resource.
observationBack to 02 · Google’s Agent Development KitTrack the current conversation and stop when the turn or recursion budget is reached.
Result or stopping pointFor A104, confirm that the answer reflects the lookup observation and contains no invented dates.
Result or stopping point
The runtime manages the loop or explicit state transitions; it does not replace resource authorization.
Where it fits
- Google ADK provides agent definitions, function tools, and application workflow building blocks.
- An agent project exposes a
root_agentthat the development runner can load.
Prepare the project
- Install
google-adk. - Create
sample_agent/__init__.pycontainingfrom . import agent, and save the example assample_agent/agent.py. - Set
GOOGLE_API_KEYandGOOGLE_MODELto an available Gemini model. - Run
adk run sample_agentfrom the parent directory.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install google-adk
export GOOGLE_API_KEY="your-api-key"
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
export GOOGLE_MODEL="your-enabled-gemini-model-id"
mkdir -p sample_agent
printf "from . import agent\n" > sample_agent/__init__.pyimport os
from google.adk.agents.llm_agent import Agent
def lookup_order(order_id: str) -> str:
"""Read an order status from a local demonstration fixture."""
orders = {"A104": "Packed; awaiting courier pickup"}
return orders.get(order_id, "Order not found")
root_agent = Agent(
name="order_assistant",
model=os.environ["GOOGLE_MODEL"],
description="Answers status questions using sample order data.",
instruction=(
"Use lookup_order for order status. "
"Report only the returned information."
),
tools=[lookup_order],
)Educational example. Uses your configured environment and credentials; no paid model call is made by this website.
Try the task
- Ask “What is the status of A104?” The tool returns sample data.
- Inspect whether the answer reflects that result, then ask about an unknown order and check that the agent does not invent a status.
Keep state and tools distinct
- As the application grows, decide which information belongs to the current session and which should persist across sessions.
- The tool service must enforce access independently of the agent’s instructions.
Run and verify
adk run sample_agent
# Then enter: What is the status of A104?- Run adk from the parent of sample_agent so the package can be discovered.
- The root_agent calls lookup_order and answers from the A104 fixture.
Troubleshooting and failure tests
- Agent discovery errors usually mean the package is missing __init__.py or root_agent.
- Do not mix a Gemini API-key setup with Vertex AI project and location credentials unintentionally.
Before production
- Replace the local fixture with a service that enforces authenticated tenant and resource permissions.
- Add timeouts, bounded retries, tracing redaction, and a regression case for each observed failure.
- Model calls consume provider API usage when you run this example; this website only displays the code.