REST API integration using OpenAPI specifications.
Blog Post: https://arjunprabhulal.com/adk-custom-tools-openapi/
OpenAPI tools allow agents to call REST APIs defined by OpenAPI/Swagger specifications. ADK automatically generates tools from the spec.
- Python 3.10+
- Gemini API key from AI Studio
- GitHub Personal Access Token (for the example)
- Navigate to this module:
cd 11-openapi-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
github_agent/.env:
GOOGLE_API_KEY=your-api-key-here
GITHUB_TOKEN=your-github-token
- Define the OpenAPI spec - JSON or YAML format
- Create OpenAPIToolset - Pass the spec and auth credentials
- Add to agent - Pass the toolset to the agent's
toolslist
from google.adk.tools.openapi_tool.openapi_toolset import OpenAPIToolset
toolset = OpenAPIToolset(
spec_str=json.dumps(GITHUB_SPEC),
spec_str_type="json",
auth_scheme=auth_scheme,
auth_credential=auth_credential
)
agent = Agent(tools=[toolset])adk webOpen http://127.0.0.1:8000 and select github_agent.
Test Queries:
- "Get my GitHub user info"
- "Who am I on GitHub?"
adk run github_agentContinue to 12. Multi-Tool Agent