Building custom Python function tools for ADK agents.
Blog Post: https://arjunprabhulal.com/adk-custom-tools-function/
Custom function tools are Python functions that agents can call. ADK automatically wraps them - no need for FunctionTool().
- Python 3.10+
- Gemini API key from AI Studio
- Navigate to this module:
cd 10-custom-function-tools- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r ../requirements.txt- Set up environment variables in
custom_tool_agent/.env:
GOOGLE_API_KEY=your-api-key-here
- Define a Python function with type hints
- Add a docstring describing the function
- Return a dictionary with the result
- Pass the function directly to the agent's
toolslist
def get_order_status(order_id: str) -> dict:
"""Retrieves the status of an order by order ID."""
return {"order_id": order_id, "status": "Shipped"}
agent = Agent(
model="gemini-2.5-flash",
tools=[get_order_status], # ADK auto-wraps it
)adk webOpen http://127.0.0.1:8000 and select custom_tool_agent.
Test Queries:
- "What is the status of order 12345?"
- "Check order ABC123"
adk run custom_tool_agentContinue to 11. OpenAPI Tools