It is still recommended to create custom tools and wrap each API call into a
BaseTool
class, even if you have the OpenAPI schema. OpenAPI schemas allow you to get started quickly, however, for production, you might want to add some custom data validation, error handling, data processing or even combine multiple API calls into a single tool.How to Find OpenAPI Schemas
The recommended way to create OpenAPI schemas is to use Actions GPT. Simply ask it to create a schema for the API you want to use and which actions you want to perform. If your API is public and well known, it should be able to create a schema for you on the first try, without any extra documentation.How to Use OpenAPI Schemas
Below are the two ways to use OpenAPI schemas in your agents:Option 1: Using the schemas_folder
The first way to integrate OpenAPI schemas is by placing all your OpenAPI schema files in a folder, and then initializing your agent with the schemas_folder
parameter. Agency Swarm will then automatically scan this folder and convert any OpenAPI schemas it finds into BaseTool
instances.
schemas_folder
: Directory where your OpenAPI schema files are stored.api_params
: Extra parameters for specific schemas.api_headers
: Custom headers for API calls, like authentication tokens.
Option 2: Using the ToolFactory Class
Alternatively, you can use theToolFactory
class to convert OpenAPI schemas from local files or URLs.
Converting from a Local Schema File
Converting from a Local Schema File
Converting from a Remote Schema URL
Converting from a Remote Schema URL
schema
: The OpenAPI schema to convert.headers
: Custom headers for API calls, like authentication tokens.params
: Extra parameters for specific schemas.strict
: Whether to use strict OpenAI mode.
tools
list to your agent:
ToolConfig
of each tool. See the ToolConfig documentation for more information.
With any of these methods, Agency still converts your schemas into PyDantic models, so your agents will perform type checking on all API parameters before making API calls, reducing errors and improving reliability.