Documentation
¶
Overview ¶
Package tools implements the ToolRegistry: Compile (run once after Registry.Compile) and ForIdentity (run per agent turn) following the deterministic O(len(CompiledDocs)) generation algorithm in TAD §10.
See TAD §10 and PRD §24 for the full specification. Implemented in Phase 7.
Package tools implements the ToolRegistry: Compile (run once after Registry.Compile) and ForIdentity (run per agent turn) following the deterministic O(len(CompiledDocs)) generation algorithm in TAD §10.
See TAD §10 and PRD §24 for the full specification. Implemented in Phase 7.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterCustomTool ¶
func RegisterCustomTool(tool Tool)
RegisterCustomTool records a hand-authored tool merged into every ToolRegistry's ForIdentity output (TAD §10.4). Custom tools bypass the Registry-derived generation: they are filtered only by their own AllowedRoles. Mirrors the package-level registration pattern of api.RegisterMethod and schema.RegisterValidator.
func ResetCustomTools ¶
func ResetCustomTools()
ResetCustomTools clears all custom tool registrations (test helper).
Types ¶
type Tool ¶
type Tool struct {
Name string
Description string
Parameters map[string]any // JSON Schema
AllowedRoles []string
Handler func(ctx context.Context, args map[string]any) (any, error)
}
Tool is a hand-authored custom agent tool (TAD §2.6). Custom tools bypass the §10.1–§10.3 Registry-derived generation entirely: they are merged into the per-identity tool list by ForIdentity, filtered only by their own AllowedRoles, and are exempt from the agent_hidden/GatedFields machinery since their Parameters are hand-authored (TAD §10.4). The Handler is executed by the Agent Executor in Phase 8; Phase 7 only publishes the definition.
func CustomTools ¶
func CustomTools() []Tool
CustomTools returns a snapshot of every registered custom tool, exposing their Handlers to the Agent Executor (agent/runtime, Phase 8). It mirrors the rpc.Methods accessor pattern; the ToolRegistry interface itself does not need them because ForIdentity already merges the definitions.
type ToolRegistry ¶
type ToolRegistry interface {
// Compile runs once, immediately after Registry.Compile (initialization
// step 9, TAD §5.3), generating one identity-independent template per
// CompiledDoc plus one per role-gated RPC method (TAD §10.1).
Compile(reg schema.Registry) error
// ForIdentity runs once per Agent Runtime turn (TAD §10.3), projecting
// each template through the caller's permissions and merging custom tools
// (TAD §10.4) to produce the tool list actually sent to the LLM.
ForIdentity(ctx context.Context, id auth.Identity) []llm.ToolDefinition
}
ToolRegistry generates and projects agent tool definitions. See TAD §10.
func NewToolRegistry ¶
func NewToolRegistry(permEngine perm.Engine, wfEngine workflow.Engine) ToolRegistry
NewToolRegistry constructs a ToolRegistry. permEngine is required for per-identity projection (TAD §10.3); wfEngine may be nil (no workflowed DocTypes → no execute_action tools).
type ToolTemplate ¶
type ToolTemplate struct {
DocType string
// Verb is one of "search"|"list"|"read"|"create"|"update"|"delete"|
// "execute_action"|"method".
Verb string
// Name is snake_case(Verb) + "_" + snake_case(DocType), e.g.
// "create_employee". The read tool is named "get_{doctype}".
Name string
// BaseSchema is the JSON Schema built from ALL fields, including gated
// ones (TAD §10).
BaseSchema map[string]any
// GatedFields lists fields whose oj:"permission=role" tag is non-empty
// (Go struct field names, as returned by perm.Engine.AllowedFields).
GatedFields []string
// Description is the human/agent-readable tool summary.
Description string
// contains filtered or unexported fields
}
ToolTemplate is the identity-independent, Registry-derived tool definition produced at compile time. BaseSchema always includes gated fields so the template is safely cacheable; ForIdentity projects it per caller. See TAD §10.