Documentation
¶
Index ¶
Constants ¶
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 (*ExitTool) Description ¶
func (*ExitTool) InputSchema ¶
func (t *ExitTool) InputSchema() *jsonschema.Schema
func (*ExitTool) OutputSchema ¶
func (t *ExitTool) OutputSchema() *jsonschema.Schema
type HandleFunc ¶
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.
type Handler ¶
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 ¶
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.
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.