Documentation
¶
Index ¶
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 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
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
Feedback returns a human-readable description of a tool call, including the tool name and its description when available.
func (*Toolkit) Register ¶ added in v0.1.0
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").