functool

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 6 Imported by: 0

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

func New[In, Out any](cfg Config, h HandlerFor[In, Out]) (tool.FuncTool, error)

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, wrapping non-struct inputs and validating arguments before invoking h. It returns an error if either schema cannot be constructed.

Types

type Config

type Config struct {
	Name        string
	Description string
}

Config represents the configuration for a FuncTool.

type Handler

type Handler func(ctx context.Context, args string) (any, error)

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

type HandlerFor[In, Out any] func(context.Context, In) (Out, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL