2026-06-28 23:03:57 +00:00
|
|
|
# pkg/tools
|
|
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
> Tools system (function calling) with JSON Schema, sandbox, and permissions.
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
## Responsibility
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
Allow the LLM to invoke functions defined in Go, with schema validation and sandboxing.
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
## Public API
|
2026-06-28 23:03:57 +00:00
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
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
|
2026-06-30 20:40:37 +00:00
|
|
|
Examples []Example // few-shot for the LLM
|
2026-06-28 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2026-06-30 20:40:37 +00:00
|
|
|
Thought string // optional: chain-of-thought from the LLM
|
2026-06-28 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Result struct {
|
|
|
|
|
Content string
|
|
|
|
|
IsError bool
|
|
|
|
|
Metadata map[string]string
|
|
|
|
|
Artifacts []Artifact
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Permission int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
Allow Permission = iota
|
|
|
|
|
Ask
|
|
|
|
|
Deny
|
|
|
|
|
)
|
|
|
|
|
```
|
|
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
## Integrated sandbox
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
`pkg/tools` uses `os.Root` (Go 1.24+) for filesystem sandbox:
|
2026-06-28 23:03:57 +00:00
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
sandbox := tools.NewSandbox("./workspace")
|
2026-06-30 20:40:37 +00:00
|
|
|
sandbox.Register(myReadTool) // can only read inside the workspace
|
2026-06-28 23:03:57 +00:00
|
|
|
```
|
|
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
See [pkg/tools/sandbox/](sandbox/) for details.
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
## Generic tools included
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
- `http_fetch` — GET URL with HTML→markdown
|
|
|
|
|
- `json_parse` — Parse arbitrary JSON
|
2026-06-28 23:03:57 +00:00
|
|
|
- `datetime_now` — Current timestamp
|
|
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
Product-specific tools (e.g., `read_file`, `bash` for software dev) are defined by each consumer in their own `internal/tools/`.
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
## See also
|
2026-06-28 23:03:57 +00:00
|
|
|
|
2026-06-30 20:40:37 +00:00
|
|
|
- [pkg/agent](../agent/README.md) — Executes tool calls
|
|
|
|
|
- [pkg/llm](../llm/README.md) — Tools are sent to the LLM
|