lloyal-agents API Reference
    Preparing search index...

    Class Tool<TArgs>Abstract

    Abstract base class for tools usable by agents in the runtime

    Subclass to define tools that agents can invoke during generation. Implement name, description, parameters, and execute(). The schema getter auto-generates the OpenAI-compatible function schema expected by formatChat().

    Pass tool instances to createToolkit to build the toolMap and toolsJson pair consumed by useAgentPool and runAgents.

    execute() returns an Effection Operation, enabling tools to spawn sub-agents via runAgents or withSharedRoot. For async work, wrap in call(). For synchronous tools, return directly from the generator body.

    class SearchTool extends Tool<{ query: string; topK?: number }> {
    readonly name = 'search';
    readonly description = 'Search the corpus for relevant passages';
    readonly parameters = {
    type: 'object',
    properties: {
    query: { type: 'string', description: 'Search query' },
    topK: { type: 'number', description: 'Number of results' },
    },
    required: ['query'],
    };

    *execute(args: { query: string; topK?: number }, ctx?: ToolContext): Operation<unknown> {
    const results = yield* call(() => this.reranker.rank(args.query, args.topK ?? 5));
    return { results };
    }
    }

    Type Parameters

    • TArgs = Record<string, unknown>
    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    • Type Parameters

      • TArgs = Record<string, unknown>

      Returns Tool<TArgs>

    Properties

    description: string

    Human-readable description shown to the model

    name: string

    Tool name — used as the function identifier in tool calls

    parameters: JsonSchema

    JSON Schema describing the tool's expected arguments

    Accessors

    Methods

    • Execute the tool with parsed arguments

      Called by the agent pool when the model emits a tool call matching this tool's name. The return value is JSON-serialized and prefilled back into the agent's context as a tool result.

      Returns an Effection Operation — implement as a generator method. The operation runs inside the agent pool's scope, so it has access to Ctx, Store, and Events contexts for nested agent spawning.

      Parameters

      • args: TArgs

        Parsed arguments from the model's tool call

      • Optionalcontext: ToolContext

        Execution context with progress reporting callback

      Returns Operation<unknown>

      Tool result (will be JSON-serialized)