tools

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryWorkspace = "workspace"
	CategoryFile      = "file"
	CategorySearch    = "search"
	CategoryEdit      = "edit"
	CategoryShell     = "shell"
	CategoryUser      = "user"
	CategoryWeb       = "web"
	CategoryAnalysis  = "analysis"
)

Category constants for organizing tools

View Source
const (
	PermissionReadFile       = "read_file"
	PermissionWriteFile      = "write_file"
	PermissionExecuteShell   = "execute_shell"
	PermissionNetworkAccess  = "network_access"
	PermissionUserPrompt     = "user_prompt"
	PermissionWorkspaceRead  = "workspace_read"
	PermissionWorkspaceWrite = "workspace_write"
)

Permission constants for tool security

Variables

This section is empty.

Functions

func GenerateSessionID

func GenerateSessionID() string

GenerateSessionID generates a unique session ID

func ParseToolCallArgumentsJSON

func ParseToolCallArgumentsJSON(arguments string) (map[string]interface{}, error)

ParseToolCallArgumentsJSON parses tool call arguments from JSON string

Types

type DefaultRegistry

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

DefaultRegistry is the default implementation of Registry

func NewDefaultRegistry

func NewDefaultRegistry() *DefaultRegistry

NewDefaultRegistry creates a new default registry

func (*DefaultRegistry) Clear

func (r *DefaultRegistry) Clear()

Clear removes all tools from the registry

func (*DefaultRegistry) GetTool

func (r *DefaultRegistry) GetTool(name string) (Tool, bool)

GetTool retrieves a tool by name

func (*DefaultRegistry) GetToolCount

func (r *DefaultRegistry) GetToolCount() int

GetToolCount returns the number of registered tools

func (*DefaultRegistry) GetToolNames

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

GetToolNames returns the names of all registered tools

func (*DefaultRegistry) HasTool

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

HasTool checks if a tool with the given name is registered

func (*DefaultRegistry) ListTools

func (r *DefaultRegistry) ListTools() []Tool

ListTools returns all registered tools

func (*DefaultRegistry) ListToolsByCategory

func (r *DefaultRegistry) ListToolsByCategory(category string) []Tool

ListToolsByCategory returns tools in a specific category

func (*DefaultRegistry) RegisterTool

func (r *DefaultRegistry) RegisterTool(tool Tool) error

RegisterTool registers a new tool

func (*DefaultRegistry) UnregisterTool

func (r *DefaultRegistry) UnregisterTool(name string) error

UnregisterTool removes a tool from the registry

type Executor

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

Executor handles the execution of tools with proper error handling, timeouts, and security

func NewExecutor

func NewExecutor(registry Registry, permissions PermissionChecker, logger *utils.Logger, config *configuration.Config) *Executor

NewExecutor creates a new tool executor

func (*Executor) EndSession

func (e *Executor) EndSession(sessionID string)

EndSession ends a session and cleans up tracking data

func (*Executor) ExecuteTool

func (e *Executor) ExecuteTool(ctx context.Context, tool Tool, params Parameters) (*Result, error)

ExecuteTool executes a tool with the given parameters

func (*Executor) ExecuteToolByName

func (e *Executor) ExecuteToolByName(ctx context.Context, toolName string, params Parameters) (*Result, error)

ExecuteToolByName executes a tool by name

func (*Executor) ExecuteToolCall

func (e *Executor) ExecuteToolCall(ctx context.Context, toolCall api.ToolCall) (*Result, error)

ExecuteToolCall executes a tool call from an LLM response

func (*Executor) GetSessionStats

func (e *Executor) GetSessionStats(sessionID string) map[string]interface{}

GetSessionStats returns statistics about a session

func (*Executor) GetTool

func (e *Executor) GetTool(name string) (Tool, bool)

GetTool retrieves a specific tool by name

func (*Executor) ListAvailableTools

func (e *Executor) ListAvailableTools() []Tool

ListAvailableTools returns a list of all available tools

func (*Executor) StartSession

func (e *Executor) StartSession() string

StartSession starts a new session for tracking tool calls

type Parameters

type Parameters struct {
	// Args contains positional arguments
	Args []string

	// Kwargs contains keyword arguments
	Kwargs map[string]interface{}

	// Config provides access to configuration
	Config *configuration.Config

	// Logger for tool execution logging
	Logger *utils.Logger

	// Timeout for tool execution
	Timeout time.Duration
}

Parameters contains the parameters passed to a tool

type PermissionChecker

type PermissionChecker interface {
	// HasPermission checks if the given permissions are granted
	HasPermission(permissions []string) bool

	// CheckToolExecution checks if a tool can be executed
	CheckToolExecution(tool Tool, params Parameters) bool
}

PermissionChecker checks if operations are allowed

type Registry

type Registry interface {
	// RegisterTool registers a new tool
	RegisterTool(tool Tool) error

	// GetTool retrieves a tool by name
	GetTool(name string) (Tool, bool)

	// UnregisterTool removes a tool from the registry
	UnregisterTool(name string) error

	// ListTools returns all registered tools
	ListTools() []Tool

	// ListToolsByCategory returns tools in a specific category
	ListToolsByCategory(category string) []Tool
}

Registry manages available tools

type Result

type Result struct {
	Success       bool                   `json:"success"`
	Output        interface{}            `json:"output"`
	Errors        []string               `json:"errors"`
	Metadata      map[string]interface{} `json:"metadata"`
	ExecutionTime time.Duration          `json:"execution_time"`
}

Result represents the outcome of a tool execution

type SessionData

type SessionData struct {
	SessionID    string
	ToolCalls    map[string]*ToolCallInfo
	CreatedAt    time.Time
	LastActivity time.Time
}

SessionData contains information about a session

type SessionTracker

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

SessionTracker tracks tool calls per session to detect duplicates

func GetGlobalSessionTracker

func GetGlobalSessionTracker() *SessionTracker

GetGlobalSessionTracker returns the global session tracker

func NewSessionTracker

func NewSessionTracker(maxSessions int, cleanupAfter time.Duration) *SessionTracker

NewSessionTracker creates a new session tracker

func (*SessionTracker) EndSession

func (st *SessionTracker) EndSession(sessionID string)

EndSession ends a session and removes its data

func (*SessionTracker) GetRecentDuplicateRequests

func (st *SessionTracker) GetRecentDuplicateRequests(sessionID string, toolName string, limit int) []*ToolCallInfo

GetRecentDuplicateRequests returns information about recent duplicate requests in a session

func (*SessionTracker) GetSessionStats

func (st *SessionTracker) GetSessionStats(sessionID string) map[string]interface{}

GetSessionStats returns statistics about a session

func (*SessionTracker) IsDuplicateRequest

func (st *SessionTracker) IsDuplicateRequest(sessionID, toolName string, arguments map[string]interface{}) (bool, *ToolCallInfo)

IsDuplicateRequest checks if a tool call is a duplicate in the same session

func (*SessionTracker) RecordToolCall

func (st *SessionTracker) RecordToolCall(sessionID, toolName string, arguments map[string]interface{}, response string)

RecordToolCall records a tool call in a session

func (*SessionTracker) StartSession

func (st *SessionTracker) StartSession() string

StartSession starts a new session and returns the session ID

type SimplePermissionChecker

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

SimplePermissionChecker is a basic implementation of PermissionChecker

func NewSimplePermissionChecker

func NewSimplePermissionChecker(allowedPermissions []string) *SimplePermissionChecker

NewSimplePermissionChecker creates a simple permission checker

func (*SimplePermissionChecker) CheckToolExecution

func (p *SimplePermissionChecker) CheckToolExecution(tool Tool, params Parameters) bool

CheckToolExecution checks if a tool can be executed

func (*SimplePermissionChecker) HasPermission

func (p *SimplePermissionChecker) HasPermission(permissions []string) bool

HasPermission checks if the given permissions are granted

type Tool

type Tool interface {
	// Name returns the unique name of the tool
	Name() string

	// Description returns a human-readable description of what the tool does
	Description() string

	// Category returns the category this tool belongs to (e.g., "workspace", "search", "edit")
	Category() string

	// Execute runs the tool with the given context and parameters
	Execute(ctx context.Context, params Parameters) (*Result, error)

	// CanExecute checks if the tool can be executed with the current context
	CanExecute(ctx context.Context, params Parameters) bool

	// RequiredPermissions returns the permissions needed to execute this tool
	RequiredPermissions() []string

	// EstimatedDuration returns an estimate of how long the tool will take to execute
	EstimatedDuration() time.Duration

	// IsAvailable checks if the tool is available in the current environment
	IsAvailable() bool
}

Tool represents a pluggable tool that can be executed

type ToolCallInfo

type ToolCallInfo struct {
	ToolName  string
	Arguments map[string]interface{}
	CallCount int
	FirstCall time.Time
	LastCall  time.Time
	Responses []string // Keep track of responses for cache purposes
}

ToolCallInfo contains information about a specific tool call

Jump to

Keyboard shortcuts

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