Documentation
¶
Index ¶
- Constants
- Variables
- func MustRegister(tool Tool)
- func Register(tool Tool) error
- type Permissions
- type Registry
- type Tool
- type ToolContext
- func (c *ToolContext) CheckBash() error
- func (c *ToolContext) CheckFileRead() error
- func (c *ToolContext) CheckFileWrite() error
- func (c *ToolContext) CheckGit() error
- func (c *ToolContext) CheckGitHub() error
- func (c *ToolContext) CheckNetwork() error
- func (c *ToolContext) FileExists(path string) bool
- func (c *ToolContext) IsDir(path string) bool
- func (c *ToolContext) ResolvePath(path string) string
- func (c *ToolContext) ValidatePath(path string) (string, error)
- func (c *ToolContext) WithBashTimeout(seconds int) *ToolContext
- func (c *ToolContext) WithEnv(key, value string) *ToolContext
- func (c *ToolContext) WithGitHub(token, owner, repo string) *ToolContext
- func (c *ToolContext) WithPermissions(p Permissions) *ToolContext
- type ToolResult
Constants ¶
const ( ErrNoWorkDir toolError = "working directory not set" ErrPathOutsideWorkDir toolError = "path is outside working directory" ErrPermissionDenied toolError = "permission denied" ErrBashNotAllowed toolError = "bash execution not allowed" ErrFileReadNotAllowed toolError = "file read not allowed" ErrFileWriteNotAllowed toolError = "file write not allowed" ErrGitNotAllowed toolError = "git operations not allowed" ErrGitHubNotAllowed toolError = "github operations not allowed" ErrNetworkNotAllowed toolError = "network operations not allowed" )
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the global default registry.
Functions ¶
func MustRegister ¶
func MustRegister(tool Tool)
MustRegister adds a tool to the default registry and panics on error.
Types ¶
type Permissions ¶
type Permissions struct {
// AllowBash allows executing bash commands.
AllowBash bool
// AllowFileRead allows reading files.
AllowFileRead bool
// AllowFileWrite allows writing files.
AllowFileWrite bool
// AllowGit allows git operations.
AllowGit bool
// AllowGitHub allows GitHub API operations.
AllowGitHub bool
// AllowNetwork allows network operations.
AllowNetwork bool
}
Permissions defines what operations a tool is allowed to perform.
func DefaultPermissions ¶
func DefaultPermissions() Permissions
DefaultPermissions returns permissions with all operations allowed.
func RestrictedPermissions ¶
func RestrictedPermissions() Permissions
RestrictedPermissions returns permissions with only read operations allowed.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages tool registration and lookup.
func (*Registry) MustRegister ¶
MustRegister adds a tool to the registry and panics on error.
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
// InputSchema returns the JSON Schema for the tool's input parameters.
InputSchema() map[string]any
// Execute runs the tool with the given input and returns the result.
Execute(ctx context.Context, toolCtx *ToolContext, input map[string]any) (ToolResult, error)
}
Tool defines the interface for all tools available to the agent.
type ToolContext ¶
type ToolContext struct {
// WorkDir is the working directory for tool execution.
// File operations should be restricted to this directory.
WorkDir string
// Permissions defines what operations are allowed.
Permissions Permissions
// GitHubToken is the token for GitHub API operations.
GitHubToken string
// RepoOwner is the owner of the repository.
RepoOwner string
// RepoName is the name of the repository.
RepoName string
// Env contains environment variables available to tools.
Env map[string]string
// BashTimeout is the timeout for bash command execution in seconds.
BashTimeout int
}
ToolContext provides execution context for tools.
func NewToolContext ¶
func NewToolContext(workDir string) *ToolContext
NewToolContext creates a new tool context with the given working directory.
func (*ToolContext) CheckBash ¶
func (c *ToolContext) CheckBash() error
CheckBash checks if bash execution is allowed.
func (*ToolContext) CheckFileRead ¶
func (c *ToolContext) CheckFileRead() error
CheckFileRead checks if file read operations are allowed.
func (*ToolContext) CheckFileWrite ¶
func (c *ToolContext) CheckFileWrite() error
CheckFileWrite checks if file write operations are allowed.
func (*ToolContext) CheckGit ¶
func (c *ToolContext) CheckGit() error
CheckGit checks if git operations are allowed.
func (*ToolContext) CheckGitHub ¶
func (c *ToolContext) CheckGitHub() error
CheckGitHub checks if GitHub operations are allowed.
func (*ToolContext) CheckNetwork ¶
func (c *ToolContext) CheckNetwork() error
CheckNetwork checks if network operations are allowed.
func (*ToolContext) FileExists ¶
func (c *ToolContext) FileExists(path string) bool
FileExists checks if a file exists at the given path.
func (*ToolContext) IsDir ¶
func (c *ToolContext) IsDir(path string) bool
IsDir checks if the path is a directory.
func (*ToolContext) ResolvePath ¶
func (c *ToolContext) ResolvePath(path string) string
ResolvePath resolves a path relative to the working directory. Unlike ValidatePath, this does not check if the path exists.
func (*ToolContext) ValidatePath ¶
func (c *ToolContext) ValidatePath(path string) (string, error)
ValidatePath checks if the given path is within the working directory. Returns the cleaned absolute path if valid, or an error if the path is outside the working directory.
func (*ToolContext) WithBashTimeout ¶
func (c *ToolContext) WithBashTimeout(seconds int) *ToolContext
WithBashTimeout sets the bash timeout and returns the context for chaining.
func (*ToolContext) WithEnv ¶
func (c *ToolContext) WithEnv(key, value string) *ToolContext
WithEnv sets an environment variable and returns the context for chaining.
func (*ToolContext) WithGitHub ¶
func (c *ToolContext) WithGitHub(token, owner, repo string) *ToolContext
WithGitHub sets GitHub credentials and returns the context for chaining.
func (*ToolContext) WithPermissions ¶
func (c *ToolContext) WithPermissions(p Permissions) *ToolContext
WithPermissions sets the permissions and returns the context for chaining.
type ToolResult ¶
type ToolResult struct {
// Content is the output of the tool execution.
Content string
// IsError indicates if the execution resulted in an error.
IsError bool
// Metadata contains additional information about the execution.
Metadata map[string]any
}
ToolResult represents the result of a tool execution.
func NewErrorResult ¶
func NewErrorResult(err error) ToolResult
NewErrorResult creates an error tool result.
func NewErrorResultf ¶
func NewErrorResultf(format string, args ...any) ToolResult
NewErrorResultf creates an error tool result with a formatted message.
func NewToolResult ¶
func NewToolResult(content string) ToolResult
NewToolResult creates a successful tool result.
func (ToolResult) WithMetadata ¶
func (r ToolResult) WithMetadata(key string, value any) ToolResult
WithMetadata adds metadata to a tool result.