toolkit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// RespondName is the name of the tool a model calls to reply with JSON
	RespondName = "respond"

	// RespondPrompt is added to the system prompt when the reply has a schema
	RespondPrompt = "Reply in JSON, by calling the " + RespondName + " tool with your final answer as its result, which must match the tool's schema. Don't reply with text instead."

	// RespondNudge is the message sent when the model replies with text, when
	// the reply has a schema
	RespondNudge = "Reply by calling the " + RespondName + " tool with your answer as its result, which must match the tool's schema."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Base added in v0.5.0

type Base struct{}

Base provides default implementations of the optional llm.Tool methods. Embed Base in a tool to avoid boilerplate, and override the methods the tool needs.

func (Base) OutputSchema added in v0.5.0

func (Base) OutputSchema() *jsonschema.Schema

OutputSchema returns nil, as the tool has no structured output schema

type CredentialsProvider added in v0.5.0

type CredentialsProvider interface {
	// Expand returns the value with each placeholder replaced with its
	// credential, or an error when a credential doesn't exist
	Expand(ctx context.Context, value string) (string, error)
}

CredentialsProvider expands credentials, such as a tool's API key, whose placeholders, such as ${WEATHERAPI_KEY} or $WEATHERAPI_KEY, are replaced with the credentials they name, as the registry's credentials provider does, so one provider can be both's

type Opt added in v0.5.0

type Opt func(*opt) error

Opt is a functional option for toolkit configuration.

func WithClientOpts added in v0.5.0

func WithClientOpts(clientopts ...client.ClientOpt) Opt

WithClientOpts sets the client options for the HTTP clients of tools which call APIs, e.g. for timeouts.

func WithCredentialsProvider added in v0.5.0

func WithCredentialsProvider(provider CredentialsProvider) Opt

WithCredentialsProvider sets the provider of credentials, such as API keys, for tools which need them, which are environment variables, without one, or with a nil provider

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer used for tracing operations.

type Respond added in v0.5.0

type Respond struct {
	Base
	// contains filtered or unexported fields
}

Respond is the tool a model calls to reply with JSON which conforms to a schema. The tool's input is an object, as the input of a tool must be, whose result is the reply, so the reply can be any JSON. The tool's result is the reply, when it conforms, or an error the model can correct.

func NewRespond added in v0.5.0

func NewRespond(schema json.RawMessage) (*Respond, error)

NewRespond returns the tool a model calls to reply with JSON which conforms to the schema. Returns an error if the schema isn't a JSON schema.

func (*Respond) Description added in v0.5.0

func (t *Respond) Description() string

func (*Respond) InputSchema added in v0.5.0

func (t *Respond) InputSchema() *jsonschema.Schema

func (*Respond) Name added in v0.5.0

func (t *Respond) Name() string

func (*Respond) Run added in v0.5.0

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

Run returns the reply, which is the input's result, as JSON, when the input conforms to the schema, or an error which says how it doesn't

type Toolkit

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

Toolkit is a set of tools, by name, which models can call

func New

func New(ctx context.Context, opts ...Opt) (_ *Toolkit, err error)

New returns a toolkit with the options

func (*Toolkit) Add added in v0.5.0

func (self *Toolkit) Add(namespace string, tools ...llm.Tool) error

Add adds the tools in the namespace to the toolkit, by their canonical name, which is the namespace and the tool's name separated by a colon, such as "weatherapi:current". The namespace must be an identifier. Returns an error, and adds none of the tools, if the namespace isn't valid or has already been added, or a tool is nil, its name isn't valid, or two tools have the same name.

func (*Toolkit) AvailableTools added in v0.5.0

func (self *Toolkit) AvailableTools(ctx context.Context, names ...string) (_ []llm.Tool, skipped []string, err error)

AvailableTools returns the tools with the names, as with Tools, except a name which isn't a tool, or a namespace which doesn't exist, is skipped, rather than an error, as when the tools of a namespace aren't available. Returns the names which were skipped, and the same errors as Tools otherwise.

func (*Toolkit) CallTool added in v0.5.0

func (self *Toolkit) CallTool(ctx context.Context, name string, input json.RawMessage) (_ json.RawMessage, err error)

CallTool runs the tool with the name, which is its canonical name, such as "weatherapi:current", or its name without a namespace, such as "current", with the input, which may be empty, and returns its result as JSON, or nil when the tool has no result. Returns ErrNotFound if there is no tool with the name, ErrConflict if the name has no namespace, and more than one namespace has a tool with the name, or ErrBadParameter if the input isn't valid JSON, or doesn't match the tool's input schema. The tool is run without holding the toolkit's lock, so tools can be added and removed while it runs.

func (*Toolkit) ClientOpts added in v0.5.0

func (self *Toolkit) ClientOpts() []client.ClientOpt

ClientOpts returns the client options for the HTTP clients of tools which call APIs

func (*Toolkit) Credential added in v0.5.0

func (self *Toolkit) Credential(ctx context.Context, key string) (_ string, err error)

Credential returns the value of the credential with the key, such as a tool's API key, from the toolkit's credential provider

func (*Toolkit) GetTool added in v0.5.0

func (self *Toolkit) GetTool(ctx context.Context, name string) (_ *schema.Tool, err error)

GetTool returns the tool with the name, which is its canonical name, such as "weatherapi:current", or its name without a namespace, such as "current". Returns ErrNotFound if there is no tool with the name, or ErrConflict if the name has no namespace, and more than one namespace has a tool with the name.

func (*Toolkit) ListTools added in v0.5.0

func (self *Toolkit) ListTools(ctx context.Context, req schema.ToolListRequest) (_ *schema.ToolList, err error)

ListTools returns the tools in the toolkit, or the tools in the namespace in the request, in order of canonical name, with their number

func (*Toolkit) ToolNames added in v0.5.0

func (self *Toolkit) ToolNames(ctx context.Context, names ...string) (_ []string, err error)

ToolNames returns the names, as with Tools, as canonical names, such as "weatherapi:current" for "current". A namespace and "*", such as "ollama:*", or "*", is returned as it is, so it includes tools added to the namespace, or the toolkit, later. Returns the same errors as Tools.

func (*Toolkit) Tools added in v0.5.0

func (self *Toolkit) Tools(ctx context.Context, names ...string) (_ []llm.Tool, err error)

Tools returns the tools with the names, which are their canonical names, their names without a namespace, a namespace and "*", such as "ollama:*", for all the tools in the namespace, or "*" for all the tools. No names are no tools. Each tool is wrapped with a new name, which is its namespace and name separated by an underscore, such as "weatherapi_current". Returns ErrNotFound if there is no tool with a name, or no namespace for "*", ErrConflict if a name without a namespace is ambiguous, or two tools have the same new name, or ErrBadParameter if a tool is named more than once, including by a "*", or its new name isn't a valid tool name, such as when it's too long.

Directories

Path Synopsis
httpclient
httpclient implements an API client for the Home Assistant REST API https://developers.home-assistant.io/docs/api/rest/
httpclient implements an API client for the Home Assistant REST API https://developers.home-assistant.io/docs/api/rest/
httpclient
httpclient implements an API client for NewsAPI https://newsapi.org/docs
httpclient implements an API client for NewsAPI https://newsapi.org/docs
httpclient
httpclient implements an API client for Ollama's web search and web fetch https://docs.ollama.com/capabilities/web-search
httpclient implements an API client for Ollama's web search and web fetch https://docs.ollama.com/capabilities/web-search
httpclient
httpclient implements an API client for WeatherAPI https://www.weatherapi.com/docs/
httpclient implements an API client for WeatherAPI https://www.weatherapi.com/docs/

Jump to

Keyboard shortcuts

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