Documentation
¶
Overview ¶
Package functool turns a typed Go function into a tool.FuncTool via New and MustNew, deriving the tool's input and output JSON schemas from the function's parameter and return types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustNew ¶
func MustNew[In, Out any](cfg Config, h HandlerFor[In, Out]) tool.FuncTool
MustNew is like New but panics if schema construction fails. It is intended for package-level initialization where a construction failure is a programming error that should surface immediately.
func New ¶
New builds a tool.FuncTool from cfg and the typed handler h. It derives the JSON input schema from In and the output schema from Out, and validates arguments before invoking h. It returns an error if either schema cannot be constructed.
The input schema always describes a JSON object. Object-shaped structs use their JSON fields as arguments. Other inputs require a single property:
- "values" for slices and arrays;
- "entries" for maps;
- "value" for all other types.
Pointers follow their pointed-to type. For example, an []int input requires {"values":[1,2]}; a bare array is rejected. Config.ArgName overrides the wrapped property name and cannot be set for object-shaped struct inputs.
Types ¶
type Config ¶
type Config struct {
Name string
Description string
// ArgName overrides the name of the single property wrapping the input.
// When empty, [New] chooses the name based on the input type. Setting ArgName
// for an object-shaped struct input causes [New] to return an error.
ArgName string
}
Config represents the configuration for a FuncTool.
type Handler ¶
A Handler handles a call to tools/call.
This is a low-level API. It does not do any pre- or post-processing of the request or result: the params contain raw arguments, no input validation is performed, and the result is returned to the user as-is, without any validation of the output.
type HandlerFor ¶
A HandlerFor handles a call to tools/call with typed arguments and results.
HandlerFor provides significant functionality out of the box, and enforces that the tool conforms to the Agent spec:
- The In type provides a default input schema for the tool.
- The input value is automatically unmarshaled from req.Params.Arguments.
- The input value is automatically validated against its input schema. Invalid input is rejected before getting to the handler.