Documentation
¶
Overview ¶
Package tools defines tool providers assembled per run.
Index ¶
- Constants
- Variables
- func AfterResult(ctx context.Context, ev agui.Event)
- func AttachImage(ctx context.Context, img Image) bool
- func CanViewImages(ctx context.Context) bool
- func Errorf(format string, args ...any) error
- func Live(ctx context.Context, ev agui.Event)
- func SpillPath(toolCallID string) string
- func SubagentUsage(ctx context.Context, model string, in, out, cached int)
- func Untrusted(ctx context.Context) bool
- func WithCall(ctx context.Context, toolCallID string, e Emitter) context.Context
- type ApprovalNamer
- type Emitter
- type Filter
- type Image
- type ImageSink
- type Interrupt
- type LiveEmitter
- type OutputSpiller
- type Provider
- type QuestionOption
- type ReadOnly
- type Registry
- type ResultEmitter
- type RunContext
- type SandboxSpiller
- type StopGuard
- type TurnCall
- type TurnObserver
- type UntrustedSource
- type UserError
Constants ¶
const SandboxOff = "off"
SandboxOff is RunContext.Sandbox of a run without sandbox.
const SpillDir = sandbox.ToolOutputDir + "/"
SpillDir is where large tool outputs are written in full (scratch space, never saved).
Variables ¶
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 ¶
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 ¶
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 ¶
CanViewImages reports whether the current call's model accepts images (false without an agent emitter).
func Live ¶
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 ¶
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 ¶
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).
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.
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).
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 ¶
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.
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 ¶
NewRegistry returns a registry of providers (nil entries are ignored).
type ResultEmitter ¶
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 ¶
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 ¶
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 ¶
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.