tool

package
v0.0.0-...-8c5cae0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReadToolName is the mandatory built-in read tool name.
	ReadToolName = "READ"
)

Variables

This section is empty.

Functions

func AddTruncationMeta

func AddTruncationMeta(result map[string]any, info TruncationInfo) map[string]any

AddTruncationMeta attaches truncation metadata to a tool result map.

func BuildMap

func BuildMap(tools []Tool) (map[string]Tool, error)

BuildMap creates a name-indexed tool lookup map.

func Declarations

func Declarations(tools []Tool) []model.ToolDefinition

Declarations returns model-visible declarations for tools.

func TruncateString

func TruncateString(s string, policy TruncationPolicy) (string, int)

TruncateString truncates a string in the middle to fit the policy budget.

func TruncateText

func TruncateText(s string, policy TruncationPolicy) (string, int)

TruncateText truncates text and includes total line count when truncated.

Types

type CoreToolsConfig

type CoreToolsConfig struct {
	Read    filesystem.ReadConfig
	Runtime toolexec.Runtime
}

CoreToolsConfig configures mandatory kernel tools.

type Handler

type Handler[TArgs, TResult any] func(context.Context, TArgs) (TResult, error)

Handler is a typed function tool handler.

type Tool

type Tool interface {
	Name() string
	Description() string
	Declaration() model.ToolDefinition
	Run(context.Context, map[string]any) (map[string]any, error)
}

Tool is the executable tool contract.

func EnsureCoreTools

func EnsureCoreTools(userTools []Tool, cfg CoreToolsConfig) ([]Tool, error)

EnsureCoreTools injects mandatory kernel tools and returns a new tool list.

func NewFunction

func NewFunction[TArgs, TResult any](name, description string, handler Handler[TArgs, TResult]) (Tool, error)

NewFunction creates a typed function-backed tool.

type TruncationInfo

type TruncationInfo struct {
	Truncated       bool
	Policy          string
	MaxTokens       int
	MaxBytes        int
	EstimatedTokens int
	EstimatedBytes  int
	RemovedTokens   int
	RemovedBytes    int
	OmittedItems    int
}

TruncationInfo describes truncation that was applied.

func TruncateMap

func TruncateMap(input map[string]any, policy TruncationPolicy) (map[string]any, TruncationInfo)

TruncateMap applies truncation to a tool result map and returns the updated map plus truncation info.

type TruncationPolicy

type TruncationPolicy struct {
	MaxTokens int
	MaxBytes  int
}

TruncationPolicy defines limits for truncating tool output.

func DefaultTruncationPolicy

func DefaultTruncationPolicy() TruncationPolicy

DefaultTruncationPolicy returns default tool output truncation policy.

Directories

Path Synopsis
builtin
lsp

Jump to

Keyboard shortcuts

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