registry

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermissionRuleMatcherKey = contract.PermissionRuleMatcherKey
	ResolvedToolMetadataKey  = contract.ResolvedToolMetadataKey

	ContentTypeText   = contract.ContentTypeText
	ContentTypeJSON   = contract.ContentTypeJSON
	ContentTypeBinary = contract.ContentTypeBinary
	ContentTypeStream = contract.ContentTypeStream
	ContentTypeMixed  = contract.ContentTypeMixed
)
View Source
const (
	ToolSurfaceProfileMonoRun    = "mono_run"
	ToolSurfaceProfileSubagent   = "subagent"
	ToolSurfaceProfileSkillAgent = "skill_agent"
)

Variables

This section is empty.

Functions

func AttachPermissionMatcherMetadata

func AttachPermissionMatcherMetadata(metadata map[string]any, resolvedTool Tool, matcher func(string) bool) map[string]any

func BuildPermissionMatcher

func BuildPermissionMatcher(ctx context.Context, resolvedTool Tool, input map[string]any) (func(string) bool, error)

func IsDeferred

func IsDeferred(tool Tool) bool

IsDeferred checks if a tool should be deferred based on its definition.

func IsValidToolName

func IsValidToolName(name string) bool

func PermissionMatcherFromMetadata

func PermissionMatcherFromMetadata(metadata map[string]any) func(string) bool

func RequiresUserInteraction

func RequiresUserInteraction(t Tool) bool

func VisibleInSurfaceProfile

func VisibleInSurfaceProfile(def ToolDefinition, profile string) bool

Types

type BackfillInputFn

type BackfillInputFn func(ctx context.Context, input map[string]any) map[string]any

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 NewBuilder

func NewBuilder(name string) *Builder

NewBuilder creates a new tool builder

func (*Builder) Build

func (b *Builder) Build() (Tool, error)

Build builds the tool

func (*Builder) ConcurrencySafe

func (b *Builder) ConcurrencySafe() *Builder

ConcurrencySafe marks the tool as concurrency-safe

func (*Builder) Destructive

func (b *Builder) Destructive() *Builder

Destructive marks the tool as destructive

func (*Builder) NoPermission

func (b *Builder) NoPermission() *Builder

NoPermission marks the tool as not requiring permission

func (*Builder) ReadOnly

func (b *Builder) ReadOnly() *Builder

ReadOnly marks the tool as read-only

func (*Builder) WithAliases

func (b *Builder) WithAliases(aliases ...string) *Builder

WithAliases sets the tool aliases

func (*Builder) WithBackfillInput

func (b *Builder) WithBackfillInput(fn BackfillInputFn) *Builder

WithBackfillInput sets the input backfill function.

func (*Builder) WithCategory

func (b *Builder) WithCategory(category string) *Builder

WithCategory sets the category

func (*Builder) WithConcurrencySafetyEvaluator

func (b *Builder) WithConcurrencySafetyEvaluator(predicate ToolPredicateFn) *Builder

WithConcurrencySafetyEvaluator sets the runtime concurrency predicate.

func (*Builder) WithDescription

func (b *Builder) WithDescription(description string) *Builder

WithDescription sets the tool description

func (*Builder) WithDisplayName

func (b *Builder) WithDisplayName(displayName string) *Builder

WithDisplayName sets the display name

func (*Builder) WithEnabled

func (b *Builder) WithEnabled(fn func() bool) *Builder

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

func (b *Builder) WithHandler(handler HandlerFn) *Builder

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

func (b *Builder) WithMaxResultSize(max int) *Builder

WithMaxResultSize sets the maximum result size in characters.

func (*Builder) WithMetadata

func (b *Builder) WithMetadata(key string, value any) *Builder

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.

func (*Builder) WithSchemaValidator

func (b *Builder) WithSchemaValidator(validator *schema.Validator) *Builder

WithSchemaValidator sets a schema validator for this tool.

type CallInput

type CallInput = contract.CallInput

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

type FormatResultFn func(data any) string

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 NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new tool registry

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) Clear

func (r *Registry) Clear()

Clear removes all tools from the registry

func (*Registry) Clone

func (r *Registry) Clone() *Registry

Clone creates a copy of the registry

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of unique tools

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get retrieves a tool by name. Kept as a compatibility alias for older call sites.

func (*Registry) GetToolNames

func (r *Registry) GetToolNames() []string

GetToolNames returns all tool names (excluding aliases)

func (*Registry) GetToolsByAlias

func (r *Registry) GetToolsByAlias(alias string) []Tool

GetToolsByAlias returns tools that have a specific alias

func (*Registry) HasTool

func (r *Registry) HasTool(name string) bool

HasTool checks if a tool is registered

func (*Registry) List

func (r *Registry) List() []Tool

List returns all registered tools

func (*Registry) ListByCategory

func (r *Registry) ListByCategory(category string) []Tool

ListByCategory returns tools in a specific category

func (*Registry) ListCategories

func (r *Registry) ListCategories() []string

ListCategories returns all categories

func (*Registry) ListDeferred

func (r *Registry) ListDeferred() []Tool

ListDeferred returns tools that should be deferred (loaded via ToolSearch).

func (*Registry) ListNonDeferred

func (r *Registry) ListNonDeferred() []Tool

ListNonDeferred returns tools that should NOT be deferred.

func (*Registry) Merge

func (r *Registry) Merge(other *Registry) error

Merge merges another registry into this one

func (*Registry) Register

func (r *Registry) Register(tool Tool) error

Register registers a tool in the registry

func (*Registry) RegisterBatch

func (r *Registry) RegisterBatch(tools []Tool) error

RegisterBatch registers multiple tools

func (*Registry) Resolve

func (r *Registry) Resolve(name string) (Tool, bool)

Resolve resolves a tool by name

func (*Registry) Search

func (r *Registry) Search(query string) []Tool

Search searches for tools by name or description

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

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 SurfaceBuildRequest struct {
	PermissionCheck    types.CanUseToolFn
	CategoryFilter     string
	IncludeReadOnly    bool
	IncludeDestructive bool
	SurfaceProfile     string
	AllowedNames       []string
	BlockedNames       []string
}

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 (*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

type Tool = contract.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

func ToolFromMetadata(metadata map[string]any) Tool

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

type ToolPredicateFn func(input map[string]any) bool

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

type Toolset

type Toolset = contract.Toolset

type ValidateInputFn

type ValidateInputFn func(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInputFn validates and optionally normalizes tool input.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL