OpenApiTool Class

A tool that retrieves information using OpenAPI specs. Initialized with an initial API definition (name, description, spec, auth), this class also supports adding and removing additional API definitions dynamically.

Constructor initializes the tool with a primary API definition.

Constructor

OpenApiTool(name: str, description: str, spec: Any, auth: OpenApiAuthDetails, default_parameters: List[str] | None = None)

Parameters

Name Description
name
Required
str

The name of the API.

description
Required
str

The API description.

spec
Required
Any

The API specification.

auth
Required

Authentication details for the API.

default_parameters

List of OpenAPI spec parameters that will use user-provided defaults.

Default value: None

Methods

add_definition

Adds a new API definition dynamically. Raises a ValueError if a definition with the same name already exists.

execute

OpenApiTool does not execute client-side.

remove_definition

Removes an API definition based on its name.

add_definition

Adds a new API definition dynamically. Raises a ValueError if a definition with the same name already exists.

add_definition(name: str, description: str, spec: Any, auth: OpenApiAuthDetails | None = None, default_parameters: List[str] | None = None) -> None

Parameters

Name Description
name
Required
str

The name of the API.

description
Required
str

The description of the API.

spec
Required
Any

The API specification.

auth

Optional authentication details for this particular API definition. If not provided, the tool's default authentication details will be used.

Default value: None
default_parameters

List of OpenAPI spec parameters that will use user-provided defaults.

Default value: None

Exceptions

Type Description

If a definition with the same name exists.

execute

OpenApiTool does not execute client-side.

execute(tool_call: Any) -> None

Parameters

Name Description
tool_call
Required
Any

The tool call to execute.

remove_definition

Removes an API definition based on its name.

remove_definition(name: str) -> None

Parameters

Name Description
name
Required
str

The name of the API definition to remove.

Exceptions

Type Description

If the definition with the specified name does not exist.

Attributes

definitions

Get the list of all API definitions for the tool.

Returns

Type Description

A list of OpenAPI tool definitions.

resources

Get the tool resources for the agent.

Returns

Type Description

An empty ToolResources as OpenApiTool doesn't have specific resources.