
How to leverage your existing OpenAPI specification to instantly give your agent new skills, without writing a single line of boilerplate code.

You’re building an AI agent. You write a function for its first skill, wrap it as a tool, and pass it to the agent. It works. Then you add another. But what happens when you have 50 API endpoints? The manual approach breaks down.
Welcome to ADK Gists, a short series where we break down core concepts in AI agent development using the Agent Development Kit framework.
An agent’s ability to act depends on its tools. The standard approach of writing a Python function for each action is fine for a few skills, but it doesn’t scale. Especially if your functions are just a boilerplate code for REST API endpoints and contain no actual business logic. This is where the OpenAPI spec becomes your superpower.
The OpenAPI spec (formerly Swagger) is a game-changer for scalability. It’s a machine-readable blueprint of your API. By using a framework that can understand this blueprint, you can skip writing tool code entirely.
This is a core feature of the AgentDevelopmentKit. Instead of manually coding each API call, you use the OpenAPIToolset. Learn more here: https://google.github.io/adk-docs/tools/openapi-tools/
The workflow is as follows:
1️⃣ 𝗣𝗿𝗼𝘃𝗶𝗱𝗲 𝘁𝗵𝗲 𝗦𝗽𝗲𝗰: Give the `OpenAPIToolset` your existing OpenAPI spec as a simple string or dictionary.
2️⃣ 𝗔𝗗𝗞 𝗽𝗮𝗿𝘀𝗲𝘀: The toolset reads the spec, identifies every endpoint (e.g., GET /users/{id}), and understands its parameters and purpose.
3️⃣ 𝗧𝗼𝗼𝗹𝘀 𝗮𝗿𝗲 𝗴𝗲𝗻𝗲𝗿𝗮𝘁𝗲𝗱: For each endpoint, ADK automatically creates a `RestApiTool` in memory. The tool’s name, description, and arguments are all derived directly from the spec.
4️⃣ 𝗔𝗴𝗲𝗻𝘁 𝗶𝘀 𝗘𝗺𝗽𝗼𝘄𝗲𝗿𝗲𝗱: You pass the single OpenAPIToolset object to your agent, instantly equipping it with every capability of your API.
Why is this a better approach than manually writing function-based tools?
✅ 𝚂̲𝚌̲𝚊̲𝚕̲𝚊̲𝚋̲𝚒̲𝚕̲𝚒̲𝚝̲𝚢̲:̲ Integrate an entire, complex API in just a few lines of code. No more writing dozens of boilerplate functions.
✅ 𝚂̲𝚒̲𝚗̲𝚐̲𝚕̲𝚎̲ ̲𝚂̲𝚘̲𝚞̲𝚛̲𝚌̲𝚎̲ ̲𝚘̲𝚏̲ ̲𝚃̲𝚛̲𝚞̲𝚝̲𝚑̲:̲ When your API changes, you update one thing: the spec file. Your agent’s tools are automatically in sync, eliminating code maintenance and preventing schema drift.
✅ 𝚁̲𝚘̲𝚋̲𝚞̲𝚜̲𝚝̲𝚗̲𝚎̲𝚜̲𝚜̲:̲ Because the tools are generated from the API’s actual contract, the risk of errors from mismatched function arguments is virtually eliminated.
Here’s an outline for implementation:
# - - Load your API spec - -
openapi_spec_string = load_my_api_spec()# - - Create OpenAPIToolset - -
petstore_toolset = OpenAPIToolset(
spec_str=openapi_spec_string,
spec_str_type='json',
)
# - - Define the Agent - -
root_agent = LlmAgent(
name="petstore_agent",
model="gemini-2.0-flash",
tools=[petstore_toolset], # Pass the list of RestApiTool objects
)
By treating your API documentation as the tool, you build more capable, scalable, and maintainable agents with a fraction of the effort.
Source Credit: https://medium.com/google-cloud/adding-tools-to-your-ai-agent-the-scalable-way-d99dd7c5e532?source=rss—-e52cf94d98af—4