Documentation
¶
Index ¶
- Constants
- func AddTool(t Tool)
- func RegisterTool(provider Provider, name string, description string, tags []string, ...)
- type ClientTransport
- type InMemoryToolRepository
- func (r InMemoryToolRepository) GetProvider(ctx context.Context, providerName string) (*Provider, error)
- func (r InMemoryToolRepository) GetProviders(ctx context.Context) ([]Provider, error)
- func (r InMemoryToolRepository) GetTool(ctx context.Context, toolName string) (*Tool, error)
- func (r InMemoryToolRepository) GetTools(ctx context.Context) ([]Tool, error)
- func (r InMemoryToolRepository) GetToolsByProvider(ctx context.Context, providerName string) ([]Tool, error)
- func (r InMemoryToolRepository) RemoveProvider(ctx context.Context, providerName string) error
- func (r InMemoryToolRepository) RemoveTool(ctx context.Context, toolName string) error
- func (r *InMemoryToolRepository) SaveProviderWithTools(ctx context.Context, provider Provider, tools []Tool) error
- type OpenAPIConverter
- type OpenApiConverter
- type TagSearchStrategy
- type TextTransport
- type Tool
- type ToolHandler
- type ToolInputOutputSchema
- type ToolProvider
- type ToolRepository
- type ToolSearchStrategy
- type UtcpManual
Constants ¶
const Version = "1.0"
Variables ¶
This section is empty.
Functions ¶
func RegisterTool ¶
func RegisterTool( provider Provider, name string, description string, tags []string, inputs *ToolInputOutputSchema, outputs *ToolInputOutputSchema, handler ToolHandler, )
RegisterTool is the Go equivalent of your @utcp_tool decorator. Call this from an init() function in the same package as your handler.
Types ¶
type ClientTransport ¶
type ClientTransport interface {
// RegisterToolProvider registers a tool provider (e.g. via the /utcp endpoint)
// and returns the list of tools it exposes.
RegisterToolProvider(ctx context.Context, manualProvider Provider) ([]Tool, error)
// DeregisterToolProvider removes a previously registered provider.
DeregisterToolProvider(ctx context.Context, manualProvider Provider) error
// CallTool invokes a named tool with the given arguments on a specific provider.
// It returns whatever the tool returns (often map[string]interface{} or a typed result).
CallTool(ctx context.Context, toolName string, arguments map[string]any, toolProvider Provider, l *string) (any, error)
}
ClientTransport defines how a client registers, deregisters, and invokes UTCP tools.
type InMemoryToolRepository ¶
type InMemoryToolRepository struct {
// contains filtered or unexported fields
}
func (InMemoryToolRepository) GetProvider ¶
func (r InMemoryToolRepository) GetProvider(ctx context.Context, providerName string) (*Provider, error)
func (InMemoryToolRepository) GetProviders ¶
func (r InMemoryToolRepository) GetProviders(ctx context.Context) ([]Provider, error)
func (InMemoryToolRepository) GetTools ¶
func (r InMemoryToolRepository) GetTools(ctx context.Context) ([]Tool, error)
func (InMemoryToolRepository) GetToolsByProvider ¶
func (InMemoryToolRepository) RemoveProvider ¶
func (r InMemoryToolRepository) RemoveProvider(ctx context.Context, providerName string) error
func (InMemoryToolRepository) RemoveTool ¶
func (r InMemoryToolRepository) RemoveTool(ctx context.Context, toolName string) error
func (*InMemoryToolRepository) SaveProviderWithTools ¶
func (r *InMemoryToolRepository) SaveProviderWithTools(ctx context.Context, provider Provider, tools []Tool) error
type OpenAPIConverter ¶
type OpenAPIConverter struct {
// contains filtered or unexported fields
}
OpenAPIConverter helps converting OpenAPI specs into a UtcpManual.
func NewOpenAPIConverter ¶
func NewOpenAPIConverter(raw interface{}, url, name string) *OpenAPIConverter
NewOpenAPIConverter creates a new converter for OpenAPI raw definitions.
func (*OpenAPIConverter) Convert ¶
func (c *OpenAPIConverter) Convert() UtcpManual
Convert processes the OpenAPI spec and returns a UtcpManual.
type OpenApiConverter ¶
type OpenApiConverter struct {
// contains filtered or unexported fields
}
OpenApiConverter converts an OpenAPI JSON spec into a UtcpManual.
func NewConverter ¶
func NewConverter( openapiSpec map[string]interface{}, specURL string, providerName string, ) *OpenApiConverter
NewConverter creates a new converter. If providerName is empty, it will be derived from spec.info.title.
func (*OpenApiConverter) Convert ¶
func (c *OpenApiConverter) Convert() UtcpManual
Convert parses the OpenAPI spec and builds a UtcpManual.
type TagSearchStrategy ¶
type TagSearchStrategy struct {
// contains filtered or unexported fields
}
TagSearchStrategy implements a tool search strategy based on tags and description keywords.
func NewTagSearchStrategy ¶
func NewTagSearchStrategy(repo ToolRepository, descriptionWeight float64) *TagSearchStrategy
NewTagSearchStrategy creates a new TagSearchStrategy with the given repository and description weight.
func (*TagSearchStrategy) SearchTools ¶
func (s *TagSearchStrategy) SearchTools(ctx context.Context, query string, limit int) ([]Tool, error)
SearchTools returns tools ordered by relevance to the query, using explicit tags and description keywords.
type TextTransport ¶
type TextTransport interface {
ClientTransport
SetBasePath(path string)
}
TextTransport interface for setting base path kept here for tests relying on it
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
Inputs ToolInputOutputSchema `json:"inputs"`
Outputs ToolInputOutputSchema `json:"outputs"`
Tags []string `json:"tags"`
AverageResponseSize *int `json:"average_response_size,omitempty"`
Provider Provider `json:"tool_provider"`
Handler ToolHandler `json:"-"`
}
Tool holds the metadata for a single UTCP tool.
func DecodeToolsResponse ¶
func DecodeToolsResponse(r io.ReadCloser) ([]Tool, error)
decodeToolsResponse parses a common tools discovery response.
type ToolHandler ¶
type ToolHandler func(ctx map[string]interface{}, inputs map[string]interface{}) (outputs map[string]interface{}, err error)
ToolHandler is the signature your Go tool functions must satisfy. The first argument is your execution context (if any), here we use a generic map. You can replace `map[string]interface{}` with a concrete struct or interface as needed.
type ToolInputOutputSchema ¶
type ToolInputOutputSchema struct {
Type string `json:"type"` // e.g. "object", "array", "string"
Properties map[string]interface{} `json:"properties,omitempty"` // field schemas
Required []string `json:"required,omitempty"`
Description string `json:"description,omitempty"`
Title string `json:"title,omitempty"`
Items map[string]interface{} `json:"items,omitempty"` // for arrays
Enum []interface{} `json:"enum,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
Format string `json:"format,omitempty"` // e.g. "date-time"
}
ToolInputOutputSchema mirrors your JSON schema description.
type ToolProvider ¶
ProviderUnion is your existing Go interface/union for providers.
type ToolRepository ¶
type ToolRepository interface {
// SaveProviderWithTools saves a provider and its associated tools.
SaveProviderWithTools(ctx context.Context, provider Provider, tools []Tool) error
// RemoveProvider removes a provider and all its tools by name.
// Returns an error if the provider does not exist.
RemoveProvider(ctx context.Context, providerName string) error
// RemoveTool removes a single tool by name.
// Returns an error if the tool does not exist.
RemoveTool(ctx context.Context, toolName string) error
// GetTool retrieves a tool by name.
// Returns (nil, nil) if the tool is not found.
GetTool(ctx context.Context, toolName string) (*Tool, error)
// GetTools returns all tools in the repository.
GetTools(ctx context.Context) ([]Tool, error)
// GetToolsByProvider returns all tools for a specific provider.
// Returns (nil, nil) if the provider is not found.
GetToolsByProvider(ctx context.Context, providerName string) ([]Tool, error)
// GetProvider retrieves a provider by name.
// Returns (nil, nil) if the provider is not found.
GetProvider(ctx context.Context, providerName string) (*Provider, error)
// GetProviders returns all providers in the repository.
GetProviders(ctx context.Context) ([]Provider, error)
}
ToolRepository defines the contract for persisting providers and their tools.
func NewInMemoryToolRepository ¶
func NewInMemoryToolRepository() ToolRepository
type ToolSearchStrategy ¶
type ToolSearchStrategy interface {
// SearchTools returns up to `limit` tools matching `query`.
// A limit of 0 means “no limit” (return all matches).
//
// ctx carries deadlines, cancellation signals, and other request-scoped values.
SearchTools(ctx context.Context, query string, limit int) ([]Tool, error)
}
ToolSearchStrategy is an interface for any component that knows how to search for tools based on a query.
type UtcpManual ¶
type UtcpManual struct {
Version string
Tools []Tool
Name string // optional, for OpenAPI-derived manuals
}
UtcpManual represents a manual with a version and a set of tools.
func NewUtcpManualFromMap ¶
func NewUtcpManualFromMap(m map[string]interface{}) UtcpManual
NewUtcpManualFromMap constructs a UtcpManual from a raw map representation.