tool

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrToolDenied = errors.New("tool not permitted")
View Source
var ErrUnknownBuiltin = errors.New("unknown builtin tool")
View Source
var ErrUnknownManifest = errors.New("unknown tool manifest")

Functions

func BuildSpecs

func BuildSpecs(reg Registry) []model.ToolSpec

BuildSpecs converts a Registry into model.ToolSpec definitions.

func ExecDirect

func ExecDirect(ctx context.Context, cmdStr string) (string, error)

ExecDirect runs a shell command directly

func IsBuiltinTool

func IsBuiltinTool(name string) bool

IsBuiltinTool checks if the given name is a builtin tool

func SetPermissions

func SetPermissions(list []string)

SetPermissions configures which tools may execute. Nil or empty slice allows all.

Types

type AuditEvent

type AuditEvent struct {
	Tool      string         `json:"tool"`
	Args      map[string]any `json:"args"`
	Duration  int64          `json:"duration_ms"`
	Error     string         `json:"error,omitempty"`
	Timestamp time.Time      `json:"ts"`
}

AuditEvent represents a tool execution event.

type ExecFn

type ExecFn func(context.Context, map[string]any) (string, error)

ExecFn defines the signature for tool execution functions.

type Registry

type Registry map[string]Tool

func DefaultRegistry

func DefaultRegistry() Registry

DefaultRegistry returns all builtin tools.

func WrapWithAudit

func WrapWithAudit(reg Registry, w io.Writer) Registry

WrapWithAudit wraps all tools in a registry with audit logging to w.

func (Registry) Use

func (r Registry) Use(name string) (Tool, bool)

type TerminalAware

type TerminalAware interface {
	Tool
	Terminal() bool
}

TerminalAware is an optional interface a Tool can implement to signal that a successful execution should normally terminate the agent loop without an additional model reflection pass. Example: the "agent" delegation tool returns a final answer string from the delegated agent.

type Tool

type Tool interface {
	Name() string
	Description() string
	JSONSchema() map[string]any
	Execute(ctx context.Context, args map[string]any) (string, error)
}

Tool represents an executable action available to agents.

func FromManifest

func FromManifest(m config.ToolManifest) (Tool, error)

func MarkTerminal

func MarkTerminal(t Tool) Tool

MarkTerminal wraps a Tool so the agent runtime can detect it and finalize immediately after successful execution (if all tool calls in a step are terminal and there are no errors).

func New

func New(name, desc string, fn func(context.Context, map[string]any) (string, error)) Tool

func NewWithSchema

func NewWithSchema(name, desc string, schema map[string]any, fn func(context.Context, map[string]any) (string, error)) Tool

Jump to

Keyboard shortcuts

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