Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

11. OpenAPI Tools

REST API integration using OpenAPI specifications.

Blog Post: https://arjunprabhulal.com/adk-custom-tools-openapi/

Table of Contents

  1. Overview
  2. Prerequisites
  3. Setup Steps
  4. How It Works
  5. Running the Agent
  6. Next Steps

Overview

OpenAPI tools allow agents to call REST APIs defined by OpenAPI/Swagger specifications. ADK automatically generates tools from the spec.

Prerequisites

  • Python 3.10+
  • Gemini API key from AI Studio
  • GitHub Personal Access Token (for the example)

Setup Steps

  1. Navigate to this module:
cd 11-openapi-tools
  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -r ../requirements.txt
  1. Set up environment variables in github_agent/.env:
GOOGLE_API_KEY=your-api-key-here
GITHUB_TOKEN=your-github-token

How It Works

  1. Define the OpenAPI spec - JSON or YAML format
  2. Create OpenAPIToolset - Pass the spec and auth credentials
  3. Add to agent - Pass the toolset to the agent's tools list
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])

Running the Agent

Using ADK Web

adk web

Open http://127.0.0.1:8000 and select github_agent.

Test Queries:

  • "Get my GitHub user info"
  • "Who am I on GitHub?"

Using ADK CLI

adk run github_agent

Next Steps

Continue to 12. Multi-Tool Agent