Skip to main content
All right — now that we understand how tools work and how to create them, let’s implement two practical tools for our helpdesk agent: user lookups and checking service status. For clarity and to make the example easy to run, we keep everything in a single file (agent.py). Later, you can break tools into separate modules if you prefer.
A presentation slide with the title "Implementing our Tools" and a dark teal curved panel on the right containing the word "Demo" in bright blue. A small "© Copyright KodeKloud" note appears in the bottom-left.
Overview
  • Build two tiny in-memory services:
    • a fake user directory
    • a fake service-status registry
  • Implement two strongly-typed tools that return structured dictionaries so the LLM knows what to expect:
    • lookup_user(email: str) -> Dict[str, Any]
    • check_service_status(service_name: str) -> Dict[str, Any]
  • Register these functions with an ADK Agent so the LLM can call them.
Comments and docstrings are visible to the LLM and can affect tool usage. Keep them accurate, concise, and machine-friendly.
Tool return schemas Use clear, predictable return shapes so the agent can consume results without guessing. The table below summarizes the two tools and their expected structured outputs. Concise example: agent.py Below is a corrected, concise implementation that demonstrates typed imports, small in-memory stores, the two tool functions, and the Agent registration exposing the tools to the LLM. Keep this code in a single file for now to simplify running and testing.
Why normalize inputs
  • Make lookups case-insensitive and tolerant of leading/trailing whitespace by lower-casing and stripping inputs.
  • Returning a clear structure (status + payload or error_message) prevents the LLM from guessing shapes and reduces hallucinations.
Best practice
  • Explicitly list each tool in Agent.tools (e.g., tools=[lookup_user, check_service_status]) — this keeps tool availability explicit and discoverable by the agent.
  • Keep docstrings short, factual, and up-to-date: the LLM relies on these to decide when and how to call a tool.
Running and testing (example terminal session) Start your agent with the ADK CLI:
Notes about ADK and how the LLM uses tools
  • ADK can auto-wrap plain Python functions as callable tools with structured I/O.
  • The agent coordinates between the LLM and your functions: the LLM decides which tool to call and prepares inputs; the function returns structured data; the LLM then translates that structured data into natural language for the user.
  • Explicit, structured tool outputs help avoid hallucination and allow concrete, checkable responses.
Common pitfalls and debugging:
  • NameError or import errors often indicate a missing import or incorrectly registered tool. Verify your imports and that you included tools in Agent.tools.
  • If the agent returns unexpected output, confirm your tool’s return schema matches its docstring and the LLM’s expectations.
Next steps
  • Implement stateful troubleshooting flows so the agent can remember context across multiple turns.
  • Add authentication and access controls when you move from fake in-memory stores to real data sources.
  • Split tools into modules for larger projects and add unit tests for each tool’s structured outputs.
Further reading

Watch Video