tool

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeAsk  = "ask"  // ask user for every tool call
	ModeAuto = "auto" // execute automatically
	ModeDeny = "deny" // refuse tool execution
)

Mode constants for tool execution behaviour.

Variables

This section is empty.

Functions

func WithPolicy

func WithPolicy(ctx context.Context, p *Policy) context.Context

WithPolicy attaches policy to context.

Types

type AskFunc

type AskFunc func(ctx context.Context, name string, args map[string]interface{}, p *Policy) bool

AskFunc is invoked when policy.Mode==ModeAsk. It should return true to approve the call, false to reject. It can optionally mutate the policy (for example to switch to auto mode after user confirmation).

type Handler

type Handler func(ctx context.Context, args map[string]interface{}) (string, error)

Handler executes a tool call and returns its textual result.

type Policy

type Policy struct {
	Mode      string   // ask, auto or deny
	AllowList []string // optional set of allowed tools (empty => all)
	BlockList []string // optional set of blocked tools
	Ask       AskFunc  // optional callback when Mode==ask
}

Policy controls runtime behaviour of tool execution.

func FromContext

func FromContext(ctx context.Context) *Policy

FromContext retrieves policy from context; may be nil.

func (*Policy) IsAllowed

func (p *Policy) IsAllowed(name string) bool

IsAllowed checks whether a tool name is permitted by Allow/Block lists.

type Registry

type Registry interface {
	// Definitions returns the merged list of available tool definitions.
	Definitions() []llm.ToolDefinition

	//MatchDefinition matches tool definition based on pattern
	MatchDefinition(pattern string) []*llm.ToolDefinition

	// GetDefinition fetches the definition for the given tool name. The second
	// result value indicates whether the definition exists.
	GetDefinition(name string) (*llm.ToolDefinition, bool)

	// MustHaveTools converts a set of patterns into the LLM toolkit slice used by
	// generation prompts.
	MustHaveTools(patterns []string) ([]llm.Tool, error)

	// Execute invokes the given tool with the supplied arguments and returns
	// its textual result.
	Execute(ctx context.Context, name string, args map[string]interface{}) (string, error)

	// SetDebugLogger attaches a writer that receives every executed tool call
	// for debugging.
	SetDebugLogger(w io.Writer)
}

Registry defines the minimal interface required by the rest of the code-base. Previous consumers used a concrete *Registry struct; moving to an interface allows alternative implementations (remote catalogues, mocks, etc.) while retaining backward-compatibility.

func WithConversation added in v0.2.0

func WithConversation(inner Registry, convID string) Registry

WithConversation returns a Registry that guarantees ctx carries convID for every Execute call. All other methods delegate to the underlying registry.

Directories

Path Synopsis
extension

Jump to

Keyboard shortcuts

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