Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶ added in v0.0.7
type Call struct {
// ID is the provider-supplied tool call identifier used to match the result.
ID string
// Name is the requested tool name.
Name string
// Arguments is the raw JSON payload supplied by the model.
Arguments json.RawMessage
}
Call is one model-requested tool invocation.
type Definition ¶
type Definition struct {
Name string
Description string
// InputSchema is the JSON Schema describing the tool's input parameters.
InputSchema *jsonschema.Schema
// OutputSchema is the JSON Schema describing the tool's structured result.
OutputSchema *jsonschema.Schema
}
Definition holds the metadata that describes a tool to an LLM.
type HandledError ¶ added in v0.0.12
type HandledError struct {
// Content is the plain-text failure message that may be sent to the model.
Content string `json:"content,omitempty"`
// StructuredContent is the optional JSON failure payload that may be sent to
// providers supporting structured tool results.
StructuredContent json.RawMessage `json:"structured_content,omitempty"`
}
HandledError is a completed tool failure whose content is safe to send to the model. It must not contain internal SDK, transport, or infrastructure error details.
func NewHandledError ¶ added in v0.0.12
func NewHandledError(content string) *HandledError
NewHandledError creates a model-visible handled tool failure.
func (*HandledError) Clone ¶ added in v0.0.12
func (e *HandledError) Clone() *HandledError
Clone returns an independent copy of e.
func (*HandledError) Error ¶ added in v0.0.12
func (e *HandledError) Error() string
Error implements the error interface.
func (*HandledError) Text ¶ added in v0.0.12
func (e *HandledError) Text() string
Text returns the safe plain-text failure sent to providers that do not support structured tool results.
type Handler ¶ added in v0.0.7
Handler is a strongly typed Go function wrapped as a Tool by NewFunc. Return a HandledError for a handled failure that is safe to send to the model; other errors are terminal.
type Outcome ¶ added in v0.0.12
type Outcome interface {
Text() string
// contains filtered or unexported methods
}
Outcome is a completed tool invocation outcome. The only implementations are Result for success and HandledError for a model-visible failure.
type Result ¶ added in v0.0.7
type Result struct {
// Content is the plain-text fallback returned to providers that do not
// support structured tool results.
Content string `json:"content,omitempty"`
// StructuredContent is the raw JSON result returned by the tool.
StructuredContent json.RawMessage `json:"structured_content,omitempty"`
}
Result is the provider-neutral result of a tool invocation.
type Tool ¶
type Tool interface {
// Definition returns the tool's metadata used by the LLM to understand and call the tool.
Definition() Definition
// Run executes the tool call and returns a provider-neutral result. A
// HandledError is a completed, model-visible failure. Any other non-nil error
// is terminal. A nil result with a nil error is invalid.
Run(ctx context.Context, call Call) (*Result, error)
}
Tool is a provider-agnostic interface for tools that can be invoked by an LLM.
func NewFunc ¶ added in v0.0.7
func NewFunc[In, Out any](def Definition, handler Handler[In, Out]) (Tool, error)
NewFunc wraps a strongly typed Go function as a Tool. If Definition does not provide schemas, they are inferred from In and Out. Ordinary Handler errors propagate to the caller. LlmAgent recognizes HandledError as a completed, model-visible failure; other errors are terminal.
func WithTimeout ¶ added in v0.0.3
WithTimeout wraps t so that each Run invocation is bounded by the given timeout. The timeout is applied on top of any deadline already present in the incoming context, so the shorter of the two wins. A zero or negative duration is a no-op and returns t unchanged.