pig/tool
Tool types and registry for the pig agent library.
A Tool pairs a ToolDefinition (schema for the LLM) with a handler
function. The handler receives parsed dynamic.Dynamic arguments and
returns either a json.Json result or a structured ToolError.
Types
A tool pairs a definition (shown to the LLM) with a handler function.
The handler receives parsed JSON arguments as dynamic.Dynamic and
returns either a json.Json result or a structured ToolError.
pub type Tool {
Tool(
definition: tool_definition.ToolDefinition,
handler: fn(dynamic.Dynamic) -> Result(json.Json, ToolError),
)
}
Constructors
-
Tool( definition: tool_definition.ToolDefinition, handler: fn(dynamic.Dynamic) -> Result(json.Json, ToolError), )
Structured error from tool execution.
pub type ToolError {
ToolError(message: String)
}
Constructors
-
ToolError(message: String)
A tool’s name and description for composing into a system prompt.
pub type ToolPrompt {
ToolPrompt(name: String, description: String)
}
Constructors
-
ToolPrompt(name: String, description: String)
Values
pub fn list_definitions(
registry: ToolRegistry,
) -> List(tool_definition.ToolDefinition)
List all tool definitions in the registry.
pub fn list_tool_prompts(
registry: ToolRegistry,
) -> List(ToolPrompt)
Extract name and description from each tool in the registry. Used to auto-compose an “Available tools” section in the system prompt.
pub fn lookup(
registry: ToolRegistry,
name: String,
) -> Result(Tool, Nil)
Look up a tool by name. Returns Error(Nil) if not found.
pub fn register(
registry: ToolRegistry,
tool: Tool,
) -> ToolRegistry
Register a tool in the registry. If a tool with the same name already exists, it is overwritten.