tools

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const ActionLoopExit = "loop_exit"

ActionLoopExit is the action key set by ExitTool on the ToolContext to signal that the enclosing loop should stop. The value is a bool indicating whether the loop should escalate to the outer handler.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, tool ToolContext) context.Context

NewContext returns a child context that carries the given ToolContext.

Types

type ExitInput

type ExitInput struct {
	Reason   string `json:"reason"             jsonschema:"Reason for exiting the loop."`
	Escalate bool   `json:"escalate,omitempty" jsonschema:"If true, escalate to the outer handler instead of completing normally."`
}

ExitInput is the argument schema for ExitTool.

type ExitTool

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

ExitTool signals the enclosing loop to stop. Register it via blades.WithTools on a sub-agent. When invoked by the LLM it sets ActionLoopExit on the ToolContext so that the loop agent can observe it via message.Actions. If called outside a loop (no ToolContext in context) the call is a no-op.

func NewExitTool

func NewExitTool() *ExitTool

NewExitTool creates a ready-to-use ExitTool.

func (*ExitTool) Description

func (t *ExitTool) Description() string

func (*ExitTool) Handle

func (t *ExitTool) Handle(ctx context.Context, input string) (string, error)

Handle is called by the agent runtime when the LLM invokes the exit tool.

func (*ExitTool) InputSchema

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

func (*ExitTool) Name

func (t *ExitTool) Name() string

func (*ExitTool) OutputSchema

func (t *ExitTool) OutputSchema() *jsonschema.Schema

type HandleFunc

type HandleFunc func(context.Context, string) (string, error)

HandleFunc adapts a plain function to a ToolHandler, similar to http.HandleFunc.

func JSONAdapter

func JSONAdapter[I, O any](handle func(context.Context, I) (O, error)) HandleFunc

JSONAdapter adapts a Handler that consumes and produces JSON-serializable types to a Handler that consumes and produces strings.

func (HandleFunc) Handle

func (f HandleFunc) Handle(ctx context.Context, input string) (string, error)

Handle is the Handle method of the Handler interface.

type Handler

type Handler interface {
	Handle(context.Context, string) (string, error)
}

Handler consumes tool arguments returned by the LLM (serialized as JSON string). Implementations should decode the payload as needed and return the tool result as JSON.

type Middleware

type Middleware func(Handler) Handler

Middleware wraps a Handler and returns a new Handler with additional behavior. It is applied in a chain (outermost first) using ChainMiddlewares.

func ChainMiddlewares

func ChainMiddlewares(mws ...Middleware) Middleware

ChainMiddlewares composes middlewares into one, applying them in order. The first middleware becomes the outermost wrapper.

type Option

type Option func(*baseTool)

Option defines a configuration option for a baseTool.

func WithInputSchema

func WithInputSchema(schema *jsonschema.Schema) Option

WithInputSchema sets the input schema for the tool.

func WithMiddleware

func WithMiddleware(mw ...Middleware) Option

WithMiddleware sets the middlewares for the tool.

func WithOutputSchema

func WithOutputSchema(schema *jsonschema.Schema) Option

WithOutputSchema sets the output schema for the tool.

type Resolver

type Resolver interface {
	// Resolve returns a list of tools available from this resolver.
	Resolve(ctx context.Context) ([]Tool, error)
}

Resolver defines the interface for dynamically resolving tools from various sources. Implementations can provide tools from MCP servers, plugins, remote services, etc.

type Tool

type Tool interface {
	Name() string
	Description() string
	InputSchema() *jsonschema.Schema
	OutputSchema() *jsonschema.Schema
	Handler
}

Tool defines the interface for a tool that can be used in a system.

func NewFunc

func NewFunc[I, O any](name string, description string, handler func(context.Context, I) (O, error), opts ...Option) (Tool, error)

NewFunc creates a new Tool with the given name, description, input and output types, and handler.

func NewTool

func NewTool(name string, description string, handler Handler, opts ...Option) Tool

NewTool creates a new Tool with the given name, description, and handler.

type ToolContext

type ToolContext interface {
	ID() string
	Name() string
	// Actions returns a copy of the tool's accumulated action map.
	Actions() map[string]any
	// SetAction records a control-flow action that callers (e.g. LoopAgent,
	// RoutingAgent) can inspect on the yielded message after tool execution.
	// Safe for concurrent use.
	SetAction(key string, value any)
}

ToolContext provides metadata about a tool invocation and allows the tool to communicate control-flow signals back to the caller through SetAction.

func FromContext

func FromContext(ctx context.Context) (ToolContext, bool)

FromContext retrieves the ToolContext stored by NewContext.

Jump to

Keyboard shortcuts

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