tools

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package tools provides the tool registry and built-in tools.

Package tools provides the tool registry and built-in tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetHTTPTimeout

func SetHTTPTimeout(timeout time.Duration)

SetHTTPTimeout configures the shared HTTP client timeout. This should be set to the maximum of configured tool timeouts. Context deadlines take precedence for individual requests.

Types

type Args

type Args map[string]interface{}

Args wraps tool arguments with typed accessor methods. Eliminates repetitive type assertions and improves error messages.

func (Args) Bool

func (a Args) Bool(key string) (bool, error)

Bool gets a required boolean argument.

func (Args) BoolOr

func (a Args) BoolOr(key string, defaultVal bool) bool

BoolOr gets an optional boolean argument with a default.

func (Args) Float

func (a Args) Float(key string) (float64, error)

Float gets a required float64 argument.

func (Args) FloatOr

func (a Args) FloatOr(key string, defaultVal float64) float64

FloatOr gets an optional float64 argument with a default.

func (Args) Has

func (a Args) Has(key string) bool

Has returns true if the key exists in the arguments.

func (Args) Int

func (a Args) Int(key string) (int, error)

Int gets a required integer argument. Handles both int and float64 (JSON numbers decode as float64).

func (Args) IntOr

func (a Args) IntOr(key string, defaultVal int) int

IntOr gets an optional integer argument with a default.

func (Args) Raw

func (a Args) Raw(key string) interface{}

Raw returns the raw value for a key, or nil if not present.

func (Args) String

func (a Args) String(key string) (string, error)

String gets a required string argument.

func (Args) StringOr

func (a Args) StringOr(key, defaultVal string) string

StringOr gets an optional string argument with a default.

func (Args) StringSlice

func (a Args) StringSlice(key string) ([]string, error)

StringSlice gets a required string slice argument. Handles []interface{} (JSON arrays decode as []interface{}).

func (Args) StringSliceOr

func (a Args) StringSliceOr(key string, defaultVal []string) []string

StringSliceOr gets an optional string slice argument with a default.

type CredentialProvider

type CredentialProvider interface {
	GetAPIKey(provider string) string
}

CredentialProvider provides API keys for tools

type DirEntry

type DirEntry struct {
	Name  string `json:"name"`
	IsDir bool   `json:"is_dir"`
	Size  int64  `json:"size"`
}

DirEntry represents a directory entry for ls.

type ExecResult

type ExecResult struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exit_code"`
}

ExecResult represents the result of bash execution.

type FILResult

type FILResult struct {
	Findings []string `json:"findings"`
	Insights []string `json:"insights"`
	Lessons  []string `json:"lessons"`
}

FILResult holds categorized observation results.

type FileMemoryStore

type FileMemoryStore struct {
	// contains filtered or unexported fields
}

FileMemoryStore stores memory in a JSON file.

func NewFileMemoryStore

func NewFileMemoryStore(path string) *FileMemoryStore

NewFileMemoryStore creates a new file-based memory store.

func (*FileMemoryStore) Get

func (s *FileMemoryStore) Get(key string) (string, error)

func (*FileMemoryStore) List

func (s *FileMemoryStore) List(filter string) ([]string, error)

func (*FileMemoryStore) Search

func (s *FileMemoryStore) Search(query string) ([]MemorySearchResult, error)

func (*FileMemoryStore) Set

func (s *FileMemoryStore) Set(key, value string) error

type GrepMatch

type GrepMatch struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Content string `json:"content"`
}

GrepMatch represents a grep match result.

type InMemoryStore

type InMemoryStore struct {
	// contains filtered or unexported fields
}

InMemoryStore stores memory in-memory only (lost after run).

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore creates a new in-memory store (scratchpad mode).

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(key string) (string, error)

func (*InMemoryStore) List

func (s *InMemoryStore) List(filter string) ([]string, error)

func (*InMemoryStore) Search

func (s *InMemoryStore) Search(query string) ([]MemorySearchResult, error)

func (*InMemoryStore) Set

func (s *InMemoryStore) Set(key, value string) error

type MemorySearchResult

type MemorySearchResult struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

MemorySearchResult represents a search hit in scratchpad.

type MemoryStore

type MemoryStore interface {
	Get(key string) (string, error)
	Set(key, value string) error
	List(prefix string) ([]string, error)
	Search(query string) ([]MemorySearchResult, error)
}

MemoryStore is the interface for key-value storage (scratchpad).

type ObservationItem

type ObservationItem struct {
	ID       string `json:"id"`
	Content  string `json:"content"`
	Category string `json:"category"`
}

ObservationItem represents a stored observation with its ID.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds all registered tools.

func NewRegistry

func NewRegistry(pol *policy.Policy) *Registry

NewRegistry creates a new registry with built-in tools.

func (*Registry) Definitions

func (r *Registry) Definitions() []ToolDefinition

Definitions returns LLM-facing definitions for enabled tools.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, args map[string]interface{}) (interface{}, error)

Execute executes a tool by name with tracing instrumentation. Returns the result and any error from execution.

func (*Registry) Get

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

Get returns a tool by name, or nil if not found.

func (*Registry) Has

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

Has returns true if the registry has a tool with the given name.

func (*Registry) Register

func (r *Registry) Register(t Tool)

Register adds a tool to the registry.

func (*Registry) SetBashChecker

func (r *Registry) SetBashChecker(checker *policy.BashChecker)

SetBashChecker sets the bash security checker for the bash tool. The checker performs two-step verification: deterministic denylist + LLM policy check.

func (*Registry) SetBashLLMChecker

func (r *Registry) SetBashLLMChecker(llmChecker policy.LLMPolicyChecker)

SetBashLLMChecker sets the LLM-based policy checker for directory access. This enables Step 2 of bash security checking.

func (*Registry) SetBashSecurityCallback

func (r *Registry) SetBashSecurityCallback(fn func(command, step string, allowed bool, reason string, durationMs int64, inputTokens, outputTokens int))

SetBashSecurityCallback sets a callback for bash security decisions (for logging/auditing).

func (*Registry) SetCredentials

func (r *Registry) SetCredentials(creds CredentialProvider)

SetCredentials sets the credential provider for tools that need API keys

func (*Registry) SetMemoryStore

func (r *Registry) SetMemoryStore(store MemoryStore)

SetMemoryStore is deprecated, use SetScratchpad instead.

func (*Registry) SetScratchpad

func (r *Registry) SetScratchpad(store MemoryStore, persisted bool)

SetScratchpad sets the scratchpad store and registers scratchpad tools. persisted indicates whether data survives across agent runs (affects tool descriptions).

func (*Registry) SetSemanticMemory

func (r *Registry) SetSemanticMemory(mem SemanticMemory)

SetSemanticMemory sets the semantic memory and registers semantic memory tools

func (*Registry) SetSpawner

func (r *Registry) SetSpawner(spawner SpawnFunc)

SetSpawner sets the spawner function for the spawn_agent and spawn_agents tools

func (*Registry) SetSummarizer

func (r *Registry) SetSummarizer(s Summarizer)

SetSummarizer sets the summarizer for web_fetch tool

type SearchResult

type SearchResult struct {
	Title   string `json:"title"`
	URL     string `json:"url"`
	Snippet string `json:"snippet"`
}

SearchResult represents a single search result

type SemanticMemory

type SemanticMemory interface {
	// RememberFIL stores multiple observations at once and returns their IDs
	RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
	// RetrieveByID gets a single observation by ID
	RetrieveByID(ctx context.Context, id string) (*ObservationItem, error)
	// RecallFIL searches and returns categorized results
	RecallFIL(ctx context.Context, query string, limitPerCategory int) (*FILResult, error)
	// Recall searches and returns flat results with scores
	Recall(ctx context.Context, query string, limit int) ([]SemanticMemoryResult, error)
}

SemanticMemory provides semantic memory operations.

type SemanticMemoryResult

type SemanticMemoryResult struct {
	ID       string  `json:"id"`
	Content  string  `json:"content"`
	Category string  `json:"category"` // "finding" | "insight" | "lesson"
	Score    float32 `json:"score"`
}

SemanticMemoryResult is a memory with relevance score.

type SpawnFunc

type SpawnFunc func(ctx context.Context, role, task string, outputs []string) (string, error)

SpawnFunc is the function signature for spawning sub-agents. It takes role, task and returns the sub-agent's output. SpawnFunc is the function signature for spawning dynamic sub-agents. outputs is optional - when provided, the sub-agent returns structured JSON.

type Summarizer

type Summarizer interface {
	Summarize(ctx context.Context, content, question string) (string, error)
}

Summarizer provides content summarization for web_fetch

type Tool

type Tool interface {
	// Name returns the tool name.
	Name() string
	// Description returns a description for the LLM.
	Description() string
	// Parameters returns the JSON schema for parameters.
	Parameters() map[string]interface{}
	// Execute runs the tool with the given arguments.
	Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)
}

Tool represents an executable tool.

func NewSpawnAgentTool

func NewSpawnAgentTool(spawner SpawnFunc) Tool

NewSpawnAgentTool creates a spawn_agent tool with the given spawner function.

type ToolDefinition

type ToolDefinition struct {
	Name        string
	Description string
	Parameters  map[string]interface{}
}

ToolDefinition is the LLM-facing tool definition.

Jump to

Keyboard shortcuts

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