Formatting only (struct field alignment, import ordering) across the files that didn't comply — no semantic changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| sandbox | ||
| README.es.md | ||
| README.md | ||
| registry.go | ||
| registry_test.go | ||
| types.go | ||
| types_test.go | ||
pkg/tools
Tools system (function calling) with JSON Schema, sandbox, and permissions.
Responsibility
Allow the LLM to invoke functions defined in Go, with schema validation and sandboxing.
Public API
type Tool struct {
Name string
Description string
InputSchema json.RawMessage // JSON Schema draft-07+
Handler Handler // func(ctx, args json.RawMessage) (Result, error)
Permission Permission // Allow | Ask | Deny
Examples []Example // few-shot for the LLM
}
type Registry interface {
Register(tool Tool) error
Get(name string) (Tool, bool)
List() []Tool
Filter(policy Policy) []Tool
}
type Call struct {
ID string
Name string
Arguments json.RawMessage
Thought string // optional: chain-of-thought from the LLM
}
type Result struct {
Content string
IsError bool
Metadata map[string]string
Artifacts []Artifact
}
type Permission int
const (
Allow Permission = iota
Ask
Deny
)
Integrated sandbox
pkg/tools uses os.Root (Go 1.24+) for filesystem sandbox:
sandbox := tools.NewSandbox("./workspace")
sandbox.Register(myReadTool) // can only read inside the workspace
See pkg/tools/sandbox/ for details.
Generic tools included
http_fetch— GET URL with HTML→markdownjson_parse— Parse arbitrary JSONdatetime_now— Current timestamp
Product-specific tools (e.g., read_file, bash for software dev) are defined by each consumer in their own internal/tools/.