Documentation
¶
Overview ¶
Package tool provides the tool system for LLM function-calling: Tool interface, Registry, concurrent execution, and schema building.
Index ¶
- Constants
- type PropertyDef
- func ArrayProperty(name, description string, items map[string]any) PropertyDef
- func EnumProperty(name, typ, description string, values ...string) PropertyDef
- func ObjectProperty(name, description string, properties map[string]any) PropertyDef
- func Property(name, typ, description string) PropertyDef
- func PropertyWithDefault(name, typ, description string, defaultVal any) PropertyDef
- type Registry
- func (r *Registry) Definitions() []model.ToolDefinition
- func (r *Registry) DefinitionsByScope(scope string) []model.ToolDefinition
- func (r *Registry) Execute(ctx context.Context, call model.ToolCall) model.ToolResult
- func (r *Registry) ExecuteAll(ctx context.Context, calls []model.ToolCall) []model.ToolResult
- func (r *Registry) Get(name string) (Tool, bool)
- func (r *Registry) Len() int
- func (r *Registry) Names() []string
- func (r *Registry) Register(tool Tool)
- func (r *Registry) RegisterWithScope(tool Tool, scope string)
- func (r *Registry) ScopeOf(name string) string
- func (r *Registry) Unregister(name string) bool
- type RegistryOption
- type SchemaBuilder
- type SelfTimeouter
- type Tool
Constants ¶
const ( // ScopeAgent marks a tool as available to all agents (default). ScopeAgent = "agent" // ScopePlatform marks a tool as internal to the CoPilot platform. // Platform tools are hidden from tool_list and the frontend ToolSelector, // but can still be referenced explicitly in an LLM node's tool_names. ScopePlatform = "platform" )
Tool scope constants control visibility in tool_list and /api/tools. The scope is registry-level metadata and does NOT appear in model.ToolDefinition.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PropertyDef ¶
type PropertyDef struct {
// contains filtered or unexported fields
}
PropertyDef describes a single JSON Schema property.
func ArrayProperty ¶
func ArrayProperty(name, description string, items map[string]any) PropertyDef
ArrayProperty creates an array property with item schema.
func EnumProperty ¶
func EnumProperty(name, typ, description string, values ...string) PropertyDef
EnumProperty creates a property restricted to a set of string values.
func ObjectProperty ¶
func ObjectProperty(name, description string, properties map[string]any) PropertyDef
ObjectProperty creates an object property with nested properties schema.
func Property ¶
func Property(name, typ, description string) PropertyDef
Property creates a simple typed property definition.
func PropertyWithDefault ¶ added in v0.1.1
func PropertyWithDefault(name, typ, description string, defaultVal any) PropertyDef
PropertyWithDefault creates a typed property with a default value.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a thread-safe collection of Tools.
func NewRegistry ¶
func NewRegistry(opts ...RegistryOption) *Registry
NewRegistry creates a new tool registry.
func (*Registry) Definitions ¶
func (r *Registry) Definitions() []model.ToolDefinition
Definitions returns the ToolDefinition for every registered tool (all scopes).
func (*Registry) DefinitionsByScope ¶
func (r *Registry) DefinitionsByScope(scope string) []model.ToolDefinition
DefinitionsByScope returns only the ToolDefinitions matching the given scope.
func (*Registry) Execute ¶
Execute runs a single tool call with OTel tracing and metrics. All errors (including tool-not-found) are returned as ToolResult with IsError=true, so callers never need to handle a separate error path.
func (*Registry) ExecuteAll ¶
ExecuteAll runs multiple tool calls concurrently with a semaphore limiting parallelism. Results are returned in the same order as the input calls.
func (*Registry) Register ¶
Register adds a tool to the registry with the default scope (ScopeAgent).
func (*Registry) RegisterWithScope ¶
RegisterWithScope adds a tool to the registry with the specified scope.
func (*Registry) ScopeOf ¶
ScopeOf returns the scope of a registered tool, or ScopeAgent if not found.
func (*Registry) Unregister ¶
Unregister removes a tool by name. Returns true if the tool existed.
type RegistryOption ¶
type RegistryOption func(*Registry)
RegistryOption configures a Registry.
func WithExecTimeout ¶
func WithExecTimeout(d time.Duration) RegistryOption
WithExecTimeout sets the default timeout for individual tool executions.
func WithMaxConcurrency ¶
func WithMaxConcurrency(n int) RegistryOption
WithMaxConcurrency sets the maximum number of concurrent tool executions.
type SchemaBuilder ¶
type SchemaBuilder struct {
// contains filtered or unexported fields
}
SchemaBuilder constructs a ToolDefinition using a fluent API.
func DefineSchema ¶
func DefineSchema(name, description string, props ...PropertyDef) *SchemaBuilder
DefineSchema starts building a ToolDefinition with the given properties.
func (*SchemaBuilder) Build ¶
func (b *SchemaBuilder) Build() model.ToolDefinition
Build returns the final ToolDefinition.
func (*SchemaBuilder) Required ¶
func (b *SchemaBuilder) Required(names ...string) *SchemaBuilder
Required marks the given property names as required in the JSON Schema. Duplicate names are silently ignored.
type SelfTimeouter ¶
type SelfTimeouter interface {
SelfTimeout() bool
}
SelfTimeouter is an optional interface a Tool can implement to signal that it manages its own execution timeout internally (e.g. sandbox tools). When Registry detects this, it skips the default per-tool timeout wrapper so the tool's own timeout takes effect.