Documentation
¶
Index ¶
- Constants
- func AttachPermissionMatcherMetadata(metadata map[string]any, resolvedTool Tool, matcher func(string) bool) map[string]any
- func BuildPermissionMatcher(ctx context.Context, resolvedTool Tool, input map[string]any) (func(string) bool, error)
- func IsDeferred(tool Tool) bool
- func IsValidToolName(name string) bool
- func PermissionMatcherFromMetadata(metadata map[string]any) func(string) bool
- func RequiresUserInteraction(t Tool) bool
- func VisibleInSurfaceProfile(def ToolDefinition, profile string) bool
- type BackfillInputFn
- type Builder
- func (b *Builder) Build() (Tool, error)
- func (b *Builder) ConcurrencySafe() *Builder
- func (b *Builder) Destructive() *Builder
- func (b *Builder) NoPermission() *Builder
- func (b *Builder) ReadOnly() *Builder
- func (b *Builder) WithAliases(aliases ...string) *Builder
- func (b *Builder) WithBackfillInput(fn BackfillInputFn) *Builder
- func (b *Builder) WithCategory(category string) *Builder
- func (b *Builder) WithConcurrencySafetyEvaluator(predicate ToolPredicateFn) *Builder
- func (b *Builder) WithDescription(description string) *Builder
- func (b *Builder) WithDisplayName(displayName string) *Builder
- func (b *Builder) WithEnabled(fn func() bool) *Builder
- func (b *Builder) WithFormatResult(fn FormatResultFn) *Builder
- func (b *Builder) WithHandler(handler HandlerFn) *Builder
- func (b *Builder) WithInputSchema(schema schema.JSONSchema) *Builder
- func (b *Builder) WithInputValidator(validator ValidateInputFn) *Builder
- func (b *Builder) WithJSONSchema(toolName string, jsonSchema schema.JSONSchema) *Builder
- func (b *Builder) WithMaxResultSize(max int) *Builder
- func (b *Builder) WithMetadata(key string, value any) *Builder
- func (b *Builder) WithPermissionChecker(checker CheckPermissionsFn) *Builder
- func (b *Builder) WithReadOnlyEvaluator(predicate ToolPredicateFn) *Builder
- func (b *Builder) WithSchemaValidator(validator *schema.Validator) *Builder
- type CallInput
- type CallResult
- type CheckPermissionsFn
- type ContentType
- type ContextModifier
- type Definition
- type FormatResultFn
- type HandlerFn
- type PermissionMatcherTool
- type Registry
- func (r *Registry) BuildSurface(ctx *SurfaceContext) (*Surface, error)
- func (r *Registry) Clear()
- func (r *Registry) Clone() *Registry
- func (r *Registry) Count() int
- func (r *Registry) Get(name string) (Tool, bool)
- func (r *Registry) GetToolNames() []string
- func (r *Registry) GetToolsByAlias(alias string) []Tool
- func (r *Registry) HasTool(name string) bool
- func (r *Registry) List() []Tool
- func (r *Registry) ListByCategory(category string) []Tool
- func (r *Registry) ListCategories() []string
- func (r *Registry) ListDeferred() []Tool
- func (r *Registry) ListNonDeferred() []Tool
- func (r *Registry) Merge(other *Registry) error
- func (r *Registry) Register(tool Tool) error
- func (r *Registry) RegisterBatch(tools []Tool) error
- func (r *Registry) Resolve(name string) (Tool, bool)
- func (r *Registry) Search(query string) []Tool
- func (r *Registry) Unregister(name string) error
- type RegistryConfig
- type RequiresUserInteractionTool
- type ResultMetadata
- type Surface
- type SurfaceBuildRequest
- type SurfaceBuilder
- type SurfaceContext
- type Tool
- type ToolDefinition
- type ToolPredicateFn
- type ToolUseContext
- type Toolset
- type ValidateInputFn
Constants ¶
const ( PermissionRuleMatcherKey = contract.PermissionRuleMatcherKey ResolvedToolMetadataKey = contract.ResolvedToolMetadataKey ContentTypeText = contract.ContentTypeText ContentTypeJSON = contract.ContentTypeJSON ContentTypeBinary = contract.ContentTypeBinary ContentTypeStream = contract.ContentTypeStream ContentTypeMixed = contract.ContentTypeMixed )
const ( ToolSurfaceProfileMonoRun = "mono_run" ToolSurfaceProfileSubagent = "subagent" ToolSurfaceProfileSkillAgent = "skill_agent" )
Variables ¶
This section is empty.
Functions ¶
func BuildPermissionMatcher ¶
func IsDeferred ¶
IsDeferred checks if a tool should be deferred based on its definition.
func IsValidToolName ¶
func RequiresUserInteraction ¶
func VisibleInSurfaceProfile ¶
func VisibleInSurfaceProfile(def ToolDefinition, profile string) bool
Types ¶
type BackfillInputFn ¶
BackfillInputFn enriches a shallow clone of the parsed input with derived fields.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds a tool from a definition and handler function
func (*Builder) ConcurrencySafe ¶
ConcurrencySafe marks the tool as concurrency-safe
func (*Builder) Destructive ¶
Destructive marks the tool as destructive
func (*Builder) NoPermission ¶
NoPermission marks the tool as not requiring permission
func (*Builder) WithAliases ¶
WithAliases sets the tool aliases
func (*Builder) WithBackfillInput ¶
func (b *Builder) WithBackfillInput(fn BackfillInputFn) *Builder
WithBackfillInput sets the input backfill function.
func (*Builder) WithCategory ¶
WithCategory sets the category
func (*Builder) WithConcurrencySafetyEvaluator ¶
func (b *Builder) WithConcurrencySafetyEvaluator(predicate ToolPredicateFn) *Builder
WithConcurrencySafetyEvaluator sets the runtime concurrency predicate.
func (*Builder) WithDescription ¶
WithDescription sets the tool description
func (*Builder) WithDisplayName ¶
WithDisplayName sets the display name
func (*Builder) WithEnabled ¶
WithEnabled sets the enabled predicate (default true).
func (*Builder) WithFormatResult ¶
func (b *Builder) WithFormatResult(fn FormatResultFn) *Builder
WithFormatResult sets the result formatter.
func (*Builder) WithHandler ¶
WithHandler sets the handler function
func (*Builder) WithInputSchema ¶
func (b *Builder) WithInputSchema(schema schema.JSONSchema) *Builder
WithInputSchema sets the input schema.
func (*Builder) WithInputValidator ¶
func (b *Builder) WithInputValidator(validator ValidateInputFn) *Builder
WithInputValidator sets the input validator.
func (*Builder) WithJSONSchema ¶
func (b *Builder) WithJSONSchema(toolName string, jsonSchema schema.JSONSchema) *Builder
WithJSONSchema registers a JSON schema for this tool.
func (*Builder) WithMaxResultSize ¶
WithMaxResultSize sets the maximum result size in characters.
func (*Builder) WithMetadata ¶
WithMetadata adds metadata to the tool
func (*Builder) WithPermissionChecker ¶
func (b *Builder) WithPermissionChecker(checker CheckPermissionsFn) *Builder
WithPermissionChecker sets the tool-specific permission checker.
func (*Builder) WithReadOnlyEvaluator ¶
func (b *Builder) WithReadOnlyEvaluator(predicate ToolPredicateFn) *Builder
WithReadOnlyEvaluator sets the runtime read-only predicate.
type CallResult ¶
type CallResult = contract.CallResult
func NewErrorResult ¶
func NewErrorResult(err error) CallResult
func NewJSONResult ¶
func NewJSONResult(data any) CallResult
func NewTextResult ¶
func NewTextResult(content string) CallResult
type CheckPermissionsFn ¶
type CheckPermissionsFn func(ctx context.Context, input map[string]any, toolCtx ToolUseContext) types.PermissionResult
CheckPermissionsFn performs tool-specific permission checks.
type ContentType ¶
type ContentType = contract.ContentType
type ContextModifier ¶
type ContextModifier = contract.ContextModifier
type Definition ¶
type Definition = contract.Definition
type FormatResultFn ¶
FormatResultFn serialises tool output into the tool_result content string.
type HandlerFn ¶
type HandlerFn func(ctx context.Context, input CallInput, toolCtx ToolUseContext) (CallResult, error)
HandlerFn is a function that handles a tool call
type PermissionMatcherTool ¶
type PermissionMatcherTool = contract.PermissionMatcherTool
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages tool registration and discovery
func NewRegistryWithConfig ¶
func NewRegistryWithConfig(config *RegistryConfig) *Registry
NewRegistryWithConfig creates a new registry with custom configuration
func (*Registry) BuildSurface ¶
func (r *Registry) BuildSurface(ctx *SurfaceContext) (*Surface, error)
BuildSurface builds a tool surface for a given context
func (*Registry) Get ¶
Get retrieves a tool by name. Kept as a compatibility alias for older call sites.
func (*Registry) GetToolNames ¶
GetToolNames returns all tool names (excluding aliases)
func (*Registry) GetToolsByAlias ¶
GetToolsByAlias returns tools that have a specific alias
func (*Registry) ListByCategory ¶
ListByCategory returns tools in a specific category
func (*Registry) ListCategories ¶
ListCategories returns all categories
func (*Registry) ListDeferred ¶
ListDeferred returns tools that should be deferred (loaded via ToolSearch).
func (*Registry) ListNonDeferred ¶
ListNonDeferred returns tools that should NOT be deferred.
func (*Registry) RegisterBatch ¶
RegisterBatch registers multiple tools
func (*Registry) Unregister ¶
Unregister removes a tool from the registry
type RegistryConfig ¶
type RegistryConfig struct {
// AllowDuplicates controls whether duplicate tool names are allowed
AllowDuplicates bool `json:"allow_duplicates"`
// CaseSensitive controls whether tool names are case-sensitive
CaseSensitive bool `json:"case_sensitive"`
}
RegistryConfig represents registry configuration
func DefaultRegistryConfig ¶
func DefaultRegistryConfig() *RegistryConfig
DefaultRegistryConfig returns default registry configuration
type RequiresUserInteractionTool ¶
type RequiresUserInteractionTool = contract.RequiresUserInteractionTool
type ResultMetadata ¶
type ResultMetadata = contract.ResultMetadata
type Surface ¶
type Surface struct {
// Tools are the tool definitions
Tools []ToolDefinition `json:"tools"`
}
Surface represents a collection of tool definitions
type SurfaceBuildRequest ¶
type SurfaceBuilder ¶
type SurfaceBuilder struct {
// contains filtered or unexported fields
}
SurfaceBuilder is the canonical way to derive the model-visible tool surface from the registry. It centralizes filtering and stable ordering so prompt assembly, provider requests, and runtime execution all agree on the same set of primary tool names.
func NewSurfaceBuilder ¶
func NewSurfaceBuilder(registry *Registry) *SurfaceBuilder
func (*SurfaceBuilder) Build ¶
func (b *SurfaceBuilder) Build(ctx context.Context, req SurfaceBuildRequest) (*Surface, error)
func (*SurfaceBuilder) BuildToolMap ¶
func (b *SurfaceBuilder) BuildToolMap(ctx context.Context, req SurfaceBuildRequest) (map[string]Tool, error)
type SurfaceContext ¶
type SurfaceContext struct {
// PermissionCheck is the permission check function
PermissionCheck types.CanUseToolFn
// SurfaceProfile selects the intended tool surface, e.g. mono_run or subagent.
SurfaceProfile string
// CategoryFilter filters tools by category
CategoryFilter string
// IncludeReadOnly controls whether to include read-only tools
IncludeReadOnly bool
// IncludeDestructive controls whether to include destructive tools
IncludeDestructive bool
}
SurfaceContext provides context for building a tool surface
type Tool ¶
func NewSimpleTool ¶
func NewSimpleTool( name string, description string, handler func(ctx context.Context, input string) (string, error), ) (Tool, error)
NewSimpleTool creates a simple tool from a handler function
func ToolFromMetadata ¶
type ToolDefinition ¶
type ToolDefinition struct {
// Name is the tool name
Name string `json:"name"`
// Description explains what the tool does
Description string `json:"description"`
// Category groups related tools
Category string `json:"category,omitempty"`
// InputSchema is the JSON schema for the tool input
InputSchema schema.JSONSchema `json:"input_schema,omitempty"`
// Metadata contains additional information
Metadata map[string]any `json:"metadata,omitempty"`
}
ToolDefinition represents a simplified tool definition for the surface
type ToolPredicateFn ¶
ToolPredicateFn returns a runtime boolean for a given tool input.
type ToolUseContext ¶
type ToolUseContext = contract.ToolUseContext
func NewToolUseContext ¶
func NewToolUseContext(sessionID types.SessionID, turnID types.TurnID, toolUseID string, permissionMode types.PermissionMode) ToolUseContext