Concept 2What is a Tool?
02b & 05a · Art #2b & #5a

A Tool is a deterministic Python function wrapped in FunctionTool. ADK automatically converts your Python type hints and docstring into a tool declaration.

  • Type hints + docstrings are prompt engineering: an agent decides when and how to call your tool purely from its signature and docstring.
  • Structured dict returns: always return a dictionary with a clear status key ({'status': 'found', 'profile': ...}) so the LLM can reason on success vs error.
  • Hidden superpower for stateful tools — tool_context: ToolContext: add a parameter typed as ToolContext and ADK automatically injects the current execution context, letting your tool read/write session.state directly!
adk_agent_app/tools/gatekeeper_tools.py
from google.adk.tools import FunctionTool, ToolContext
def is_registered_user(
user_id: str,
tool_context: ToolContext, # <-- Auto-injected by ADK!
) -> dict:
"""Verifies if a traveler user_id exists in Firestore.
Args:
user_id: Unique ID of the traveler (e.g. usr_0a8f67).
"""
doc = db.collection("users").document(user_id).get()
if doc.exists:
tool_context.state["user:user_id"] = user_id
return {"status": "found", "user_profile": doc.to_dict()}
return {"status": "not_found"}