tools

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package tools provides tool implementations for the LLM agent system. It includes file operations (read, write, edit, delete), shell commands, search utilities, and integration with LSP servers.

Index

Constants

View Source
const (
	BashToolName = "bash"

	DefaultTimeout = 2 * 60 * 1000  // 2 minutes in milliseconds
	MaxTimeout     = 10 * 60 * 1000 // 10 minutes in milliseconds
	MaxOutputBytes = 50 * 1024      // 50KB
	MaxOutputLines = 2000
)
View Source
const (
	LSToolName = "ls"
	MaxLSFiles = 1000
)
View Source
const (
	MaxPersistBytes    = 100 * 1024 * 1024 // 100MB
	TruncatedHeadLines = 500
	TruncatedTailLines = 500
)
View Source
const (
	ToolResponseTypeText  toolResponseType = "text"
	ToolResponseTypeImage toolResponseType = "image"

	SessionIDContextKey   sessionIDContextKey   = "session_id"
	MessageIDContextKey   messageIDContextKey   = "message_id"
	IsTaskAgentContextKey isTaskAgentContextKey = "is_task_agent"
	AgentIDContextKey     agentIDContextKey     = "agent_id"

	// MaxToolResponseTokens is the maximum number of tokens allowed in a tool response
	// to prevent context overflow. ~1200KB of text content.
	MaxToolResponseTokens = 300_000
)
View Source
const (
	ViewToolName     = "view"
	MaxReadSize      = 250 * 1024
	DefaultReadLimit = 2000
	MaxLineLength    = 2000
)
View Source
const (
	ViewImageToolName = "view_image"
	MaxImageSize      = 5 * 1024 * 1024 // 5MB

)
View Source
const (
	DeleteToolName = "delete"
)
View Source
const (
	EditToolName = "edit"
)
View Source
const (
	FetchToolName = "fetch"
)
View Source
const (
	GlobToolName = "glob"
)
View Source
const (
	GrepToolName = "grep"
)
View Source
const (
	LSPToolName = "lsp"
)
View Source
const (
	MultiEditToolName = "multiedit"
)
View Source
const (
	PatchToolName = "patch"
)
View Source
const (
	PlanTaskToolName = "plan_task"
)
View Source
const (
	SkillToolName = "skill"
)
View Source
const (
	SourcegraphToolName = "sourcegraph"
)
View Source
const (
	StructOutputToolName = "struct_output"
)
View Source
const (
	UpdateStepToolName = "update_step"
)
View Source
const (
	WriteToolName = "write"
)

Variables

This section is empty.

Functions

func CleanupTempDir added in v1.7.0

func CleanupTempDir()

CleanupTempDir removes the process-scoped temp directory and all its contents.

func GetAgentID

func GetAgentID(ctx context.Context) config.AgentName

GetAgentID returns the agent name from context, or empty string if not set

func GetContextValues

func GetContextValues(ctx context.Context) (string, string)

func IsTaskAgent

func IsTaskAgent(ctx context.Context) bool

IsTaskAgent returns true if the context indicates this is a task agent

func NewEmptyResponse

func NewEmptyResponse() toolResponse

func NewImageResponse

func NewImageResponse(content string) toolResponse

func NewTextErrorResponse

func NewTextErrorResponse(content string) toolResponse

func NewTextResponse

func NewTextResponse(content string) toolResponse

func ValidatePathInWorkingDirectory added in v1.5.0

func ValidatePathInWorkingDirectory(filePath string) (string, error)

ValidatePathInWorkingDirectory checks if a path is within the working directory to prevent path traversal attacks. It returns the absolute path if valid, or an error if not. This is a wrapper around fileutil.SecureResolvePath that uses config.WorkingDirectory().

func WithResponseMetadata

func WithResponseMetadata(response toolResponse, metadata any) toolResponse

Types

type BaseTool

type BaseTool interface {
	Info() ToolInfo
	Run(ctx context.Context, params ToolCall) (ToolResponse, error)
}

func NewBashTool

func NewBashTool(permission permission.Service, reg agentregistry.Registry) BaseTool

func NewDeleteTool

func NewDeleteTool(permissions permission.Service, files history.Service, reg agentregistry.Registry) BaseTool

func NewEditTool

func NewEditTool(
	lspService lsp.LspService,
	permissions permission.Service,
	files history.Service,
	reg agentregistry.Registry,
) BaseTool

func NewFetchTool

func NewFetchTool(permissions permission.Service) BaseTool

func NewGlobTool

func NewGlobTool() BaseTool

func NewGrepTool

func NewGrepTool() BaseTool

func NewLsTool

func NewLsTool(cfg config.Configurator) BaseTool

func NewLspTool

func NewLspTool(lspService lsp.LspService) BaseTool

func NewMultiEditTool

func NewMultiEditTool(lspService lsp.LspService, permissions permission.Service, files history.Service, reg agentregistry.Registry) BaseTool

func NewPatchTool

func NewPatchTool(lspService lsp.LspService, permissions permission.Service, files history.Service, reg agentregistry.Registry) BaseTool

func NewPlanTaskTool added in v1.5.0

func NewPlanTaskTool(taskService task.Service) BaseTool

func NewSkillTool

func NewSkillTool(permissions permission.Service, reg agentregistry.Registry) BaseTool

NewSkillTool creates a new skill tool instance.

func NewSourcegraphTool

func NewSourcegraphTool() BaseTool

func NewStructOutputTool added in v1.3.0

func NewStructOutputTool(schema map[string]any) BaseTool

func NewUpdateStepTool added in v1.5.0

func NewUpdateStepTool(taskService task.Service) BaseTool

func NewViewImageTool

func NewViewImageTool() BaseTool

func NewViewTool

func NewViewTool(lspService lsp.LspService) BaseTool

func NewWriteTool

func NewWriteTool(lspService lsp.LspService, permissions permission.Service, files history.Service, reg agentregistry.Registry) BaseTool

type BashParams

type BashParams struct {
	Command     string `json:"command"`
	Timeout     int    `json:"timeout"`
	Workdir     string `json:"workdir"`
	Description string `json:"description"`
}

type BashPermissionsParams

type BashPermissionsParams struct {
	Command string `json:"command"`
	Timeout int    `json:"timeout"`
	Workdir string `json:"workdir"`
}

type BashResponseMetadata

type BashResponseMetadata struct {
	StartTime    int64  `json:"start_time"`
	EndTime      int64  `json:"end_time"`
	Description  string `json:"description,omitempty"`
	ExitCode     int    `json:"exit_code"`
	TempFilePath string `json:"temp_file_path,omitempty"`
}

type DeleteParams

type DeleteParams struct {
	Path string `json:"path"`
}

type DeletePermissionsParams

type DeletePermissionsParams struct {
	Path string `json:"path"`
	Diff string `json:"diff"`
}

type DeleteResponseMetadata

type DeleteResponseMetadata struct {
	Diff         string `json:"diff"`
	Removals     int    `json:"removals"`
	FilesDeleted int    `json:"files_deleted"`
}

type EditParams

type EditParams struct {
	FilePath   string `json:"file_path"`
	OldString  string `json:"old_string"`
	NewString  string `json:"new_string"`
	ReplaceAll bool   `json:"replace_all,omitempty"`
}

type EditPermissionsParams

type EditPermissionsParams struct {
	FilePath string `json:"file_path"`
	Diff     string `json:"diff"`
}

type EditResponseMetadata

type EditResponseMetadata struct {
	Diff      string `json:"diff"`
	Additions int    `json:"additions"`
	Removals  int    `json:"removals"`
}

type FetchParams

type FetchParams struct {
	URL     string `json:"url"`
	Format  string `json:"format"`
	Timeout int    `json:"timeout,omitempty"`
}

type FetchPermissionsParams

type FetchPermissionsParams = FetchParams

type GlobParams

type GlobParams struct {
	Pattern string `json:"pattern"`
	Path    string `json:"path"`
}

type GlobResponseMetadata

type GlobResponseMetadata struct {
	NumberOfFiles int  `json:"number_of_files"`
	Truncated     bool `json:"truncated"`
}

type GrepParams

type GrepParams struct {
	Pattern     string `json:"pattern"`
	Path        string `json:"path"`
	Include     string `json:"include"`
	LiteralText bool   `json:"literal_text"`
}

type GrepResponseMetadata

type GrepResponseMetadata struct {
	NumberOfMatches int  `json:"number_of_matches"`
	Truncated       bool `json:"truncated"`
}

type LSPToolMetadata

type LSPToolMetadata struct {
	Title string `json:"title"`
}

type LSParams

type LSParams struct {
	Path   string   `json:"path"`
	Ignore []string `json:"ignore"`
}

type LSResponseMetadata

type LSResponseMetadata struct {
	NumberOfFiles int  `json:"number_of_files"`
	Truncated     bool `json:"truncated"`
}

type LineScanner

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

func NewLineScanner

func NewLineScanner(r io.Reader) *LineScanner

func (*LineScanner) Err

func (s *LineScanner) Err() error

func (*LineScanner) Scan

func (s *LineScanner) Scan() bool

func (*LineScanner) Text

func (s *LineScanner) Text() string

type LspParams

type LspParams struct {
	Operation string `json:"operation"`
	FilePath  string `json:"filePath"`
	Line      int    `json:"line"`
	Character int    `json:"character"`
}

type MultiEditItem

type MultiEditItem struct {
	OldString  string `json:"old_string"`
	NewString  string `json:"new_string"`
	ReplaceAll bool   `json:"replace_all,omitempty"`
}

type MultiEditParams

type MultiEditParams struct {
	FilePath string          `json:"file_path"`
	Edits    []MultiEditItem `json:"edits"`
}

type MultiEditPermissionEdit added in v1.7.0

type MultiEditPermissionEdit struct {
	Diff       string `json:"diff"`
	LineNumber int    `json:"line_number"`
}

type MultiEditPermissionsParams added in v1.7.0

type MultiEditPermissionsParams struct {
	FilePath string                    `json:"file_path"`
	Edits    []MultiEditPermissionEdit `json:"edits"`
}

type MultiEditResponseMetadata

type MultiEditResponseMetadata struct {
	Diff      string `json:"diff"`
	Additions int    `json:"additions"`
	Removals  int    `json:"removals"`
}

type PatchParams

type PatchParams struct {
	PatchText string `json:"patch_text"`
}

type PatchResponseMetadata

type PatchResponseMetadata struct {
	FilesChanged []string `json:"files_changed"`
	Additions    int      `json:"additions"`
	Removals     int      `json:"removals"`
}

type PlanTaskParams added in v1.5.0

type PlanTaskParams struct {
	Title string      `json:"title"`
	Steps []task.Step `json:"steps"`
}

type PlanTaskResponseMetadata added in v1.5.0

type PlanTaskResponseMetadata struct {
	TaskID string `json:"task_id"`
}

type SkillParams

type SkillParams struct {
	Name string `json:"name"`
}

type SourcegraphParams

type SourcegraphParams struct {
	Query         string `json:"query"`
	Count         int    `json:"count,omitempty"`
	ContextWindow int    `json:"context_window,omitempty"`
	Timeout       int    `json:"timeout,omitempty"`
}

type ToolCall

type ToolCall struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Input string `json:"input"`
}

type ToolInfo

type ToolInfo struct {
	Name        string
	Description string
	Parameters  map[string]any
	Required    []string
}

type ToolResponse

type ToolResponse = toolResponse

ToolResponse is the public interface for tool responses

type TreeNode

type TreeNode struct {
	Name     string      `json:"name"`
	Path     string      `json:"path"`
	Type     string      `json:"type"` // "file" or "directory"
	Children []*TreeNode `json:"children,omitempty"`
}

type UpdateStepParams added in v1.5.0

type UpdateStepParams struct {
	TaskID    string `json:"task_id"`
	StepIndex int    `json:"step_index"`
	Status    string `json:"status"`
	Output    string `json:"output,omitempty"`
	Error     string `json:"error,omitempty"`
}

type UpdateStepResponseMetadata added in v1.5.0

type UpdateStepResponseMetadata struct {
	TaskID         string `json:"task_id"`
	StepIndex      int    `json:"step_index"`
	PreviousStatus string `json:"previous_status"`
	CurrentStatus  string `json:"current_status"`
	NextStepIndex  int    `json:"next_step_index,omitempty"`
	IsTaskComplete bool   `json:"is_task_complete"`
}

type ViewImageParams

type ViewImageParams struct {
	FilePath string `json:"file_path"`
}

type ViewImageResponseMetadata

type ViewImageResponseMetadata struct {
	MimeType string `json:"mime_type"`
	FilePath string `json:"file_path"`
}

type ViewParams

type ViewParams struct {
	FilePath string `json:"file_path"`
	Offset   int    `json:"offset"`
	Limit    int    `json:"limit"`
}

type ViewResponseMetadata

type ViewResponseMetadata struct {
	FilePath string `json:"file_path"`
	Content  string `json:"content"`
}

type WriteParams

type WriteParams struct {
	FilePath string `json:"file_path"`
	Content  string `json:"content"`
}

type WritePermissionsParams

type WritePermissionsParams struct {
	FilePath string `json:"file_path"`
	Diff     string `json:"diff"`
}

type WriteResponseMetadata

type WriteResponseMetadata struct {
	Diff      string `json:"diff"`
	Additions int    `json:"additions"`
	Removals  int    `json:"removals"`
}

Directories

Path Synopsis
Package mock_tools is a generated GoMock package.
Package mock_tools is a generated GoMock package.

Jump to

Keyboard shortcuts

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