lloyal-agents API Reference
    Preparing search index...

    Function useAgentPool

    • Concurrent agent generation loop as an Effection resource

      Runs N agents in parallel using a four-phase tick loop over shared BranchStore infrastructure. Each agent forks from a parent branch, generates tokens, invokes tools, and reports findings.

      Four-phase tick loop:

      1. PRODUCE — sample all active agents via produceSync() (no async gap)
      2. COMMIT — single GPU call via store.commit() for all produced tokens
      3. SETTLE — drain settled tool results, batch prefill, reset grammars
      4. DISPATCH — execute collected tool calls sequentially via scoped() + call()

      Tool dispatch uses scoped() + call() — each tool executes to completion before the next tick, ensuring exclusive llama_context access (no concurrent decode).

      Resource semantics: provide() suspends after all agents complete, keeping branches alive so the caller can fork from them (e.g. for verification). Branches are pruned when the scope exits — each branch's ensure() from setupAgent handles cleanup automatically.

      For automatic branch cleanup on return, use runAgents instead.

      Parameters

      • opts: AgentPoolOptions

        Pool configuration: tasks, tools, sampling params, max turns

      Returns Operation<AgentPoolResult>

      Agent pool result with per-agent findings and aggregate statistics

      const pool = yield* withSharedRoot(
      { systemPrompt: RESEARCH_PROMPT, tools: toolsJson },
      function*(root) {
      return yield* useAgentPool({
      tasks: questions.map(q => ({
      systemPrompt: RESEARCH_PROMPT,
      content: q,
      tools: toolsJson,
      parent: root,
      })),
      tools: toolMap,
      maxTurns: 6,
      });
      },
      );