Documentation
¶
Index ¶
- Constants
- func WithTool(t llm.Tool) opt.Opt
- func WithToolkit(toolkit *Toolkit) opt.Opt
- type DefaultTool
- type OutputTool
- type Toolkit
- func (tk *Toolkit) AddBuiltin(tools ...llm.Tool) error
- func (tk *Toolkit) AddConnector(url string, c llm.Connector) error
- func (tk *Toolkit) Close() error
- func (tk *Toolkit) Feedback(call schema.ToolCall) string
- func (tk *Toolkit) ListTools(req schema.ListToolsRequest) []llm.Tool
- func (tk *Toolkit) Lookup(name string) llm.Tool
- func (tk *Toolkit) RemoveConnector(url string)
- func (tk *Toolkit) Run(ctx context.Context, name string, input any) (any, error)
- func (tk *Toolkit) String() string
- type ToolkitOpt
Constants ¶
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
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
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 DefaultTool ¶ added in v0.4.2
type DefaultTool struct{}
DefaultTool provides no-op default implementations of the optional Tool interface methods OutputSchema and Meta. Embed it in concrete tool types so they satisfy the full Tool interface without boilerplate.
func (DefaultTool) Meta ¶ added in v0.4.2
func (DefaultTool) Meta() llm.ToolMeta
func (DefaultTool) OutputSchema ¶ added in v0.4.2
func (DefaultTool) OutputSchema() (*jsonschema.Schema, error)
type OutputTool ¶ added in v0.3.0
type OutputTool struct {
DefaultTool
// 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) InputSchema ¶ added in v0.4.2
func (t *OutputTool) InputSchema() (*jsonschema.Schema, error)
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) 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 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(opts ...ToolkitOpt) (*Toolkit, error)
NewToolkit creates a new toolkit with the given options.
func (*Toolkit) AddBuiltin ¶ added in v0.4.2
AddBuiltin adds one or more locally-implemented 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) AddConnector ¶ added in v0.4.2
AddConnector registers a remote connector under the given URL and starts its Run loop in a background goroutine. The goroutine's context is cancelled by RemoveConnector or Close. Returns an error if a connector with the same URL is already registered.
func (*Toolkit) Close ¶ added in v0.4.2
Close cancels all active connector goroutines, waits for them to finish, and releases resources.
func (*Toolkit) Feedback ¶ added in v0.1.0
Feedback returns a human-readable description of a tool call, including the tool name and its description when available.
func (*Toolkit) ListTools ¶ added in v0.4.2
func (tk *Toolkit) ListTools(req schema.ListToolsRequest) []llm.Tool
ListTools returns tools matching the given request filters. An empty request returns all tools across all namespaces (builtins + connectors).
func (*Toolkit) Lookup ¶ added in v0.1.0
Lookup returns a tool by name, searching builtins first then connector tools. Returns nil if not found.
func (*Toolkit) RemoveConnector ¶ added in v0.4.2
RemoveConnector cancels the named connector's goroutine, waits for it to finish, then removes it from the registry. No-op if the URL is not registered.
type ToolkitOpt ¶ added in v0.4.2
ToolkitOpt is a functional option for configuring a Toolkit at construction time.
func WithBuiltin ¶ added in v0.4.2
func WithBuiltin(tools ...llm.Tool) ToolkitOpt
WithBuiltin adds one or more locally-implemented tools to the toolkit at construction time.
func WithLogHandler ¶ added in v0.4.2
WithLogHandler sets a callback that receives log messages forwarded from a connector's MCP session. url identifies the originating connector.
func WithStateHandler ¶ added in v0.4.2
func WithStateHandler(fn func(url string, state schema.ConnectorState)) ToolkitOpt
WithStateHandler sets a callback that is invoked when a connector successfully connects or reconnects. state contains the server-reported name, version, and capabilities for that session.
func WithToolsHandler ¶ added in v0.4.2
func WithToolsHandler(fn func(url string, tools []llm.Tool)) ToolkitOpt
WithToolsHandler sets a callback that is invoked when a connector's tool list changes, or when a connector is removed or disconnects. tools is nil when the connector has gone away.