tools

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDelegateFn added in v0.2.0

func SetDelegateFn(fn func(ctx context.Context, role, request string) (string, error))

SetDelegateFn sets the delegate function used by DelegateToAgentTool.

func SetSandboxProvider added in v0.3.0

func SetSandboxProvider(sp sandbox.Provider)

SetSandboxProvider sets the sandbox provider used by CodeInterpreterTool.

func WithAlignedFormat added in v0.9.0

func WithAlignedFormat() dbOption

WithAlignedFormat switches result output to human-readable aligned columns.

func WithChromePath added in v0.4.0

func WithChromePath(path string) func(*browserTool)

WithChromePath sets a custom Chrome/Chromium binary path.

func WithCloudTimeout added in v0.9.0

func WithCloudTimeout(d time.Duration) cloudOption

WithCloudTimeout sets the HTTP client timeout for cloud tool requests.

func WithEmbedderEndpoint added in v0.9.0

func WithEmbedderEndpoint(url string) ragOption

WithEmbedderEndpoint overrides the LLM base URL used by the embedder.

func WithEndpoint added in v0.9.0

func WithEndpoint(url string) cloudOption

WithEndpoint sets the base endpoint URL for cloud tool requests.

func WithHTTPEndpoint added in v0.9.0

func WithHTTPEndpoint(url string) httpOption

WithHTTPEndpoint sets the base endpoint URL for research tool requests.

func WithHTTPTimeout added in v0.9.0

func WithHTTPTimeout(d time.Duration) httpOption

WithHTTPTimeout sets the HTTP client timeout for research tool requests.

func WithHeadless added in v0.4.0

func WithHeadless(headless bool) func(*browserTool)

WithHeadless overrides the headless mode after construction. Pass false to show the browser window (useful for debugging).

func WithMaxRows added in v0.9.0

func WithMaxRows(n int) dbOption

WithMaxRows sets the maximum number of rows returned (default 1000).

func WithNL2SQLPrompt added in v0.9.0

func WithNL2SQLPrompt(prompt string) dbOption

WithNL2SQLPrompt sets a custom system prompt for SQL generation.

func WithQueryTimeout added in v0.9.0

func WithQueryTimeout(d time.Duration) dbOption

WithQueryTimeout sets the maximum duration for a single query execution.

func WithRegion added in v0.9.0

func WithRegion(r string) cloudOption

WithRegion sets the AWS region for cloud tool requests.

func WithRootDir added in v0.6.0

func WithRootDir(dir string) fileToolOption

WithRootDir sets the allowed root directory for file operations. Paths that escape this directory are rejected with ErrPathTraversal. Default is os.TempDir() when not set.

func WithTabTimeout added in v0.4.0

func WithTabTimeout(d time.Duration) func(*browserTool)

WithTabTimeout sets the per-action timeout (default 30s).

func WithWriteMode added in v0.9.0

func WithWriteMode(enabled bool) dbOption

WithWriteMode enables write queries (INSERT, UPDATE, DELETE, DROP, etc.). By default, only read-only queries are allowed.

Types

type AskHumanOption added in v0.6.0

type AskHumanOption func(*askHumanTool)

AskHumanOption configures an AskHumanTool.

func WithAskTimeout added in v0.6.0

func WithAskTimeout(d time.Duration) AskHumanOption

WithAskTimeout sets the maximum duration to wait for human input. A zero value means no timeout.

func WithEnabled added in v0.6.0

func WithEnabled(enabled bool) AskHumanOption

WithEnabled configures whether the tool prompts for human input. When false, Execute returns "[ask_human disabled]" without reading stdin.

func WithPrompt added in v0.6.0

func WithPrompt(prompt string) AskHumanOption

WithPrompt sets the prompt prefix displayed before the question.

func WithStdout added in v0.6.0

func WithStdout(w io.Writer) AskHumanOption

WithStdout sets the writer used for prompt output. Defaults to os.Stderr.

type Base

type Base struct {
	ToolName  string
	Desc      string
	Params    map[string]any
	ExecuteFn func(ctx context.Context, args map[string]any) (string, error)
}

Base provides a default implementation of the Tool interface.

func (*Base) Description

func (b *Base) Description() string

Description returns the tool's description.

func (*Base) Execute

func (b *Base) Execute(ctx context.Context, args map[string]any) (string, error)

Execute runs the tool's execute function with the given arguments.

func (*Base) Name

func (b *Base) Name() string

Name returns the tool's name.

func (*Base) Parameters

func (b *Base) Parameters() map[string]any

Parameters returns the tool's JSON schema parameters.

type SearchResult added in v0.6.0

type SearchResult struct {
	Title   string
	URL     string
	Snippet string
	Content string
}

SearchResult represents a single web search result.

func (SearchResult) Format added in v0.6.0

func (sr SearchResult) Format() string

Format returns a formatted string representation in the spec-defined format.

type Tool

type Tool interface {
	Name() string
	Description() string
	Parameters() map[string]any
	Execute(ctx context.Context, args map[string]any) (string, error)
}

Tool is the interface that all tools must implement.

func ArxivTool added in v0.9.0

func ArxivTool(opts ...httpOption) Tool

ArxivTool creates a Tool that searches arxiv for academic papers and returns structured metadata (title, authors, abstract, PDF link, published date).

Rate-limit advisory: arxiv recommends at most 1 request per 3 seconds. The agent controls call frequency — this tool does not enforce throttling.

func AskAgentTool added in v0.2.0

func AskAgentTool() Tool

AskAgentTool creates a tool that asks another agent a question via A2A.

func AskHumanTool

func AskHumanTool() Tool

AskHumanTool creates a tool that asks a human for input or approval.

func BrowserTool added in v0.4.0

func BrowserTool(headless bool, opts ...func(*browserTool)) Tool

BrowserTool creates a new browser automation tool. headless=false enables visible Chrome mode for debugging. Options: WithChromePath, WithTabTimeout, WithHeadless. Actions: navigate(url), click(selector), type(selector,text), extract_text(selector), extract_html(selector), screenshot(), scroll(direction=down|up).

func CSVSearchTool added in v0.9.0

func CSVSearchTool(opts ...ragOption) Tool

CSVSearchTool creates a Tool that searches CSV documents using vector retrieval.

func CalculatorTool

func CalculatorTool() Tool

CalculatorTool creates a tool that evaluates mathematical expressions.

func CodeInterpreterTool added in v0.3.0

func CodeInterpreterTool() Tool

CodeInterpreterTool creates a tool that executes code using the configured sandbox.

func DelegateToAgentTool added in v0.2.0

func DelegateToAgentTool() Tool

DelegateToAgentTool creates a tool that delegates a task to another agent via A2A.

func DelegateWorkTool

func DelegateWorkTool() Tool

DelegateWorkTool creates a tool that delegates a task to another agent.

func DirTool added in v0.6.0

func DirTool(opts ...fileToolOption) Tool

DirTool creates a tool that lists files and directories. Supports single-level and recursive listing.

func DirectorySearchTool added in v0.9.0

func DirectorySearchTool(opts ...ragOption) Tool

DirectorySearchTool creates a Tool that walks a directory, indexes all supported files (.txt, .md, .pdf, .csv, .json), and searches their content using vector retrieval.

func EditFileTool added in v0.6.0

func EditFileTool(opts ...fileToolOption) Tool

EditFileTool creates a tool that performs search-and-replace in a file. Uses bufio.Scanner for line-by-line processing — memory is proportional to the longest line, not the total file size. Writes to a temp file in the same directory, then atomically renames on success.

func ExaTool added in v0.9.0

func ExaTool(opts ...httpOption) Tool

ExaTool creates a Tool that searches the web via the Exa AI API and returns structured results with full-page content extraction. Requires an Exa API key; falls back to EXA_API_KEY environment variable.

func FirecrawlTool added in v0.9.0

func FirecrawlTool(opts ...cloudOption) Tool

FirecrawlTool creates a Tool that interacts with the Firecrawl API for web scraping, crawling, and sitemap extraction. It requires FIRECRAWL_API_KEY environment variable.

func GitHubTool added in v0.9.0

func GitHubTool(opts ...cloudOption) Tool

GitHubTool creates a Tool that interacts with the GitHub API. It requires the GITHUB_TOKEN environment variable. Supported actions: list_issues, read_file, create_issue.

func JSONSearchTool added in v0.9.0

func JSONSearchTool(opts ...ragOption) Tool

JSONSearchTool creates a Tool that searches JSON documents using vector retrieval.

func MySQLSearchTool added in v0.9.0

func MySQLSearchTool(opts ...dbOption) Tool

MySQLSearchTool creates a tool that queries a MySQL database. Parameters: conn_str (MySQL DSN), query (SQL query).

func New

func New(name, description string, params map[string]any, fn func(ctx context.Context, args map[string]any) (string, error)) Tool

New creates a new Tool with the given name, description, parameters, and execute function.

func NewAskHumanTool added in v0.6.0

func NewAskHumanTool(opts ...AskHumanOption) Tool

NewAskHumanTool creates a new AskHumanTool with the given options.

func NewNL2SQLTool added in v0.9.0

func NewNL2SQLTool(llmClient llm.Client, opts ...dbOption) Tool

NewNL2SQLTool creates a tool that translates natural language questions into SQL and executes them against a database. The llm parameter is used for SQL generation.

func NewWebSearchTool added in v0.6.0

func NewWebSearchTool(opts ...WebSearchOption) Tool

NewWebSearchTool creates a web search tool with the given options.

func PDFSearchTool added in v0.9.0

func PDFSearchTool(opts ...ragOption) Tool

PDFSearchTool creates a Tool that searches PDF documents using vector retrieval.

func PGSearchTool added in v0.9.0

func PGSearchTool(opts ...dbOption) Tool

PGSearchTool creates a tool that queries a PostgreSQL database. Parameters: conn_str (PostgreSQL DSN), query (SQL query).

func ReadFileTool

func ReadFileTool(opts ...fileToolOption) Tool

ReadFileTool creates a tool that reads the contents of a file. The tool streams content up to maxBytes (default 10 MB) to avoid loading large files entirely into memory. If the file exceeds maxBytes, the result includes a truncation warning.

func S3ReaderTool added in v0.9.0

func S3ReaderTool(opts ...cloudOption) Tool

S3ReaderTool creates a Tool that reads an object from S3. It requires AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.

func S3WriterTool added in v0.9.0

func S3WriterTool(opts ...cloudOption) Tool

S3WriterTool creates a Tool that writes content to an S3 bucket. It requires AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.

func SQLiteSearchTool added in v0.9.0

func SQLiteSearchTool(opts ...dbOption) Tool

SQLiteSearchTool creates a tool that queries a SQLite database. Parameters: path (file path or ":memory:"), query (SQL query).

func ScrapeWebsiteTool added in v0.9.0

func ScrapeWebsiteTool(opts ...cloudOption) Tool

ScrapeWebsiteTool creates a Tool that fetches a web page and extracts text content. When selector is provided, only content matching the CSS selector is returned.

func ShellTool

func ShellTool() Tool

ShellTool creates a tool that executes shell commands on the local system.

func SlackTool added in v0.9.0

func SlackTool(opts ...cloudOption) Tool

SlackTool creates a Tool that interacts with the Slack API. It requires the SLACK_TOKEN environment variable. Supported actions: send_message, channel_history.

func TXTSearchTool added in v0.9.0

func TXTSearchTool(opts ...ragOption) Tool

TXTSearchTool creates a Tool that searches text documents using vector retrieval.

func WebSearchTool

func WebSearchTool(apiKey string) Tool

WebSearchTool creates a web search tool. Deprecated: use NewWebSearchTool.

func WebsiteSearchTool added in v0.9.0

func WebsiteSearchTool(opts ...ragOption) Tool

WebsiteSearchTool creates a Tool that fetches a web page and searches its text content using vector retrieval.

func WikipediaTool added in v0.9.0

func WikipediaTool(opts ...httpOption) Tool

WikipediaTool creates a Tool that fetches a Wikipedia page summary for a given query and language.

func WriteFileTool

func WriteFileTool(opts ...fileToolOption) Tool

WriteFileTool creates a tool that writes content to a file. Parent directories are created automatically if they do not exist.

type WebSearchOption added in v0.6.0

type WebSearchOption func(*webSearchTool)

WebSearchOption configures a webSearchTool.

func WithNumResults added in v0.6.0

func WithNumResults(n int) WebSearchOption

WithNumResults sets the maximum number of search results to return (default 5).

func WithTimeout added in v0.6.0

func WithTimeout(d time.Duration) WebSearchOption

WithTimeout sets the HTTP timeout for search requests (default 10s).

Jump to

Keyboard shortcuts

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