Documentation
¶
Overview ¶
Package tool provides primitives for defining and executing tools that can be used by LLM-powered agents. It is provider-agnostic, with no dependency on any specific LLM backend.
Class: primitive UseWhen: Always required with axon-loop. The loop drives behaviour through tool calls.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeArguments ¶ added in v0.2.0
NormalizeArguments coerces tool call argument values to match the JSON Schema types declared in the tool's parameter schema. LLMs sometimes return numbers as strings, bools as strings, etc. Unknown or missing properties are left unchanged.
types maps property names to their JSON Schema type strings (e.g. "number", "boolean", "string", "array", "object").
Types ¶
type ParameterSchema ¶
type ParameterSchema struct {
Type string `json:"type"`
Required []string `json:"required,omitempty"`
Properties map[string]PropertySchema `json:"properties,omitempty"`
}
ParameterSchema describes the parameters a tool accepts.
type PropertySchema ¶
type PropertySchema struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Enum []any `json:"enum,omitempty"`
Default any `json:"default,omitempty"`
Items *PropertySchema `json:"items,omitempty"`
Properties map[string]PropertySchema `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
}
PropertySchema describes a single parameter property using JSON Schema.
type TextGenerator ¶
TextGenerator is a simple function that sends a prompt to an LLM and returns the response text. Used by components that need LLM capabilities without depending on a full ChatClient.
type ToolCallAction ¶ added in v0.2.0
type ToolCallAction struct{ Calls []ToolCall }
ToolCallAction is returned when a tool call is detected in the stream.
func (ToolCallAction) IsFilterAction ¶ added in v0.2.0
func (ToolCallAction) IsFilterAction()
type ToolCallMatcher ¶ added in v0.2.0
type ToolCallMatcher struct{}
ToolCallMatcher detects tool call JSON emitted as text content.
func NewToolCallMatcher ¶ added in v0.2.0
func NewToolCallMatcher() *ToolCallMatcher
func (*ToolCallMatcher) Extract ¶ added in v0.2.0
func (m *ToolCallMatcher) Extract(buf []byte) tape.FilterAction
func (*ToolCallMatcher) Name ¶ added in v0.2.0
func (m *ToolCallMatcher) Name() string
func (*ToolCallMatcher) Scan ¶ added in v0.2.0
func (m *ToolCallMatcher) Scan(buf []byte, _ string) tape.MatchResult
type ToolContext ¶
type ToolContext struct {
Ctx context.Context
UserID string
Username string
AgentSlug string
ConversationID string
SystemPrompt string
}
ToolContext carries request-scoped state into tool execution.
type ToolDef ¶
type ToolDef struct {
Name string
Description string
Parameters ParameterSchema
Execute func(ctx *ToolContext, args map[string]any) ToolResult
}
ToolDef describes a tool that an agent can invoke.
Example ¶
package main
import (
"fmt"
tool "github.com/benaskins/axon-tool"
)
func main() {
greet := tool.ToolDef{
Name: "greet",
Description: "Greet a user by name",
Parameters: tool.ParameterSchema{
Type: "object",
Required: []string{"name"},
Properties: map[string]tool.PropertySchema{
"name": {
Type: "string",
Description: "The name of the person to greet",
},
},
},
Execute: func(ctx *tool.ToolContext, args map[string]any) tool.ToolResult {
name, _ := args["name"].(string)
return tool.ToolResult{Content: "Hello, " + name + "!"}
},
}
fmt.Println(greet.Name)
fmt.Println(greet.Description)
}
Output: greet Greet a user by name
type ToolResult ¶
type ToolResult struct {
Content string
}
ToolResult is the output of a tool execution.