Help us shape the future of Go! Take the 2026 Go Developer Survey

tools

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package tools implements the agent's file and shell tools, sandboxed to a root directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bash

func Bash(ctx context.Context, root, command string, timeout time.Duration) (string, error)

Bash runs command in a fresh `bash -c` process in root. On timeout the whole process group is killed so background children do not linger.

func EditFile

func EditFile(root, path, oldStr, newStr string, replaceAll bool) (int, error)

EditFile replaces the single occurrence of oldStr with newStr, or every occurrence if replaceAll is set, and returns the number of replacements.

func Grep

func Grep(root, pattern, path, include string) (string, error)

Grep returns lines matching pattern as "file:line: content". Binary and very large files are skipped. A non-empty include glob limits the search to matching files, using the same rules as ListFiles: a glob without "/" matches base names, a glob with "/" matches paths relative to the searched directory. When path is a single file, include is ignored.

func ListFiles

func ListFiles(root, path, pattern string) (string, error)

ListFiles lists the entries of a directory, or, with a pattern, walks it recursively and returns matching files. A pattern without "/" matches base names; a pattern with "/" matches paths relative to the listed directory.

func ReadFile

func ReadFile(root, path string, offset, limit int) (string, error)

ReadFile returns a file's contents. A positive offset (1-based start line) or limit (max lines) returns just that range, ending in a "[lines A-B of N]" note when the range isn't the whole file.

func Resolve

func Resolve(root, path string) (string, error)

Resolve maps a path relative to root (or absolute inside root) to an absolute path, rejecting anything that escapes root. The check is lexical; symlinks inside root that point outside it are followed.

func Specs

func Specs() []model.ToolSpec

Specs returns the OpenAI tool definitions for all tools.

func WriteFile

func WriteFile(root, path, content string) error

Types

type Executor

type Executor struct {
	Root           string // absolute working directory
	BashTimeout    time.Duration
	MaxOutputChars int // 0 = unlimited
}

Executor runs tool calls against files under Root.

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, call model.ToolCall) string

Run executes one tool call and returns text for the model. Tool failures are reported as text so the model can recover; Run never returns an error.

Jump to

Keyboard shortcuts

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