tool

package
v0.98.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package tool provides tool registration and execution for agent runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildLLMTools

func BuildLLMTools(tools []Tool) []llms.Tool

BuildLLMTools converts registered tools into langchaingo tool definitions.

func ErrorResult added in v0.95.0

func ErrorResult(callID, name, code, message, hint string) msg.ToolResultMessage

ErrorResult builds an inline tool error result with an actionable message.

func FormatToolError added in v0.95.0

func FormatToolError(code, message, hint string) string

FormatToolError builds an actionable tool error message for the model.

func ValidateArgs added in v0.95.0

func ValidateArgs(schema map[string]any, args map[string]any) error

ValidateArgs checks required fields and top-level JSON Schema types against args. It does not implement a full JSON Schema engine.

Types

type BatchRequest

type BatchRequest struct {
	Assistant msg.AssistantMessage
	Context   *msg.Context
	Registry  *Registry
	Mode      msg.ToolExecutionMode
	Before    msg.BeforeToolCallFn
	After     msg.AfterToolCallFn
	Emit      func(context.Context, agentevent.Event) error
}

BatchRequest describes one tool execution batch from an assistant turn.

type BatchResult

type BatchResult struct {
	Messages  []msg.ToolResultMessage
	Terminate bool
}

BatchResult is the outcome of executing one assistant tool batch.

func ExecuteBatch

func ExecuteBatch(ctx context.Context, req BatchRequest) (BatchResult, error)

ExecuteBatch runs tool calls from an assistant message and returns tool result messages.

type Registry

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

Registry stores registered tools and an optional active allowlist.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty tool registry.

func (*Registry) ActiveTools

func (r *Registry) ActiveTools() []Tool

ActiveTools returns tools allowed for the current run.

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get returns a tool by name.

func (*Registry) Register

func (r *Registry) Register(t Tool) error

Register adds a tool and rejects duplicate names.

func (*Registry) SetActive

func (r *Registry) SetActive(names []string)

SetActive restricts the tools exposed to the model; nil or empty means all registered tools.

type Tool

type Tool interface {
	Name() string
	Description() string
	Parameters() map[string]any
	Execute(ctx context.Context, id string, args map[string]any, onUpdate UpdateHandler) (msg.ToolResultMessage, error)
}

Tool is an executable capability exposed to the agent loop.

type UpdateHandler

type UpdateHandler func(update string) error

UpdateHandler receives incremental tool execution progress.

Jump to

Keyboard shortcuts

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