tool

package
v0.3.52 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: Apache-2.0 Imports: 3 Imported by: 57

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImplSpecificOptions

func GetImplSpecificOptions[T any](base *T, opts ...Option) *T

GetImplSpecificOptions provides tool author the ability to extract their own custom options from the unified Option type. T: the type of the impl specific options struct. This function should be used within the tool implementation's InvokableRun or StreamableRun functions. It is recommended to provide a base T as the first argument, within which the tool author can provide default values for the impl specific options. eg.

type customOptions struct {
    conf string
}
defaultOptions := &customOptions{}

customOptions := tool.GetImplSpecificOptions(defaultOptions, opts...)

Types

type BaseTool

type BaseTool interface {
	Info(ctx context.Context) (*schema.ToolInfo, error)
}

BaseTool get tool info for ChatModel intent recognition.

type CallbackInput

type CallbackInput struct {
	// ArgumentsInJSON is the arguments in json format for the tool.
	ArgumentsInJSON string
	// Extra is the extra information for the tool.
	Extra map[string]any
}

CallbackInput is the input for the tool callback.

func ConvCallbackInput

func ConvCallbackInput(src callbacks.CallbackInput) *CallbackInput

ConvCallbackInput converts the callback input to the tool callback input.

type CallbackOutput

type CallbackOutput struct {
	// Response is the response for the tool.
	Response string
	// Extra is the extra information for the tool.
	Extra map[string]any
}

CallbackOutput is the output for the tool callback.

func ConvCallbackOutput

func ConvCallbackOutput(src callbacks.CallbackOutput) *CallbackOutput

ConvCallbackOutput converts the callback output to the tool callback output.

type InvokableTool

type InvokableTool interface {
	BaseTool

	// InvokableRun call function with arguments in JSON format
	InvokableRun(ctx context.Context, argumentsInJSON string, opts ...Option) (string, error)
}

InvokableTool the tool for ChatModel intent recognition and ToolsNode execution. nolint: byted_s_interface_name

type Option

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

Option defines call option for InvokableTool or StreamableTool component, which is part of component interface signature. Each tool implementation could define its own options struct and option funcs within its own package, then wrap the impl specific option funcs into this type, before passing to InvokableRun or StreamableRun.

func WrapImplSpecificOptFn

func WrapImplSpecificOptFn[T any](optFn func(*T)) Option

WrapImplSpecificOptFn wraps the impl specific option functions into Option type. T: the type of the impl specific options struct. Tool implementations are required to use this function to convert its own option functions into the unified Option type. For example, if the tool defines its own options struct:

type customOptions struct {
    conf string
}

Then the tool needs to provide an option function as such:

func WithConf(conf string) Option {
    return WrapImplSpecificOptFn(func(o *customOptions) {
		o.conf = conf
	}
}

.

type StreamableTool

type StreamableTool interface {
	BaseTool

	StreamableRun(ctx context.Context, argumentsInJSON string, opts ...Option) (*schema.StreamReader[string], error)
}

StreamableTool the stream tool for ChatModel intent recognition and ToolsNode execution. nolint: byted_s_interface_name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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