tools

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TodoPending    = "pending"
	TodoInProgress = "in_progress"
	TodoCompleted  = "completed"
)

Todo statuses. The model is asked to pass the complete list on every call.

View Source
const (
	A2AToolType                = "a2a"
	AskUserToolType            = "ask_user"
	BingSearchToolType         = "bing_search"
	BrowserUseToolType         = "browser_use"
	CommandLineToolType        = "command_line"
	CustomExecToolType         = "custom_exec"
	CustomHTTPToolType         = "custom_http"
	DuckDuckGoToolType         = "duckduckgo"
	FileSystemToolType         = "file_system"
	GoogleSearchToolType       = "google_search"
	HTTPRequestToolType        = "http_request"
	JavaScriptToolType         = "javascript"
	PluginToolType             = "plugin"
	SequentialThinkingToolType = "sequential_thinking"
	SubagentToolType           = "subagent"
	TodoListToolType           = "todo_list"
	WikipediaToolType          = "wikipedia"
)

Tool type identifiers use lowercase snake_case. The default instance name is the type identifier; configured instances may use their own explicit names.

View Source
const (
	A2AToolName         = A2AToolType
	AskUserToolName     = AskUserToolType
	BrowserUseToolName  = BrowserUseToolType
	CommandLineToolName = CommandLineToolType
	FileSystemToolName  = FileSystemToolType
	HTTPRequestToolName = HTTPRequestToolType
	JavaScriptToolName  = JavaScriptToolType
	SubagentToolName    = SubagentToolType
	TodoListToolName    = TodoListToolType
)

Variables

This section is empty.

Functions

func ActiveModel

func ActiveModel(ctx context.Context) string

ActiveModel returns the model recorded by WithActiveModel, or "".

func ActiveTools

func ActiveTools(ctx context.Context) []string

ActiveTools returns the tool names recorded by WithActiveTools.

func CreateTool

func CreateTool(name string, cfg config.Tool) (tool.InvokableTool, error)

CreateTool creates a tool whose runtime name is exactly its configuration key.

func CreateToolsFromConfig

func CreateToolsFromConfig(cfg *config.Config) (map[string]tool.InvokableTool, error)

CreateToolsFromConfig creates all tools from configuration.

func NewA2ATool added in v0.5.0

func NewA2ATool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewA2ATool creates a tool that calls configured remote A2A agents without streaming.

Config options:

  • agents: allowlist of names from a2a_agents (default: all)
  • timeout: overall per-call timeout in seconds (default 300)
  • poll_interval_ms: task polling interval in milliseconds (default 1000)

func NewAskUserTool

func NewAskUserTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewAskUserTool creates the ask_user tool.

func NewBingSearchTool

func NewBingSearchTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewBingSearchTool creates Bing search tool

func NewBrowserUseTool

func NewBrowserUseTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewBrowserUseTool creates browser usage tool.

The upstream constructor launches Chrome immediately, which made every agent startup pop a browser window (browser_use is one of the built-in agent's default tools). The returned tool therefore starts the browser lazily, on the first actual tool call.

func NewCommandLineTool

func NewCommandLineTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewCommandLineTool creates the "command_line" shell tool.

Config options:

  • work_dir: working directory for commands (optional)
  • timeout: execution timeout in seconds (default 60)

func NewDuckDuckGoTool

func NewDuckDuckGoTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewDuckDuckGoTool creates DuckDuckGo search tool

func NewFileSystemTool

func NewFileSystemTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewFileSystemTool creates the "file_system" tool.

Config options:

  • root: directory the tool may access (default: current working directory)
  • max_bytes: read budget per call in bytes (default 200 KiB)
  • max_entries: list/grep result cap (default 500 for list, 200 for grep)
  • timeout: per-call timeout in seconds (default 30)

func NewGoogleSearchTool

func NewGoogleSearchTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewGoogleSearchTool creates Google search tool

func NewHTTPRequestTool

func NewHTTPRequestTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewHTTPRequestTool creates HTTP request tool

func NewJavaScriptTool

func NewJavaScriptTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewJavaScriptTool executes an async function body in a fresh moejs runtime. No filesystem, network, process or module loader APIs are installed.

func NewSequentialThinkingTool

func NewSequentialThinkingTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewSequentialThinkingTool uses the configured name and description rather than exposing the upstream implementation's fixed tool name.

func NewSubagentTool

func NewSubagentTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewSubagentTool creates the "subagent" tool.

Config options:

  • agents: allowlist of configured agent names (default: all)
  • tools: allowlist of tool names a temporary agent may request (default: all)
  • allow_temp: allow ad-hoc agents built from a system prompt (default true)
  • max_depth: maximum subagent nesting depth (default 1)
  • timeout: per-child-run timeout in seconds (default 300)

func NewTodoListTool

func NewTodoListTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewTodoListTool creates the todo tool.

func NewWikipediaTool

func NewWikipediaTool(name string, cfg config.Tool) (tool.InvokableTool, error)

NewWikipediaTool creates Wikipedia tool

func SetRemoteAgentRunner added in v0.5.0

func SetRemoteAgentRunner(r RemoteAgentRunner)

SetRemoteAgentRunner installs the remote A2A agent runner.

func SetSubagentRunner

func SetSubagentRunner(r SubagentRunner)

SetSubagentRunner installs the child-agent runner.

func SubagentDepth

func SubagentDepth(ctx context.Context) int

SubagentDepth reports the nesting depth carried by ctx.

func WithActiveModel

func WithActiveModel(ctx context.Context, model string) context.Context

WithActiveModel records the model the current run is using, so nested agents (the subagent tool) run on the same model, including a runtime /model switch.

func WithActiveTools

func WithActiveTools(ctx context.Context, names []string) context.Context

WithActiveTools records the tool names the current run has, so a subagent asked for nothing but a prompt inherits the same capabilities.

func WithApproval

func WithApproval(inner tool.InvokableTool, policy approval.Policy) (tool.InvokableTool, error)

WithApproval wraps inner with the given approval policy. Tools that only talk to the user (ask_user, todo_list) are never gated.

func WithHost

func WithHost(ctx context.Context, h Host) context.Context

WithHost attaches an interactive host to a context.

func WithSubagentDepth

func WithSubagentDepth(ctx context.Context, depth int) context.Context

WithSubagentDepth records how many subagents deep the current run is.

Types

type AskUserTool

type AskUserTool struct {
	// contains filtered or unexported fields
}

AskUserTool asks the user a question through the host and waits for an answer.

func (*AskUserTool) Info

func (t *AskUserTool) Info(ctx context.Context) (*schema.ToolInfo, error)

Info returns the tool metadata.

func (*AskUserTool) InvokableRun

func (t *AskUserTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error)

InvokableRun asks the question and returns the user's answer.

type Host

type Host interface {
	// AskUser asks the user a question and returns the answer ("" when the
	// user cancels).
	AskUser(ctx context.Context, question string, options []string) (string, error)
	// UpdateTodos replaces the displayed task list.
	UpdateTodos(ctx context.Context, items []TodoItem) error
	// ApproveTool asks the user whether a dangerous tool call may run. It
	// reports false when the user denies the request.
	ApproveTool(ctx context.Context, req approval.Request) (bool, error)
}

Host is implemented by interactive front-ends (the TUI) that can talk to the user and display the task list. Tools receive it through the context.

func HostFromContext

func HostFromContext(ctx context.Context) Host

HostFromContext returns the host attached to a context, or nil.

type RemoteAgentRunner added in v0.5.0

type RemoteAgentRunner func(context.Context, RemoteAgentSpec) (string, error)

RemoteAgentRunner runs a remote A2A agent. The agent package installs the implementation so the tools package does not depend on the protocol server.

type RemoteAgentSpec added in v0.5.0

type RemoteAgentSpec struct {
	Agent        string
	Prompt       string
	TaskID       string
	ContextID    string
	Timeout      time.Duration
	PollInterval time.Duration
}

RemoteAgentSpec describes one non-streaming A2A call.

type SubagentRunner

type SubagentRunner func(ctx context.Context, spec SubagentSpec) (string, error)

SubagentRunner runs a child agent and returns its final answer. The agent package installs the real implementation; injecting it keeps the dependency direction one-way (agent imports tools).

type SubagentSpec

type SubagentSpec struct {
	Agent  string
	System string
	Model  string
	Tools  []string
	Prompt string
}

SubagentSpec describes a child-agent run requested by the model. Agent names a configured agent; otherwise System describes a temporary one (it falls back to a default instruction when the call only carried a prompt).

type TodoItem

type TodoItem struct {
	Content string `json:"content"`
	Status  string `json:"status"`
}

TodoItem is one entry of the task list.

type TodoListTool

type TodoListTool struct {
	// contains filtered or unexported fields
}

TodoListTool maintains the task list shown by the host.

func (*TodoListTool) Info

func (t *TodoListTool) Info(ctx context.Context) (*schema.ToolInfo, error)

Info returns the tool metadata.

func (*TodoListTool) InvokableRun

func (t *TodoListTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error)

InvokableRun replaces the host's task list and returns a summary.

Directories

Path Synopsis
Package approval holds the types shared by the tool-approval wrapper and the tools that know which of their calls need a human decision.
Package approval holds the types shared by the tool-approval wrapper and the tools that know which of their calls need a human decision.

Jump to

Keyboard shortcuts

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