Documentation
¶
Index ¶
- Variables
- func ExtractFilePath(input json.RawMessage) string
- func ListUndoHistory() string
- type BashTool
- type DiffTool
- type EditTool
- func (t *EditTool) Description() string
- func (t *EditTool) Execute(_ context.Context, input json.RawMessage) (Result, error)
- func (t *EditTool) GetFilePath(input json.RawMessage) string
- func (t *EditTool) InputSchema() anthropic.ToolInputSchemaParam
- func (t *EditTool) IsWriteOperation() bool
- func (t *EditTool) Name() string
- type FileAccessor
- type FileChange
- type FileHistory
- func (h *FileHistory) Clear()
- func (h *FileHistory) GetAllChanges() []FileChange
- func (h *FileHistory) GetChanges(filePath string) []FileChange
- func (h *FileHistory) Len() int
- func (h *FileHistory) PopChange(filePath string) *FileChange
- func (h *FileHistory) PopMostRecent() *FileChange
- func (h *FileHistory) RecordChange(filePath, toolName, description string) error
- type GitStatus
- type GitTool
- type GlobTool
- type GrepTool
- type InputNormalizer
- type LSPTool
- type ListDirTool
- type MoveTool
- type MultiReadTool
- type ParallelSafeTool
- type ProgressUpdate
- type ReadTool
- type Registry
- type Result
- type TaskResult
- type TodoTool
- type Tool
- type ToolCall
- type ToolExecutor
- type ToolTask
- type TreeTool
- type UndoTool
- type WebFetchTool
- type WebSearchTool
- type WorkerPool
- type WriteTool
- func (t *WriteTool) Description() string
- func (t *WriteTool) Execute(_ context.Context, input json.RawMessage) (Result, error)
- func (t *WriteTool) GetFilePath(input json.RawMessage) string
- func (t *WriteTool) InputSchema() anthropic.ToolInputSchemaParam
- func (t *WriteTool) IsWriteOperation() bool
- func (t *WriteTool) Name() string
Constants ¶
This section is empty.
Variables ¶
var DefaultFileHistory = NewFileHistory(100)
DefaultFileHistory is the global history instance used by write tools.
Functions ¶
func ExtractFilePath ¶ added in v0.2.0
func ExtractFilePath(input json.RawMessage) string
ExtractFilePath is a helper to extract file_path from common tool inputs.
func ListUndoHistory ¶ added in v0.3.0
func ListUndoHistory() string
ListUndoHistory returns a formatted string of all available undo operations.
Types ¶
type BashTool ¶
type BashTool struct {
WorkDir string
}
BashTool executes shell commands.
func (*BashTool) Description ¶
func (*BashTool) InputSchema ¶
func (t *BashTool) InputSchema() anthropic.ToolInputSchemaParam
func (*BashTool) NormalizeInput ¶ added in v0.3.0
func (t *BashTool) NormalizeInput(input json.RawMessage) json.RawMessage
NormalizeInput strips redundant "cd <workdir> &&" prefixes from bash commands. This ensures permission checks and execution see the actual command being run.
type DiffTool ¶ added in v0.3.0
type DiffTool struct{}
DiffTool compares two files or a file against provided content. It implements ParallelSafeTool since it only reads data.
func (*DiffTool) Description ¶ added in v0.3.0
func (*DiffTool) InputSchema ¶ added in v0.3.0
func (t *DiffTool) InputSchema() anthropic.ToolInputSchemaParam
func (*DiffTool) IsParallelSafe ¶ added in v0.3.0
IsParallelSafe returns true since diff operations don't modify state.
type EditTool ¶
type EditTool struct {
// History is the file history to record changes to. If nil, uses DefaultFileHistory.
History *FileHistory
}
EditTool performs string-replacement edits on files. It implements FileAccessor to enable conflict detection.
func (*EditTool) Description ¶
func (*EditTool) GetFilePath ¶ added in v0.2.0
func (t *EditTool) GetFilePath(input json.RawMessage) string
GetFilePath extracts the target file path from the input.
func (*EditTool) InputSchema ¶
func (t *EditTool) InputSchema() anthropic.ToolInputSchemaParam
func (*EditTool) IsWriteOperation ¶ added in v0.2.0
IsWriteOperation returns true since this tool modifies files.
type FileAccessor ¶ added in v0.2.0
type FileAccessor interface {
// GetFilePath extracts the target file path from the tool input.
// Returns empty string if the tool doesn't target a specific file.
GetFilePath(input json.RawMessage) string
// IsWriteOperation returns true if this tool modifies the file system.
IsWriteOperation() bool
}
FileAccessor is implemented by tools that access files, enabling conflict detection for parallel execution. Write operations to the same file must be serialized.
type FileChange ¶ added in v0.3.0
type FileChange struct {
FilePath string
OldContent []byte // nil means file didn't exist before
Existed bool // whether the file existed before the change
Timestamp time.Time
ToolName string // which tool made the change
Description string // human-readable description of what changed
}
FileChange represents a single file modification that can be undone.
type FileHistory ¶ added in v0.3.0
type FileHistory struct {
// contains filtered or unexported fields
}
FileHistory tracks file changes for undo operations. It maintains a stack of changes per file, allowing multiple undos.
func NewFileHistory ¶ added in v0.3.0
func NewFileHistory(maxSize int) *FileHistory
NewFileHistory creates a new FileHistory with the given max size.
func (*FileHistory) Clear ¶ added in v0.3.0
func (h *FileHistory) Clear()
Clear removes all recorded changes.
func (*FileHistory) GetAllChanges ¶ added in v0.3.0
func (h *FileHistory) GetAllChanges() []FileChange
GetAllChanges returns all recorded changes, most recent first.
func (*FileHistory) GetChanges ¶ added in v0.3.0
func (h *FileHistory) GetChanges(filePath string) []FileChange
GetChanges returns the change history for a specific file, most recent first.
func (*FileHistory) Len ¶ added in v0.3.0
func (h *FileHistory) Len() int
Len returns the number of recorded changes.
func (*FileHistory) PopChange ¶ added in v0.3.0
func (h *FileHistory) PopChange(filePath string) *FileChange
PopChange removes and returns the most recent change for a file. Returns nil if no changes exist for the file.
func (*FileHistory) PopMostRecent ¶ added in v0.3.0
func (h *FileHistory) PopMostRecent() *FileChange
PopMostRecent removes and returns the most recent change across all files. Returns nil if no changes exist.
func (*FileHistory) RecordChange ¶ added in v0.3.0
func (h *FileHistory) RecordChange(filePath, toolName, description string) error
RecordChange saves the current state of a file before it is modified. If the file doesn't exist, it records that fact so undo can delete it.
type GitStatus ¶ added in v0.4.2
type GitStatus struct {
Branch string `json:"branch"`
Ahead int `json:"ahead,omitempty"`
Behind int `json:"behind,omitempty"`
Staged []string `json:"staged,omitempty"`
Modified []string `json:"modified,omitempty"`
Untracked []string `json:"untracked,omitempty"`
Deleted []string `json:"deleted,omitempty"`
Renamed map[string]string `json:"renamed,omitempty"`
HasConflicts bool `json:"has_conflicts"`
IsClean bool `json:"is_clean"`
RemoteTracking string `json:"remote_tracking,omitempty"`
}
GitStatus represents the structured output of git status.
type GitTool ¶ added in v0.4.2
type GitTool struct {
WorkDir string
}
GitTool provides git version control operations with enhanced safety and structure.
func (*GitTool) Description ¶ added in v0.4.2
func (*GitTool) InputSchema ¶ added in v0.4.2
func (t *GitTool) InputSchema() anthropic.ToolInputSchemaParam
type GlobTool ¶
type GlobTool struct {
WorkDir string
}
GlobTool searches for files matching a glob pattern. It implements ParallelSafeTool since it only reads directory listings.
func (*GlobTool) Description ¶
func (*GlobTool) InputSchema ¶
func (t *GlobTool) InputSchema() anthropic.ToolInputSchemaParam
func (*GlobTool) IsParallelSafe ¶ added in v0.2.0
IsParallelSafe returns true since glob operations don't modify state.
type GrepTool ¶
type GrepTool struct {
WorkDir string
}
GrepTool searches file contents for a regular expression. It implements ParallelSafeTool since it only reads file contents.
func (*GrepTool) Description ¶
func (*GrepTool) InputSchema ¶
func (t *GrepTool) InputSchema() anthropic.ToolInputSchemaParam
func (*GrepTool) IsParallelSafe ¶ added in v0.2.0
IsParallelSafe returns true since grep operations don't modify state.
type InputNormalizer ¶ added in v0.3.0
type InputNormalizer interface {
NormalizeInput(input json.RawMessage) json.RawMessage
}
InputNormalizer is an optional interface for tools that need to normalize their input before permission checking and execution. For example, the bash tool strips redundant "cd <workdir> &&" prefixes since commands already run in the working directory.
type LSPTool ¶ added in v0.3.0
LSPTool provides code navigation using language servers.
func (*LSPTool) Description ¶ added in v0.3.0
Description returns a description of the tool.
func (*LSPTool) InputSchema ¶ added in v0.3.0
func (t *LSPTool) InputSchema() anthropic.ToolInputSchemaParam
InputSchema returns the JSON schema for the tool input.
func (*LSPTool) IsParallelSafe ¶ added in v0.3.0
IsParallelSafe returns true because LSP operations are read-only.
type ListDirTool ¶ added in v0.3.0
type ListDirTool struct {
WorkDir string
}
ListDirTool lists directory contents. It implements ParallelSafeTool since it only reads data.
func (*ListDirTool) Description ¶ added in v0.3.0
func (t *ListDirTool) Description() string
func (*ListDirTool) Execute ¶ added in v0.3.0
func (t *ListDirTool) Execute(_ context.Context, input json.RawMessage) (Result, error)
func (*ListDirTool) InputSchema ¶ added in v0.3.0
func (t *ListDirTool) InputSchema() anthropic.ToolInputSchemaParam
func (*ListDirTool) IsParallelSafe ¶ added in v0.3.0
func (t *ListDirTool) IsParallelSafe() bool
IsParallelSafe returns true since list operations don't modify state.
func (*ListDirTool) Name ¶ added in v0.3.0
func (t *ListDirTool) Name() string
type MoveTool ¶ added in v0.2.0
type MoveTool struct{}
MoveTool moves or renames files and directories.
func (*MoveTool) Description ¶ added in v0.2.0
func (*MoveTool) InputSchema ¶ added in v0.2.0
func (t *MoveTool) InputSchema() anthropic.ToolInputSchemaParam
type MultiReadTool ¶ added in v0.3.0
type MultiReadTool struct{}
MultiReadTool reads multiple files in a single call. It implements ParallelSafeTool since it only reads data.
func (*MultiReadTool) Description ¶ added in v0.3.0
func (t *MultiReadTool) Description() string
func (*MultiReadTool) Execute ¶ added in v0.3.0
func (t *MultiReadTool) Execute(_ context.Context, input json.RawMessage) (Result, error)
func (*MultiReadTool) InputSchema ¶ added in v0.3.0
func (t *MultiReadTool) InputSchema() anthropic.ToolInputSchemaParam
func (*MultiReadTool) IsParallelSafe ¶ added in v0.3.0
func (t *MultiReadTool) IsParallelSafe() bool
IsParallelSafe returns true since read operations don't modify state.
func (*MultiReadTool) Name ¶ added in v0.3.0
func (t *MultiReadTool) Name() string
type ParallelSafeTool ¶ added in v0.2.0
ParallelSafeTool indicates a tool can safely run concurrently with other parallel-safe tools. Tools that only read data (e.g., read, glob, grep) should implement this interface.
type ProgressUpdate ¶ added in v0.2.0
type ProgressUpdate struct {
TotalTasks int
CompletedTasks int
InProgress []string // Tool names currently executing
}
ProgressUpdate reports progress during parallel tool execution.
type ReadTool ¶
type ReadTool struct{}
ReadTool reads file contents with optional offset and limit. It implements ParallelSafeTool since it only reads data.
func (*ReadTool) Description ¶
func (*ReadTool) InputSchema ¶
func (t *ReadTool) InputSchema() anthropic.ToolInputSchemaParam
func (*ReadTool) IsParallelSafe ¶ added in v0.2.0
IsParallelSafe returns true since read operations don't modify state.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages the set of tools available to the agent.
func (*Registry) Register ¶
Register adds a tool to the registry. Returns an error if a tool with the same name is already registered.
func (*Registry) ToolParams ¶
func (r *Registry) ToolParams() []anthropic.ToolUnionParam
ToolParams returns the Anthropic API tool parameter definitions for all registered tools.
type TaskResult ¶ added in v0.2.0
TaskResult holds the outcome of a tool execution.
type TodoTool ¶ added in v0.3.0
TodoTool manages the task list for tracking progress.
func (*TodoTool) Description ¶ added in v0.3.0
func (*TodoTool) InputSchema ¶ added in v0.3.0
func (t *TodoTool) InputSchema() anthropic.ToolInputSchemaParam
func (*TodoTool) IsParallelSafe ¶ added in v0.3.0
IsParallelSafe returns false since todo updates should be sequential.
type Tool ¶
type Tool interface {
Name() string
Description() string
InputSchema() anthropic.ToolInputSchemaParam
Execute(ctx context.Context, input json.RawMessage) (Result, error)
}
Tool defines the interface that all agent tools must implement.
type ToolCall ¶ added in v0.2.0
type ToolCall struct {
ID string
Name string
Input json.RawMessage
}
ToolCall represents a single tool invocation request.
type ToolExecutor ¶ added in v0.2.0
type ToolExecutor struct {
// contains filtered or unexported fields
}
ToolExecutor orchestrates tool execution, running parallel-safe tools concurrently while serializing conflicting operations.
func NewToolExecutor ¶ added in v0.2.0
func NewToolExecutor(registry *Registry, workers int) *ToolExecutor
NewToolExecutor creates a new executor with the specified number of workers.
func (*ToolExecutor) CanParallelize ¶ added in v0.2.0
func (e *ToolExecutor) CanParallelize(t Tool) bool
CanParallelize checks if a tool is safe for parallel execution.
func (*ToolExecutor) ExecuteTools ¶ added in v0.2.0
func (e *ToolExecutor) ExecuteTools(ctx context.Context, calls []ToolCall, progressCh chan<- ProgressUpdate) ([]TaskResult, error)
ExecuteTools runs the given tool calls, parallelizing where safe. Tools are grouped by conflict detection: parallel-safe read operations run concurrently, while write operations to the same file are serialized. Results are returned in the same order as the input calls.
type ToolTask ¶ added in v0.2.0
type ToolTask struct {
Call ToolCall
Tool Tool
Ctx context.Context
ResultCh chan<- TaskResult
}
ToolTask is an internal structure for the worker pool.
type TreeTool ¶ added in v0.3.0
type TreeTool struct {
WorkDir string
}
TreeTool displays directory structure as a tree. It implements ParallelSafeTool since it only reads data.
func (*TreeTool) Description ¶ added in v0.3.0
func (*TreeTool) InputSchema ¶ added in v0.3.0
func (t *TreeTool) InputSchema() anthropic.ToolInputSchemaParam
func (*TreeTool) IsParallelSafe ¶ added in v0.3.0
IsParallelSafe returns true since tree operations don't modify state.
type UndoTool ¶ added in v0.3.0
type UndoTool struct {
// History is the file history to undo from. If nil, uses DefaultFileHistory.
History *FileHistory
}
UndoTool reverts recent file changes made by write and edit tools.
func (*UndoTool) Description ¶ added in v0.3.0
func (*UndoTool) InputSchema ¶ added in v0.3.0
func (t *UndoTool) InputSchema() anthropic.ToolInputSchemaParam
type WebFetchTool ¶ added in v0.3.0
type WebFetchTool struct{}
WebFetchTool fetches content from a URL. It implements ParallelSafeTool since it only reads external data.
func (*WebFetchTool) Description ¶ added in v0.3.0
func (t *WebFetchTool) Description() string
func (*WebFetchTool) Execute ¶ added in v0.3.0
func (t *WebFetchTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)
func (*WebFetchTool) InputSchema ¶ added in v0.3.0
func (t *WebFetchTool) InputSchema() anthropic.ToolInputSchemaParam
func (*WebFetchTool) IsParallelSafe ¶ added in v0.3.0
func (t *WebFetchTool) IsParallelSafe() bool
IsParallelSafe returns true since fetch operations don't modify local state.
func (*WebFetchTool) Name ¶ added in v0.3.0
func (t *WebFetchTool) Name() string
type WebSearchTool ¶ added in v0.3.0
type WebSearchTool struct{}
WebSearchTool searches the web using DuckDuckGo. It implements ParallelSafeTool since it only reads external data.
func (*WebSearchTool) Description ¶ added in v0.3.0
func (t *WebSearchTool) Description() string
func (*WebSearchTool) Execute ¶ added in v0.3.0
func (t *WebSearchTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)
func (*WebSearchTool) InputSchema ¶ added in v0.3.0
func (t *WebSearchTool) InputSchema() anthropic.ToolInputSchemaParam
func (*WebSearchTool) IsParallelSafe ¶ added in v0.3.0
func (t *WebSearchTool) IsParallelSafe() bool
IsParallelSafe returns true since search operations don't modify local state.
func (*WebSearchTool) Name ¶ added in v0.3.0
func (t *WebSearchTool) Name() string
type WorkerPool ¶ added in v0.2.0
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool manages a pool of workers for concurrent tool execution.
func NewWorkerPool ¶ added in v0.2.0
func NewWorkerPool(workers int) *WorkerPool
NewWorkerPool creates a new worker pool with the specified number of workers.
func (*WorkerPool) ExecuteBatch ¶ added in v0.2.0
func (p *WorkerPool) ExecuteBatch(ctx context.Context, tasks []ToolTask, progressCh chan<- ProgressUpdate) []TaskResult
ExecuteBatch runs multiple tool tasks concurrently, respecting the worker limit. Results are returned in the same order as the input tasks. The progressCh receives updates as tasks complete (can be nil to disable).
type WriteTool ¶
type WriteTool struct {
// History is the file history to record changes to. If nil, uses DefaultFileHistory.
History *FileHistory
}
WriteTool writes content to a file, creating parent directories as needed. It implements FileAccessor to enable conflict detection.
func (*WriteTool) Description ¶
func (*WriteTool) GetFilePath ¶ added in v0.2.0
func (t *WriteTool) GetFilePath(input json.RawMessage) string
GetFilePath extracts the target file path from the input.
func (*WriteTool) InputSchema ¶
func (t *WriteTool) InputSchema() anthropic.ToolInputSchemaParam
func (*WriteTool) IsWriteOperation ¶ added in v0.2.0
IsWriteOperation returns true since this tool modifies files.