LLM Tool implementations for Golang
-
Go-native tool implementations for common local tasks. Current tools:
-
File system (
fstool):- List directory (
listdir): Lists entries under a directory, optionally filtered via glob. - Read file (
readfile): Reads local files as UTF-8 text (rejects non-text content) or base64 binary (with image/file output kinds). Includes a size cap for safety. - Search files (
searchfiles): Recursively searches path and (text) content using RE2 regex. - Inspect path (
statpath): Returns existence, size, timestamps, and directory flag.
- List directory (
-
Images (
imagetool):- Read image (
readimage): Read intrinsic metadata for a local image file, optionally including base64-encoded contents.
- Read image (
-
Execute Commands (
exectool):- Execute Shell commands (
shell): Execute local shell commands (cross-platform) with timeouts, output caps, and session-like persistence for workdir/env. (Check notes below too).
- Execute Shell commands (
-
Text Processing (
texttool):- Delete text lines (
deletetextlines): Delete one or more exact line-block occurrences from a UTF-8 text file. Use beforeLines/afterLines as immediate-adjacent context to disambiguate. - Find text matches with context (
findtext): Search a UTF-8 text file and return matching lines/blocks with surrounding context lines. Supported Modes: substring, RE2 regex (line-by-line), or exact line-block match. - Insert text lines (
inserttextlines): Insert lines into a UTF-8 text file at start/end or relative to a uniquely-matched anchor block. - Read text range (
readtextrange): Read a UTF-8 text file and return lines. Start and end marker lines can be provided to narrow the range. - Replace text lines
replacetextlines: Replace a block of lines in a UTF-8 text file; use beforeLines/afterLines to make the match more specific.
- Delete text lines (
-
-
Tool registry for:
- collecting and listing tool manifests (stable ordering)
- invoking tools via JSON input/output with strict JSON input decoding
- tool call timeout handling
llmtools: Registry and registration helpersspec: Tool manifests + IO/output schemafstool: Filesystem tools.imagetool: Image tools.exectool: Execute commands.texttool: Text tools.
# Go 1.25+
go get github.com/flexigpt/llmtools-gopackage main
import (
"context"
"encoding/json"
"fmt"
"github.com/flexigpt/llmtools-go"
"github.com/flexigpt/llmtools-go/spec"
)
func main() {
r, err := llmtools.NewBuiltinRegistry(
llmtools.WithCallTimeoutForAll(10*time.Minute),
)
if err != nil {
panic(err)
}
// List tool manifests (for prompt/tool definition)
for _, t := range r.Tools() {
fmt.Printf("%s (%s): %s\n", t.Slug, t.GoImpl.FuncID, t.Description)
}
// Call a tool by FuncID using JSON input
in := json.RawMessage(`{"path": ".", "pattern": "*.go"}`)
out, err := r.Call(context.Background(), spec.FuncID("..."), in)
if err != nil {
panic(err)
}
fmt.Printf("tool outputs: %+v\n", out)
}package main
import (
"context"
"fmt"
"github.com/flexigpt/llmtools-go/fstool"
)
func main() {
out, err := fstool.ListDirectory(context.Background(), fstool.ListDirectoryArgs{
Path: ".",
Pattern: "*.md",
})
if err != nil {
panic(err)
}
fmt.Println(out.Entries)
}-
OS support:
- Uses Go build constraints (
windows/!windows) to select process-group handling. - No consumer build tags are required.
- Uses Go build constraints (
-
Timeouts:
- The tool enforces its own per-command timeout via
timeoutMS. - If you also set a registry-level timeout (
WithDefaultCallTimeoutorWithCallTimeout), ensure it is >= the tool timeout or set it to 0 to avoid early cancellation.
- The tool enforces its own per-command timeout via
-
Policy knobs:
- Hosts can pass a policy into tool instantiation. The default policy is at:
exectool.DefaultShellCommandPolicy.
- Hosts can pass a policy into tool instantiation. The default policy is at:
- Formatting follows
gofumptandgolinesviagolangci-lint, which is also used for linting. All rules are in .golangci.yml. - Useful scripts are defined in
taskfile.yml; requires Task. - Bug reports and PRs are welcome:
- Keep the public API (
package llmtoolsandspec) small and intentional. - Avoid leaking provider‑specific types through the public surface; put them under
internal/. - Please run tests and linters before sending a PR.
- Keep the public API (
Copyright (c) 2026 - Present - Pankaj Pipada
All source code in this repository, unless otherwise noted, is licensed under the MIT License. See LICENSE for details.