tools

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tools defines tool providers assembled per run.

Index

Constants

View Source
const SandboxOff = "off"

SandboxOff is RunContext.Sandbox of a run without sandbox.

View Source
const SpillDir = sandbox.ToolOutputDir + "/"

SpillDir is where large tool outputs are written in full (scratch space, never saved).

Variables

View Source
var ErrNoSpill = errors.New("tools: no running sandbox to keep the full output")

ErrNoSpill: there is no running sandbox to spill into (the output is cut instead).

Functions

func AfterResult

func AfterResult(ctx context.Context, ev agui.Event)

AfterResult queues an AG-UI event to follow the current tool call's result (dropped when the call has no agent emitter, e.g. in isolation).

func AttachImage

func AttachImage(ctx context.Context, img Image) bool

AttachImage queues an image for the model's next call; false when the model cannot see images (or there is no agent emitter).

func CanViewImages

func CanViewImages(ctx context.Context) bool

CanViewImages reports whether the current call's model accepts images (false without an agent emitter).

func Errorf

func Errorf(format string, args ...any) error

Errorf builds a UserError.

func Live

func Live(ctx context.Context, ev agui.Event)

Live emits an AG-UI event while the current tool call runs (dropped when the call has no agent emitter, e.g. in isolation).

func SpillPath

func SpillPath(toolCallID string) string

SpillPath is a new file for a tool call's spilled output: the call id (made safe) and a random suffix, so a provider reusing call ids never overwrites an earlier output.

func SubagentUsage

func SubagentUsage(ctx context.Context, model string, in, out, cached int)

SubagentUsage adds the token usage of a sub-agent's model calls to the run's totals (reported under its own model name; no-op without an agent emitter).

func Untrusted

func Untrusted(ctx context.Context) bool

Untrusted reports whether the current call follows untrusted content in the model's context (false without an agent emitter).

func WithCall

func WithCall(ctx context.Context, toolCallID string, e Emitter) context.Context

WithCall attaches the current tool call id and emitter to ctx.

Types

type ApprovalNamer

type ApprovalNamer interface {
	ApprovalNames() []string
}

ApprovalNamer is a tool whose exposed name may not show what it does (MCP: sanitized and truncated to 64 characters): ApprovalNames are the original names its riskiness (interactive approvals) is decided from.

type Emitter

type Emitter interface {
	ToolOutput(toolCallID, stream, text string)
}

Emitter receives live tool output.

func CallFromContext

func CallFromContext(ctx context.Context) (string, Emitter)

CallFromContext returns the tool call id and emitter (nil emitter when absent).

type Filter

type Filter struct {
	Inner Provider
	Allow func(ctx context.Context, rc RunContext, name string) bool
}

Filter is a Provider that offers only the tools of Inner that Allow accepts (called per run, in Inner's order, so the tool list stays byte-stable).

func (Filter) Name

func (f Filter) Name() string

Name implements Provider.

func (Filter) Tools

func (f Filter) Tools(ctx context.Context, rc RunContext) ([]ai.BaseTool, func(), error)

Tools implements Provider.

type Image

type Image struct {
	// Path is the sandbox file the image comes from (the stub of later steps names it).
	Path     string
	MIMEType string
	Data     []byte
}

Image is a picture a tool shows to the model (read_file of an image, view_file pages): sent to vision models with the next model call only (harness v3 §3).

type ImageSink

type ImageSink interface {
	CanViewImages() bool
	AttachImage(img Image)
}

ImageSink is implemented by the agent's emitter: whether the run's model can see images, and the queue of images for its next call.

type Interrupt

type Interrupt struct {
	Reason        string
	Question      string
	Options       []QuestionOption
	AllowFreeText bool
	// ID and ToolCallID are set by the agent.
	ID         string
	ToolCallID string
	// Approval is set for a risky tool call paused before it runs (reason
	// tool_approval, interactive mode); ID is then the approval id.
	Approval *store.Approval
}

Interrupt is returned (as error) by a tool that needs the user before the agent can continue (ask_user): the run ends with an AG-UI interrupt outcome and the tool result is supplied by the user when the run is resumed.

func (*Interrupt) Error

func (i *Interrupt) Error() string

type LiveEmitter

type LiveEmitter interface {
	EmitLive(ev agui.Event)
	AddSubagentUsage(model string, in, out, cached int)
}

LiveEmitter is implemented by the agent's emitter: events emitted with Live are written while the tool runs (in call order when calls run in parallel), and sub-agent usage is added to the run's usage totals.

type OutputSpiller

type OutputSpiller interface {
	SpillOutput(ctx context.Context, rc RunContext, toolCallID, content string) (path string, err error)
}

OutputSpiller writes a tool output too large for the model's context to a file of the run's workspace and returns its path (harness v3 §2).

type Provider

type Provider interface {
	Name() string
	// Tools returns the provider's tools for this run and a cleanup func called at run end.
	Tools(ctx context.Context, rc RunContext) ([]ai.BaseTool, func(), error)
}

Provider contributes tools to a run.

type QuestionOption

type QuestionOption struct {
	Label       string `json:"label"`
	Description string `json:"description,omitempty"`
}

QuestionOption is an answer choice of an Interrupt.

type ReadOnly

type ReadOnly interface {
	ReadOnly() bool
}

ReadOnly is an optional interface of a tool: a tool whose ReadOnly reports true has no side effects (it reads, searches or loads text) and may run in parallel with the other read-only calls of a step (harness v3 §2).

type Registry

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

Registry assembles all providers; a failing provider is logged and skipped.

func NewRegistry

func NewRegistry(providers ...Provider) *Registry

NewRegistry returns a registry of providers (nil entries are ignored).

func (*Registry) Name

func (r *Registry) Name() string

Name implements Provider.

func (*Registry) Tools

func (r *Registry) Tools(ctx context.Context, rc RunContext) ([]ai.BaseTool, func(), error)

Tools implements Provider: merges every provider's tools, dropping duplicate names.

type ResultEmitter

type ResultEmitter interface {
	EmitAfterResult(ev agui.Event)
}

ResultEmitter is implemented by the agent's emitter: events queued with EmitAfterResult are written right after the tool's TOOL_CALL_RESULT.

type RunContext

type RunContext struct {
	ThreadID string
	RunID    string
	Login    string
	// Sandbox is the run's sandbox mode ("", "auto", "on" or "off"): with "off"
	// the sandbox tools offer nothing and no sandbox is used.
	Sandbox string
}

RunContext identifies the run a tool set is built for.

type SandboxSpiller

type SandboxSpiller struct {
	Sandboxes sandbox.Manager
}

SandboxSpiller writes spilled outputs into the thread's running sandbox. It never creates one (Get, not Acquire): a large result of a tool that needs no sandbox (MCP, web search) in a thread without one is cut instead (ErrNoSpill).

func (SandboxSpiller) SpillOutput

func (s SandboxSpiller) SpillOutput(ctx context.Context, rc RunContext, toolCallID, content string) (string, error)

SpillOutput implements OutputSpiller.

type StopGuard

type StopGuard interface {
	StopReminder(ctx context.Context) string
}

StopGuard is an optional interface of a tool. When the model answers without tool calls and the run still has steps left, the agent asks every StopGuard tool of the run (in tool-name order); non-empty reminders are given to the model as one unpersisted user message and the run continues (at most 2 per run).

type TurnCall

type TurnCall struct {
	Name      string
	Arguments string
	Result    string
	Failed    bool
}

TurnCall is a tool call of the current turn made by an earlier run of the same turn (a run resumed after an approval or an ask_user answer).

type TurnObserver

type TurnObserver interface {
	ObserveTurn(calls []TurnCall)
}

TurnObserver is an optional interface of a tool: at the start of a run that resumes a turn, the agent gives it the turn's earlier calls, so its state (e.g. the plan StopGuard) survives the resume (A-21).

type UntrustedSource

type UntrustedSource interface {
	Untrusted() bool
}

UntrustedSource is implemented by the agent's emitter: it reports whether the model's context holds untrusted content (tool output, attachments, a user skill, a compaction summary) at the time of the current tool call.

type UserError

type UserError struct{ Msg string }

UserError is a tool failure whose message is meant for the model.

func (*UserError) Error

func (e *UserError) Error() string

Jump to

Keyboard shortcuts

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