Documentation
¶
Index ¶
- Constants
- func WithTool(t ...llm.Tool) opt.Opt
- type DefaultTool
- type JSONResource
- 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.ToolListRequest) []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 json.RawMessage) (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 ¶
Types ¶
type DefaultTool ¶
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 ¶
func (DefaultTool) Meta() llm.ToolMeta
func (DefaultTool) OutputSchema ¶
func (DefaultTool) OutputSchema() *jsonschema.Schema
type JSONResource ¶
type JSONResource struct {
// contains filtered or unexported fields
}
JSONResource wraps raw JSON bytes as an llm.Resource with MIME type application/json. Use this to return JSON output from tool Run methods.
func NewJSONResource ¶
func NewJSONResource(data []byte) *JSONResource
NewJSONResource creates a Resource wrapping the given JSON bytes.
func (*JSONResource) Description ¶
func (r *JSONResource) Description() string
func (*JSONResource) Name ¶
func (r *JSONResource) Name() string
func (*JSONResource) Type ¶
func (r *JSONResource) Type() string
func (*JSONResource) URI ¶
func (r *JSONResource) URI() string
type OutputTool ¶
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 ¶
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 ¶
func (t *OutputTool) Description() string
func (*OutputTool) InputSchema ¶
func (t *OutputTool) InputSchema() *jsonschema.Schema
func (*OutputTool) Name ¶
func (t *OutputTool) Name() string
func (*OutputTool) Run ¶
func (t *OutputTool) Run(_ context.Context, input json.RawMessage) (any, error)
func (*OutputTool) Validate ¶
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 ¶
type Toolkit struct {
// contains filtered or unexported fields
}
Toolkit is a collection of tools with unique names
func NewToolkit ¶
func NewToolkit(opts ...ToolkitOpt) (*Toolkit, error)
NewToolkit creates a new toolkit with the given options.
func (*Toolkit) AddBuiltin ¶
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 ¶
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 ¶
Close cancels all active connector goroutines, waits for them to finish, and releases resources.
func (*Toolkit) Feedback ¶
Feedback returns a human-readable description of a tool call, including the tool name and its description when available.
func (*Toolkit) ListTools ¶
func (tk *Toolkit) ListTools(req schema.ToolListRequest) []llm.Tool
ListTools returns tools matching the given request filters. An empty request returns all tools across all namespaces (builtins + connectors).
func (*Toolkit) Lookup ¶
Lookup returns a tool by name, searching builtins first then connector tools. Returns nil if not found.
func (*Toolkit) RemoveConnector ¶
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 ¶
ToolkitOpt is a functional option for configuring a Toolkit at construction time.
func WithBuiltin ¶
func WithBuiltin(tools ...llm.Tool) ToolkitOpt
WithBuiltin adds one or more locally-implemented tools to the toolkit at construction time.
func WithLogHandler ¶
WithLogHandler sets a callback that receives log messages forwarded from a connector's MCP session. url identifies the originating connector.
func WithStateHandler ¶
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 ¶
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.