Documentation
¶
Overview ¶
Package openapi provides a compiled.Skill implementation that wraps an OpenAPI spec.
This allows any HTTP API with an OpenAPI 3.x specification to be used as an agent skill. The skill parses the spec, generates tools from operations, and handles HTTP calls with authentication.
Example ¶
skill := openapi.NewSkill(openapi.Config{
Name: "petstore",
SpecURL: "https://petstore3.swagger.io/api/v3/openapi.json",
Auth: openapi.AuthConfig{
Type: openapi.AuthAPIKey,
APIKey: os.Getenv("PETSTORE_API_KEY"),
},
})
agent, err := agent.New(config,
agent.WithCompiledSkill(skill),
)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
// Type is the authentication type.
Type AuthType
// APIKey is the API key value (for AuthAPIKey).
APIKey string
// APIKeyName is the header or query parameter name (for AuthAPIKey).
// Defaults to "X-API-Key" for header, "api_key" for query.
APIKeyName string
// APIKeyIn specifies where to send the API key: "header" or "query".
// Defaults to "header".
APIKeyIn string
// Token is the bearer token (for AuthBearer).
Token string
// Username is the username (for AuthBasic).
Username string
// Password is the password (for AuthBasic).
Password string
}
AuthConfig configures authentication for API calls.
type AuthType ¶
type AuthType string
AuthType specifies the authentication method.
const ( // AuthNone indicates no authentication. AuthNone AuthType = "" // AuthAPIKey indicates API key authentication. AuthAPIKey AuthType = "apiKey" // AuthBearer indicates Bearer token authentication. AuthBearer AuthType = "bearer" // AuthBasic indicates HTTP Basic authentication. AuthBasic AuthType = "basic" )
type Config ¶
type Config struct {
// Name is the skill identifier (e.g., "petstore").
// This must be unique among all skills registered with an agent.
Name string
// Description is a human-readable description of the skill.
// If empty, uses the OpenAPI spec's info.description or a default.
Description string
// SpecURL is the URL to fetch the OpenAPI spec from.
// Either SpecURL or SpecFile must be provided.
SpecURL string
// SpecFile is the path to a local OpenAPI spec file.
// Either SpecURL or SpecFile must be provided.
SpecFile string
// BaseURL overrides the server URL from the OpenAPI spec.
// If empty, uses the first server URL from the spec.
BaseURL string
// Auth configures authentication for API calls.
Auth AuthConfig
// IncludeOperations filters which operations to expose as tools.
// If empty, all operations are included.
// Use operation IDs (e.g., ["getPet", "listPets"]).
IncludeOperations []string
// ExcludeOperations filters which operations to exclude.
// Applied after IncludeOperations.
ExcludeOperations []string
// IncludeTags filters operations by tags.
// If set, only operations with at least one matching tag are included.
IncludeTags []string
// HTTPClient is the HTTP client to use for API calls.
// If nil, http.DefaultClient is used.
HTTPClient *http.Client
// RequestTimeout is the timeout for individual API requests.
// If zero, no timeout is applied beyond any client timeout.
RequestTimeout int // seconds
// LazyLoad defers spec loading until first tool call (default: false).
LazyLoad bool
}
Config configures an OpenAPI skill.
type Skill ¶
type Skill struct {
// contains filtered or unexported fields
}
Skill wraps an OpenAPI spec as a compiled.Skill.
The skill parses the OpenAPI specification and exposes each operation as a tool that can be called by the agent.
func NewSkill ¶
NewSkill creates a new OpenAPI skill with the given configuration.
The spec is not loaded until Init() is called (or first tool call if LazyLoad is true).
func (*Skill) Close ¶
Close releases resources. For OpenAPI skills, this is a no-op since there are no persistent connections.
func (*Skill) Description ¶
Description returns a human-readable description of the skill.