tools

package
v0.0.0-...-14e3c9d Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package tools provides tool implementations for the agent runtime

Package tools provides tool implementations for the agent runtime

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteFile

func DeleteFile(path string) error

func FileExists

func FileExists(path string) bool

func LoadToolsFromConfig

func LoadToolsFromConfig(toolRegistry *ToolRegistry) error

func ReadFile

func ReadFile(path string) (string, error)

func SaveToolsToConfig

func SaveToolsToConfig(toolRegistry *ToolRegistry) error

func WriteFile

func WriteFile(path, content string) error

Types

type Argument

type Argument struct {
	Name           string `json:"name"`
	Type           string `json:"type"`
	Description    string `json:"description"`
	Required       bool   `json:"required"`
	ArgumentFormat string `json:"argument_format,omitempty"`
}

type Bundle

type Bundle struct {
	Path         string
	StateCommand string
	Commands     []*Command
}

type Command

type Command struct {
	Name           string     `json:"name"`
	Description    string     `json:"description"`
	Arguments      []Argument `json:"arguments"`
	Category       string     `json:"category"`
	Timeout        int        `json:"timeout"`
	EndName        string     `json:"end_name,omitempty"`
	InvokeFormat   string     `json:"invoke_format,omitempty"`
	ArgumentFormat string     `json:"argument_format,omitempty"`
}

type CppTool

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

func NewCppTool

func NewCppTool(name, description string) (*CppTool, error)

func (*CppTool) Close

func (t *CppTool) Close() error

func (*CppTool) Description

func (t *CppTool) Description() string

func (*CppTool) Execute

func (t *CppTool) Execute(ctx context.Context, params map[string]interface{}) (interface{}, error)

func (*CppTool) Name

func (t *CppTool) Name() string

type EditAnthropicTool

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

EditAnthropicTool implements the Tool interface for Anthropic-specific editing

func (*EditAnthropicTool) Description

func (t *EditAnthropicTool) Description() string

func (*EditAnthropicTool) Execute

func (t *EditAnthropicTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute performs Anthropic-specific editing operations

func (*EditAnthropicTool) Name

func (t *EditAnthropicTool) Name() string

type EditLintingTool

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

EditLintingTool implements the Tool interface for linting-based editing

func (*EditLintingTool) Description

func (t *EditLintingTool) Description() string

func (*EditLintingTool) Execute

func (t *EditLintingTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute performs linting-based editing operations

func (*EditLintingTool) Name

func (t *EditLintingTool) Name() string

type EditReplaceTool

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

EditReplaceTool implements the Tool interface for replacing text in files

func (*EditReplaceTool) Description

func (t *EditReplaceTool) Description() string

func (*EditReplaceTool) Execute

func (t *EditReplaceTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute replaces occurrences of a string in a file

func (*EditReplaceTool) Name

func (t *EditReplaceTool) Name() string

type EditRewriteTool

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

EditRewriteTool implements the Tool interface for rewriting code

func (*EditRewriteTool) Description

func (t *EditRewriteTool) Description() string

func (*EditRewriteTool) Execute

func (t *EditRewriteTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute performs code rewriting operations

func (*EditRewriteTool) Name

func (t *EditRewriteTool) Name() string

type FileTool

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

FileTool implements the Tool interface for file operations

func (*FileTool) Description

func (t *FileTool) Description() string

Description returns the description of the file tool

func (*FileTool) Execute

func (t *FileTool) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

Execute performs file operations based on the provided arguments

func (*FileTool) Name

func (t *FileTool) Name() string

Name returns the name of the file tool

type FilemapTool

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

FilemapTool implements the Tool interface for file mapping operations

func (*FilemapTool) Description

func (t *FilemapTool) Description() string

func (*FilemapTool) Execute

func (t *FilemapTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute performs file mapping operations

func (*FilemapTool) Name

func (t *FilemapTool) Name() string

type ForfeitTool

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

ForfeitTool implements the Tool interface for forfeiting tasks

func (*ForfeitTool) Description

func (t *ForfeitTool) Description() string

func (*ForfeitTool) Execute

func (t *ForfeitTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute performs task forfeiting operations

func (*ForfeitTool) Name

func (t *ForfeitTool) Name() string

type HTTPTool

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

HTTPTool implements the Tool interface for HTTP requests

func (*HTTPTool) Description

func (t *HTTPTool) Description() string

Description returns the description of the HTTP tool

func (*HTTPTool) Execute

func (t *HTTPTool) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

Execute performs HTTP requests with the provided arguments

func (*HTTPTool) Name

func (t *HTTPTool) Name() string

Name returns the name of the HTTP tool

type Handler

type Handler struct {
	Config      *ToolConfig // Use ToolConfig from tools package
	Definitions map[string]ToolDefinition
	Registry    *Registry // Reference to the tool registry
}

Handler manages tool execution and parsing

func NewHandler

func NewHandler(config *ToolConfig, definitions []ToolDefinition, registry *Registry) (*Handler, error)

NewHandler creates a new tool handler with the provided configuration and registry

func (*Handler) ExecuteAction

func (h *Handler) ExecuteAction(ctx context.Context, action string, environment *env.SWEEnv) (observation string, err error)

ExecuteAction executes a tool action with the provided context and environment

func (*Handler) GetState

func (h *Handler) GetState(environment *env.SWEEnv) (map[string]interface{}, error)

GetState retrieves the current state of the environment

func (*Handler) Install

func (h *Handler) Install(environment *env.SWEEnv) error

Install sets up the tools in the provided environment

func (*Handler) ParseActions

func (h *Handler) ParseActions(output string) (thought string, action string, err error)

ParseActions parses the model output to extract thought and action

type PythonTool

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

func NewPythonTool

func NewPythonTool(name, description string) (*PythonTool, error)

func (*PythonTool) Close

func (t *PythonTool) Close() error

func (*PythonTool) Description

func (t *PythonTool) Description() string

func (*PythonTool) Execute

func (t *PythonTool) Execute(ctx context.Context, params map[string]interface{}) (interface{}, error)

func (*PythonTool) Name

func (t *PythonTool) Name() string

type Registry

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

Registry manages the collection of available tools

func NewRegistry

func NewRegistry(cfg *config.Config, toolCfg *ToolConfig) (*Registry, error)

NewRegistry creates a new tool registry with the provided configuration

func (*Registry) Get

func (r *Registry) Get(name string) (ToolWithEnv, error)

Get retrieves a tool from the registry by name

func (*Registry) Register

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

Register adds a tool to the registry

type ReviewOnSubmitMTool

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

ReviewOnSubmitMTool implements the Tool interface for multi-submission reviews

func (*ReviewOnSubmitMTool) Description

func (t *ReviewOnSubmitMTool) Description() string

func (*ReviewOnSubmitMTool) Execute

func (t *ReviewOnSubmitMTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute performs multi-submission review operations

func (*ReviewOnSubmitMTool) Name

func (t *ReviewOnSubmitMTool) Name() string

type ReviewOnSubmitTool

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

ReviewOnSubmitTool implements the Tool interface for reviewing submissions

func (*ReviewOnSubmitTool) Description

func (t *ReviewOnSubmitTool) Description() string

func (*ReviewOnSubmitTool) Execute

func (t *ReviewOnSubmitTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute performs submission review operations

func (*ReviewOnSubmitTool) Name

func (t *ReviewOnSubmitTool) Name() string

type SearchTool

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

SearchTool implements the Tool interface for searching in files

func (*SearchTool) Description

func (t *SearchTool) Description() string

func (*SearchTool) Execute

func (t *SearchTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute searches for a pattern in files

func (*SearchTool) Name

func (t *SearchTool) Name() string

type ShellTool

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

ShellTool implements the Tool interface for executing shell commands

func (*ShellTool) Description

func (t *ShellTool) Description() string

Description returns the description of the shell tool

func (*ShellTool) Execute

func (t *ShellTool) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

Execute runs a shell command with the provided arguments

func (*ShellTool) Name

func (t *ShellTool) Name() string

Name returns the name of the shell tool

type SubmitTool

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

SubmitTool implements the Tool interface for submitting solutions

func (*SubmitTool) Description

func (t *SubmitTool) Description() string

func (*SubmitTool) Execute

func (t *SubmitTool) Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error)

Execute submits the final solution or patch

func (*SubmitTool) Name

func (t *SubmitTool) Name() string

type Tool

type Tool interface {
	Name() string

	Description() string

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

Tool is the interface that all tools must implement

type ToolConfig

type ToolConfig struct {
	ExecutionTimeout        time.Duration          `json:"execution_timeout"`
	MaxOutputSize           int                    `json:"max_output_size"`
	ToolsDir                string                 `json:"tools_dir"`
	Filter                  ToolFilterConfig       `json:"filter"`
	Bundles                 []Bundle               `json:"bundles"`
	EnvVariables            map[string]interface{} `json:"env_variables"`
	RegistryVariables       map[string]interface{} `json:"registry_variables"`
	SubmitCommand           string                 `json:"submit_command"`
	EnableBashTool          bool                   `json:"enable_bash_tool"`
	FormatErrorTemplate     string                 `json:"format_error_template"`
	MultiLineCommandEndings map[string]string      `json:"multi_line_command_endings"`
	SubmitCommandEndName    string                 `json:"submit_command_end_name"`
	ResetCommands           []string               `json:"reset_commands"`
	InstallTimeout          int                    `json:"install_timeout"`
	TotalExecutionTimeout   int                    `json:"total_execution_timeout"`
	MaxConsecutiveTimeouts  int                    `json:"max_consecutive_timeouts"`
}

type ToolDefinition

type ToolDefinition struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"input_schema"` // JSON schema for input
}

type ToolFilterConfig

type ToolFilterConfig struct {
	BlocklistErrorTemplate string            `json:"blocklist_error_template"`
	Blocklist              []string          `json:"blocklist"`
	BlocklistStandalone    []string          `json:"blocklist_standalone"`
	BlockUnlessRegex       map[string]string `json:"block_unless_regex"`
}

type ToolRegistry

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

func NewToolRegistry

func NewToolRegistry(config *ToolConfig, scriptRunner *python.ScriptRunner) (*ToolRegistry, error)

func (*ToolRegistry) ExecuteAction

func (r *ToolRegistry) ExecuteAction(action string, env interface{}) (string, error)

func (*ToolRegistry) GetCommand

func (r *ToolRegistry) GetCommand(name string) (*Command, error)

func (*ToolRegistry) GetState

func (r *ToolRegistry) GetState(env *env.SWEEnv) (map[string]interface{}, error)

func (*ToolRegistry) Install

func (r *ToolRegistry) Install(env *env.SWEEnv) error

func (*ToolRegistry) ListCommands

func (r *ToolRegistry) ListCommands() []*Command

func (*ToolRegistry) LoadTools

func (r *ToolRegistry) LoadTools(toolsPath string) error

func (*ToolRegistry) Reset

func (r *ToolRegistry) Reset(env *env.SWEEnv) error

func (*ToolRegistry) SetMockState

func (r *ToolRegistry) SetMockState(state map[string]interface{})

type ToolWithEnv

type ToolWithEnv interface {
	Name() string
	Description() string
	Execute(ctx context.Context, args map[string]interface{}, environment *env.SWEEnv) (string, error) // Observation, error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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