Documentation
¶
Index ¶
- Constants
- func ToProviderTools(tools []ToolDef) []map[string]any
- func TruncateOutput(s string, dir TruncateDirection) (string, bool)
- type BashTool
- type BreakdownInput
- type BreakdownTool
- type Context
- type DeepSearchFunc
- type DeepSearchTool
- type DocxIndexTool
- type EditTool
- type FetchPageTool
- type GlobTool
- type GrepTool
- type LatexToPdfTool
- type MemoryRecallTool
- type MetadataUpdate
- type PdfIndexTool
- type PermissionRequest
- type ProjectIndexTool
- type ProjectMemoryRecallTool
- type ReadDocxPageTool
- type ReadPdfPageTool
- type ReadTool
- type Registry
- type Result
- type ResultImage
- type SubmitDocIndexTool
- type TaskFunc
- type TaskTool
- type ToolDef
- type TruncateDirection
- type ViewImageTool
- type WebSearchTool
- type WriteTool
Constants ¶
const ( // MaxToolOutputBytes caps the byte length of any single tool result. MaxToolOutputBytes = 50 * 1024 // 50 KB // MaxToolOutputLines caps the line count of any single tool result. MaxToolOutputLines = 2000 // MaxLineLength caps one very long line (e.g. minified JS, a base64 blob) so // a single line cannot consume the whole budget on its own. MaxLineLength = 2000 )
Tool-output size caps. Every tool result that would otherwise flood the model context is truncated to these limits. The values mirror opencode's shared truncation service (50 KB / 2000 lines): a single large tool output (a build log, a big file, a verbose test run) is the dominant source of wasted tokens in an agentic loop, because it is re-sent on every subsequent step of the turn until compaction. Capping it here bounds that cost at the source.
Variables ¶
This section is empty.
Functions ¶
func ToProviderTools ¶
ToProviderTools converts tool definitions to provider format.
func TruncateOutput ¶ added in v0.21.0
func TruncateOutput(s string, dir TruncateDirection) (string, bool)
TruncateOutput caps s to MaxToolOutputLines and MaxToolOutputBytes, keeping the requested end, and inserts a one-line notice describing what was dropped. It returns the (possibly unchanged) text and whether any truncation happened.
It is the shared backstop applied to every tool result that does not cap its own output. Tools that truncate themselves (read, bash, grep, glob) set Result.Truncated so the agent loop skips this pass.
Types ¶
type BashTool ¶
type BashTool struct{}
func (BashTool) Description ¶
func (BashTool) Parameters ¶
func (BashTool) Parameters() json.RawMessage
type BreakdownInput ¶
type BreakdownInput struct {
Tasks []struct {
Title string `json:"title"`
Description string `json:"description"`
Dependencies []int `json:"dependencies"`
Effort string `json:"effort"`
Complexity string `json:"complexity"`
OrderIndex int `json:"orderIndex"`
} `json:"tasks"`
}
BreakdownInput matches the tool's parameter schema.
type BreakdownTool ¶
type BreakdownTool struct{}
BreakdownTool receives a structured task breakdown from the breakdown agent. The LLM calls this tool with properly formatted JSON (guaranteed valid by the tool-calling system), eliminating free-text JSON parsing issues.
func (BreakdownTool) Description ¶
func (t BreakdownTool) Description() string
func (BreakdownTool) Execute ¶
func (t BreakdownTool) Execute(_ context.Context, args json.RawMessage, _ Context) (Result, error)
func (BreakdownTool) ID ¶
func (t BreakdownTool) ID() string
func (BreakdownTool) Parameters ¶
func (t BreakdownTool) Parameters() json.RawMessage
type Context ¶
type Context struct {
SessionID session.SessionID
MessageID session.MessageID
Agent string
CallID string
Ctx context.Context
SessionDir string
Ask func(req PermissionRequest) error
Metadata func(meta MetadataUpdate) error
// ModelSupportsImages is true when the session's active model accepts image
// input. Tools may use this to decide whether to return an image (e.g. a
// rendered PDF page) instead of text.
ModelSupportsImages bool
// Model is the model ID the parent session is using. Tools that spawn child
// sessions (e.g. deep_search) should inherit this so they run on the same model.
Model string
}
Context is passed to every tool execution.
type DeepSearchFunc ¶ added in v0.8.0
DeepSearchFunc is a function that runs a child search-agent session and returns the synthesised answer. Implemented by agent.LoopRunner.RunSearchSession and wired in from server.go to avoid the tool→agent import cycle.
type DeepSearchTool ¶ added in v0.8.0
type DeepSearchTool struct {
Run DeepSearchFunc
}
DeepSearchTool lets any agent delegate a research query to the SearchAgent. It creates an ephemeral child session, runs the full search loop, and returns the synthesised text as the tool result.
func (DeepSearchTool) Description ¶ added in v0.8.0
func (DeepSearchTool) Description() string
func (DeepSearchTool) Execute ¶ added in v0.8.0
func (t DeepSearchTool) Execute(ctx context.Context, args json.RawMessage, tctx Context) (Result, error)
func (DeepSearchTool) ID ¶ added in v0.8.0
func (DeepSearchTool) ID() string
func (DeepSearchTool) Parameters ¶ added in v0.8.0
func (DeepSearchTool) Parameters() json.RawMessage
type DocxIndexTool ¶ added in v0.13.6
DocxIndexTool returns the stored semantic map for a DOCX file — pseudo-page labels — so the agent can decide which pages to read before calling read_docx_page.
func NewDocxIndexTool ¶ added in v0.13.6
func NewDocxIndexTool(store *docindex.Store) DocxIndexTool
func (DocxIndexTool) Description ¶ added in v0.13.6
func (DocxIndexTool) Description() string
func (DocxIndexTool) Execute ¶ added in v0.13.6
func (t DocxIndexTool) Execute(_ context.Context, args json.RawMessage, tctx Context) (Result, error)
func (DocxIndexTool) ID ¶ added in v0.13.6
func (DocxIndexTool) ID() string
func (DocxIndexTool) Parameters ¶ added in v0.13.6
func (DocxIndexTool) Parameters() json.RawMessage
type EditTool ¶
type EditTool struct{}
func (EditTool) Description ¶
func (EditTool) Parameters ¶
func (EditTool) Parameters() json.RawMessage
type FetchPageTool ¶ added in v0.8.0
type FetchPageTool struct {
Bridge *search.BridgeClient
}
FetchPageTool retrieves the text content of a URL via the Playwright bridge.
func (FetchPageTool) Description ¶ added in v0.8.0
func (FetchPageTool) Description() string
func (FetchPageTool) Execute ¶ added in v0.8.0
func (t FetchPageTool) Execute(ctx context.Context, args json.RawMessage, _ Context) (Result, error)
func (FetchPageTool) ID ¶ added in v0.8.0
func (FetchPageTool) ID() string
func (FetchPageTool) Parameters ¶ added in v0.8.0
func (FetchPageTool) Parameters() json.RawMessage
type GlobTool ¶
type GlobTool struct{}
func (GlobTool) Description ¶
func (GlobTool) Parameters ¶
func (GlobTool) Parameters() json.RawMessage
type GrepTool ¶
type GrepTool struct{}
func (GrepTool) Description ¶
func (GrepTool) Parameters ¶
func (GrepTool) Parameters() json.RawMessage
type LatexToPdfTool ¶ added in v0.9.1
type LatexToPdfTool struct{}
LatexToPdfTool compiles LaTeX source to PDF using pdflatex. It returns the path to the generated PDF file and, for vision-capable models, renders the first page as a JPEG image.
func (LatexToPdfTool) Description ¶ added in v0.9.1
func (LatexToPdfTool) Description() string
func (LatexToPdfTool) Execute ¶ added in v0.9.1
func (LatexToPdfTool) Execute(ctx context.Context, args json.RawMessage, tctx Context) (Result, error)
func (LatexToPdfTool) ID ¶ added in v0.9.1
func (LatexToPdfTool) ID() string
func (LatexToPdfTool) Parameters ¶ added in v0.9.1
func (LatexToPdfTool) Parameters() json.RawMessage
type MemoryRecallTool ¶ added in v0.2.1
MemoryRecallTool lets the LLM query the agentic knowledge graph on demand. Synthesis uses the session's currently selected model: the tool resolves the provider from the model ID via the registry and builds a per-call chat client.
func NewMemoryRecallTool ¶ added in v0.2.1
func NewMemoryRecallTool(mem *memory.Memory, registry *provider.Registry) MemoryRecallTool
func (MemoryRecallTool) Description ¶ added in v0.2.1
func (t MemoryRecallTool) Description() string
func (MemoryRecallTool) Execute ¶ added in v0.2.1
func (t MemoryRecallTool) Execute(ctx context.Context, args json.RawMessage, tctx Context) (Result, error)
func (MemoryRecallTool) ID ¶ added in v0.2.1
func (t MemoryRecallTool) ID() string
func (MemoryRecallTool) Parameters ¶ added in v0.2.1
func (t MemoryRecallTool) Parameters() json.RawMessage
type MetadataUpdate ¶
type MetadataUpdate struct {
Title string `json:"title,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
MetadataUpdate updates the running tool call's display metadata.
type PdfIndexTool ¶ added in v0.6.0
PdfIndexTool returns the stored semantic map for a PDF — page labels — so the agent can decide which pages to read before calling read_pdf_page.
func NewPdfIndexTool ¶ added in v0.6.0
func NewPdfIndexTool(store *docindex.Store) PdfIndexTool
func (PdfIndexTool) Description ¶ added in v0.6.0
func (PdfIndexTool) Description() string
func (PdfIndexTool) Execute ¶ added in v0.6.0
func (t PdfIndexTool) Execute(_ context.Context, args json.RawMessage, tctx Context) (Result, error)
func (PdfIndexTool) ID ¶ added in v0.6.0
func (PdfIndexTool) ID() string
func (PdfIndexTool) Parameters ¶ added in v0.6.0
func (PdfIndexTool) Parameters() json.RawMessage
type PermissionRequest ¶
type PermissionRequest struct {
ID session.PermissionID
SessionID session.SessionID
Tool string
Input string
}
PermissionRequest is sent when a tool needs user approval.
type ProjectIndexTool ¶ added in v0.7.0
ProjectIndexTool returns a labeled JSON tree of all indexed files in the session directory — text/code files, PDF documents, and DOCX documents alike — so the agent can navigate the project by topic without knowing file paths upfront.
Every file — text, code, PDF, or DOCX — appears as a leaf holding a flat topic-label array. For PDFs and DOCX files a concise subset of labels (capped at 15) is aggregated and de-duplicated across all pages, giving the agent a quick overview of what the document covers without the per-page breakdown. The dedicated pdf_index and docx_index tools provide the full per-page detail when the agent needs to decide which page to read.
func NewProjectIndexTool ¶ added in v0.7.0
func NewProjectIndexTool(store *docindex.Store) ProjectIndexTool
func (ProjectIndexTool) Description ¶ added in v0.7.0
func (ProjectIndexTool) Description() string
func (ProjectIndexTool) Execute ¶ added in v0.7.0
func (t ProjectIndexTool) Execute(_ context.Context, args json.RawMessage, tctx Context) (Result, error)
func (ProjectIndexTool) ID ¶ added in v0.7.0
func (ProjectIndexTool) ID() string
func (ProjectIndexTool) Parameters ¶ added in v0.7.0
func (ProjectIndexTool) Parameters() json.RawMessage
type ProjectMemoryRecallTool ¶ added in v0.23.0
ProjectMemoryRecallTool queries the agentic knowledge graph across every conversation ever held in this workspace, where memory_recall only sees the current session. Synthesis uses the session's selected model, resolved per call from the registry — same contract as MemoryRecallTool.
func NewProjectMemoryRecallTool ¶ added in v0.23.0
func NewProjectMemoryRecallTool(mem *memory.Memory, registry *provider.Registry) ProjectMemoryRecallTool
func (ProjectMemoryRecallTool) Description ¶ added in v0.23.0
func (t ProjectMemoryRecallTool) Description() string
func (ProjectMemoryRecallTool) Execute ¶ added in v0.23.0
func (t ProjectMemoryRecallTool) Execute(ctx context.Context, args json.RawMessage, tctx Context) (Result, error)
func (ProjectMemoryRecallTool) ID ¶ added in v0.23.0
func (t ProjectMemoryRecallTool) ID() string
func (ProjectMemoryRecallTool) Parameters ¶ added in v0.23.0
func (t ProjectMemoryRecallTool) Parameters() json.RawMessage
type ReadDocxPageTool ¶ added in v0.13.6
type ReadDocxPageTool struct{}
ReadDocxPageTool extracts the text of a single pseudo-page from a DOCX file for the agent to read. Use docx_index first to identify which pages are relevant, then call this tool to read their content.
func (ReadDocxPageTool) Description ¶ added in v0.13.6
func (ReadDocxPageTool) Description() string
func (ReadDocxPageTool) Execute ¶ added in v0.13.6
func (ReadDocxPageTool) Execute(_ context.Context, args json.RawMessage, tctx Context) (Result, error)
func (ReadDocxPageTool) ID ¶ added in v0.13.6
func (ReadDocxPageTool) ID() string
func (ReadDocxPageTool) Parameters ¶ added in v0.13.6
func (ReadDocxPageTool) Parameters() json.RawMessage
type ReadPdfPageTool ¶ added in v0.6.0
type ReadPdfPageTool struct{}
ReadPdfPageTool extracts the text of a single PDF page for the agent to read.
func (ReadPdfPageTool) Description ¶ added in v0.6.0
func (ReadPdfPageTool) Description() string
func (ReadPdfPageTool) Execute ¶ added in v0.6.0
func (ReadPdfPageTool) Execute(_ context.Context, args json.RawMessage, tctx Context) (Result, error)
func (ReadPdfPageTool) ID ¶ added in v0.6.0
func (ReadPdfPageTool) ID() string
func (ReadPdfPageTool) Parameters ¶ added in v0.6.0
func (ReadPdfPageTool) Parameters() json.RawMessage
type ReadTool ¶
type ReadTool struct{}
func (ReadTool) Description ¶
func (ReadTool) Parameters ¶
func (ReadTool) Parameters() json.RawMessage
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all registered tools.
func NewRegistry ¶
func NewRegistry() *Registry
type Result ¶
type Result struct {
Title string `json:"title"`
Metadata map[string]any `json:"metadata,omitempty"`
Output string `json:"output"`
// Image, when non-nil, is an image the tool wants the model to see (e.g. a
// rendered PDF page). It is delivered to the model alongside Output, in a
// provider-appropriate way. Only honored for vision-capable models.
Image *ResultImage `json:"image,omitempty"`
// Truncated marks that the tool already capped its own Output to a safe size.
// The agent loop's global truncation backstop leaves such results untouched;
// results without this flag are capped to MaxToolOutputBytes/MaxToolOutputLines
// before they enter the model context.
Truncated bool `json:"truncated,omitempty"`
}
Result is returned from tool execution.
type ResultImage ¶ added in v0.6.0
ResultImage is an image attachment on a tool Result. Data is base64-encoded image bytes; MediaType is e.g. "image/jpeg".
type SubmitDocIndexTool ¶ added in v0.6.0
SubmitDocIndexTool allows the index agent to store semantic page labels.
func NewSubmitDocIndexTool ¶ added in v0.6.0
func NewSubmitDocIndexTool(store *docindex.Store) SubmitDocIndexTool
NewSubmitDocIndexTool creates a new SubmitDocIndexTool.
func (SubmitDocIndexTool) Description ¶ added in v0.6.0
func (SubmitDocIndexTool) Description() string
func (SubmitDocIndexTool) Execute ¶ added in v0.6.0
func (t SubmitDocIndexTool) Execute(_ context.Context, args json.RawMessage, _ Context) (Result, error)
func (SubmitDocIndexTool) ID ¶ added in v0.6.0
func (SubmitDocIndexTool) ID() string
func (SubmitDocIndexTool) Parameters ¶ added in v0.6.0
func (SubmitDocIndexTool) Parameters() json.RawMessage
type TaskFunc ¶ added in v0.21.0
TaskFunc runs a read-only sub-agent session for a delegated investigation and returns its final written answer. Implemented by agent.LoopRunner.RunTaskSession and wired in from server.go/cli to avoid the tool→agent import cycle.
type TaskTool ¶ added in v0.21.0
type TaskTool struct {
Run TaskFunc
}
TaskTool lets a coding/planning agent delegate a focused, self-contained investigation to an autonomous read-only sub-agent. The sub-agent explores the codebase (read/glob/grep/codebase_map) and, if needed, the web (deep_search), then returns a concise written answer as the tool result. It cannot edit files or run shell commands, and it cannot spawn further sub-agents (depth-1).
func (TaskTool) Description ¶ added in v0.21.0
func (TaskTool) Parameters ¶ added in v0.21.0
func (TaskTool) Parameters() json.RawMessage
type ToolDef ¶
type ToolDef interface {
ID() string
Description() string
Parameters() json.RawMessage
Execute(ctx context.Context, args json.RawMessage, tctx Context) (Result, error)
}
ToolDef is the interface every tool must implement.
type TruncateDirection ¶ added in v0.21.0
type TruncateDirection int
TruncateDirection selects which end of the output to keep when it exceeds the caps. Most tools keep the head — the start of a file or listing is usually the useful part. Shell keeps the tail, because the end of a build/test log is where the error and summary live.
const ( KeepHead TruncateDirection = iota KeepTail )
type ViewImageTool ¶ added in v0.15.0
type ViewImageTool struct{}
ViewImageTool lets the agent view an image file (PNG, JPEG, GIF, BMP, WebP) on disk. For vision-capable models the decoded image is returned as a ResultImage; otherwise a textual description is returned.
func (ViewImageTool) Description ¶ added in v0.15.0
func (ViewImageTool) Description() string
func (ViewImageTool) Execute ¶ added in v0.15.0
func (ViewImageTool) Execute(_ context.Context, args json.RawMessage, tctx Context) (Result, error)
func (ViewImageTool) ID ¶ added in v0.15.0
func (ViewImageTool) ID() string
func (ViewImageTool) Parameters ¶ added in v0.15.0
func (ViewImageTool) Parameters() json.RawMessage
type WebSearchTool ¶ added in v0.8.0
type WebSearchTool struct {
Bridge *search.BridgeClient
}
WebSearchTool searches the web via the Playwright bridge and returns a markdown list of results.
func (WebSearchTool) Description ¶ added in v0.8.0
func (WebSearchTool) Description() string
func (WebSearchTool) Execute ¶ added in v0.8.0
func (t WebSearchTool) Execute(ctx context.Context, args json.RawMessage, _ Context) (Result, error)
func (WebSearchTool) ID ¶ added in v0.8.0
func (WebSearchTool) ID() string
func (WebSearchTool) Parameters ¶ added in v0.8.0
func (WebSearchTool) Parameters() json.RawMessage
type WriteTool ¶
type WriteTool struct{}
func (WriteTool) Description ¶
func (WriteTool) Parameters ¶
func (WriteTool) Parameters() json.RawMessage
Source Files
¶
- bash.go
- bash_safety.go
- bash_unix.go
- breakdown.go
- deep_search.go
- docx_index.go
- edit.go
- fetch_page.go
- glob.go
- grep.go
- latex_pdf.go
- memory_recall.go
- pathlock.go
- pdf_index.go
- pdf_render.go
- project_index.go
- project_memory_recall.go
- read.go
- read_docx_page.go
- read_pdf_page.go
- submit_doc_index.go
- task.go
- tool.go
- truncate.go
- view_image.go
- web_search.go
- write.go