tool

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OutputToolName is the well-known name for the structured output tool.
	OutputToolName = "submit_output"

	// OutputToolInstruction is appended to the system prompt when the
	// output tool is active, directing the model to call it with the final answer.
	OutputToolInstruction = "Use available tools to gather information. When ready, only call " + OutputToolName + " with your final answer, do not output any other text."
)

Variables

This section is empty.

Functions

func WithTool added in v0.3.0

func WithTool(t Tool) opt.Opt

WithTool adds an individual tool to the generation options. Individual tools are appended under opt.ToolKey and merged with toolkit tools by each provider.

func WithToolkit added in v0.1.0

func WithToolkit(toolkit *Toolkit) opt.Opt

WithToolkit sets a toolkit for generation options. The toolkit is stored under opt.ToolkitKey and can be retrieved with opts.Get(opt.ToolkitKey) and type-asserted to *Toolkit.

Types

type OutputTool added in v0.3.0

type OutputTool struct {
	// contains filtered or unexported fields
}

OutputTool wraps a JSON schema as a tool, allowing the model to produce structured output by "calling" this tool with the desired data. This avoids the conflict in providers like Gemini that don't support function calling combined with a response JSON schema.

func NewOutputTool added in v0.3.0

func NewOutputTool(s *jsonschema.Schema) *OutputTool

NewOutputTool creates a tool whose parameter schema is the given JSON schema. When the model calls this tool, its arguments ARE the structured output.

func (*OutputTool) Description added in v0.3.0

func (t *OutputTool) Description() string

func (*OutputTool) Name added in v0.3.0

func (t *OutputTool) Name() string

func (*OutputTool) Run added in v0.3.0

func (t *OutputTool) Run(_ context.Context, input json.RawMessage) (any, error)

func (*OutputTool) Schema added in v0.3.0

func (t *OutputTool) Schema() (*jsonschema.Schema, error)

func (*OutputTool) Validate added in v0.3.0

func (t *OutputTool) Validate(data json.RawMessage) error

Validate checks that the given JSON conforms to the output schema. Returns nil if the data is valid or no schema was provided.

type Tool added in v0.1.0

type Tool interface {
	// Return the name of the tool
	Name() string

	// Return the description of the tool
	Description() string

	// Return the JSON schema for the tool input
	Schema() (*jsonschema.Schema, error)

	// Run the tool with the given input as JSON (may be nil)
	Run(ctx context.Context, input json.RawMessage) (any, error)
}

Tool is an interface for a tool with a name, description and JSON schema

type Toolkit added in v0.1.0

type Toolkit struct {
	// contains filtered or unexported fields
}

Toolkit is a collection of tools with unique names

func NewToolkit added in v0.1.0

func NewToolkit(tools ...Tool) (*Toolkit, error)

NewToolkit creates a new toolkit with the given tools. Returns an error if any tool has an invalid or duplicate name.

func (*Toolkit) Feedback added in v0.1.0

func (tk *Toolkit) Feedback(call schema.ToolCall) string

Feedback returns a human-readable description of a tool call, including the tool name and its description when available.

func (*Toolkit) Lookup added in v0.1.0

func (tk *Toolkit) Lookup(name string) Tool

Lookup returns a tool by name, or nil if not found

func (*Toolkit) Register added in v0.1.0

func (tk *Toolkit) Register(tools ...Tool) error

Register adds one or more tools to the toolkit. Returns an error if any tool has an invalid or duplicate name, or if the name is reserved (e.g. "submit_output").

func (*Toolkit) Run added in v0.1.0

func (tk *Toolkit) Run(ctx context.Context, name string, input any) (any, error)

Run executes a tool by name with the given input. The input should be json.RawMessage or nil. Returns an error if the tool is not found, the input does not match the schema, or the tool execution fails.

func (*Toolkit) String added in v0.1.0

func (tk *Toolkit) String() string

func (*Toolkit) Tools added in v0.1.0

func (tk *Toolkit) Tools() []Tool

Tools returns all tools in the toolkit

Jump to

Keyboard shortcuts

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