Documentation
¶
Index ¶
- func FilterTools(defs []schema.ToolDef, names []string) []schema.ToolDef
- func ToAIModelTools(defs []schema.ToolDef) []aimodel.Tool
- type ExternalToolCaller
- type Registry
- func (r *Registry) Execute(ctx context.Context, name, args string) (schema.ToolResult, error)
- func (r *Registry) Get(name string) (schema.ToolDef, bool)
- func (r *Registry) List() []schema.ToolDef
- func (r *Registry) Merge(defs []schema.ToolDef)
- func (r *Registry) Register(def schema.ToolDef, handler ToolHandler) error
- func (r *Registry) RegisterIfAbsent(def schema.ToolDef, handler ToolHandler) error
- func (r *Registry) SetExternalCaller(c ExternalToolCaller)
- func (r *Registry) Unregister(name string) error
- type RegistryOption
- type ToolExecutor
- type ToolHandler
- type ToolRegistry
- type TruncatingToolRegistry
- func (t *TruncatingToolRegistry) Execute(ctx context.Context, name, args string) (schema.ToolResult, error)
- func (t *TruncatingToolRegistry) Get(name string) (schema.ToolDef, bool)
- func (t *TruncatingToolRegistry) List() []schema.ToolDef
- func (t *TruncatingToolRegistry) Merge(defs []schema.ToolDef)
- func (t *TruncatingToolRegistry) Register(def schema.ToolDef, handler ToolHandler) error
- func (t *TruncatingToolRegistry) Unregister(name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterTools ¶
FilterTools returns only the tools whose names are in the whitelist. If names is empty, all tools are returned.
Types ¶
type ExternalToolCaller ¶
type ExternalToolCaller interface {
CallTool(ctx context.Context, name, args string) (schema.ToolResult, error)
}
ExternalToolCaller calls tools that are not handled locally.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a thread-safe in-memory tool registry.
func NewRegistry ¶
func NewRegistry(opts ...RegistryOption) *Registry
NewRegistry creates an empty Registry.
func (*Registry) List ¶
List returns all registered tool definitions in a deterministic (name-sorted) order. Stable ordering keeps the Anthropic prompt-cache prefix (tools block) byte-identical across independent invocations, which is a prerequisite for cache hits — map iteration order would otherwise shuffle the prefix on every call.
func (*Registry) Register ¶
func (r *Registry) Register(def schema.ToolDef, handler ToolHandler) error
func (*Registry) RegisterIfAbsent ¶
func (r *Registry) RegisterIfAbsent(def schema.ToolDef, handler ToolHandler) error
RegisterIfAbsent atomically checks for duplicates and registers under a single write lock to avoid a TOCTOU race between a separate read-lock check and Register().
func (*Registry) SetExternalCaller ¶
func (r *Registry) SetExternalCaller(c ExternalToolCaller)
SetExternalCaller sets the caller used for tools with no local handler. Prefer WithExternalCaller at construction time when possible.
func (*Registry) Unregister ¶
type RegistryOption ¶
type RegistryOption func(*Registry)
RegistryOption configures a Registry during construction.
func WithExternalCaller ¶
func WithExternalCaller(c ExternalToolCaller) RegistryOption
WithExternalCaller sets the caller used for tools with no local handler.
type ToolExecutor ¶
type ToolExecutor interface {
Execute(ctx context.Context, name, args string) (schema.ToolResult, error)
}
ToolExecutor executes a named tool with the given arguments.
type ToolHandler ¶
ToolHandler is a function that handles a tool invocation. name is the tool name, args is the raw JSON arguments string.
type ToolRegistry ¶
type ToolRegistry interface {
ToolExecutor
Register(def schema.ToolDef, handler ToolHandler) error
Unregister(name string) error
Get(name string) (schema.ToolDef, bool)
List() []schema.ToolDef
Merge(defs []schema.ToolDef) // merge external tool definitions (for MCP)
}
ToolRegistry manages tool definitions and their handlers.
type TruncatingToolRegistry ¶ added in v0.4.0
type TruncatingToolRegistry struct {
// contains filtered or unexported fields
}
TruncatingToolRegistry wraps a ToolRegistry and truncates tool results that exceed maxTokens.
TruncatingToolRegistry is safe for concurrent use if the underlying ToolRegistry is safe for concurrent use.
func NewTruncatingToolRegistry ¶ added in v0.4.0
func NewTruncatingToolRegistry(inner ToolRegistry, maxTokens int) *TruncatingToolRegistry
NewTruncatingToolRegistry creates a truncating wrapper. If maxTokens <= 0, no truncation is applied.
func (*TruncatingToolRegistry) Execute ¶ added in v0.4.0
func (t *TruncatingToolRegistry) Execute(ctx context.Context, name, args string) (schema.ToolResult, error)
Execute delegates to the inner registry, then truncates text content parts exceeding maxTokens.
func (*TruncatingToolRegistry) Get ¶ added in v0.4.0
func (t *TruncatingToolRegistry) Get(name string) (schema.ToolDef, bool)
Get delegates to the inner registry.
func (*TruncatingToolRegistry) List ¶ added in v0.4.0
func (t *TruncatingToolRegistry) List() []schema.ToolDef
List delegates to the inner registry.
func (*TruncatingToolRegistry) Merge ¶ added in v0.4.0
func (t *TruncatingToolRegistry) Merge(defs []schema.ToolDef)
Merge delegates to the inner registry.
func (*TruncatingToolRegistry) Register ¶ added in v0.4.0
func (t *TruncatingToolRegistry) Register(def schema.ToolDef, handler ToolHandler) error
Register delegates to the inner registry.
func (*TruncatingToolRegistry) Unregister ¶ added in v0.4.0
func (t *TruncatingToolRegistry) Unregister(name string) error
Unregister delegates to the inner registry.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package todo implements the todo_write built-in tool: a session-scoped, in-memory task tracker that the LLM agent maintains during a multi-step task.
|
Package todo implements the todo_write built-in tool: a session-scoped, in-memory task tracker that the LLM agent maintains during a multi-step task. |
|
Package toolkit provides shared utilities for file tools, including path validation, atomic file writes, file locking, and edit snippet generation.
|
Package toolkit provides shared utilities for file tools, including path validation, atomic file writes, file locking, and edit snippet generation. |