Class EmergentCapabilityEngine

Orchestrates runtime tool creation for agents with emergent capabilities.

Pipeline: forge request → build tool → run tests → judge review → register.

Supports two creation modes:

Example

const engine = new EmergentCapabilityEngine({
config: { ...DEFAULT_EMERGENT_CONFIG, enabled: true },
composableBuilder,
sandboxForge,
judge,
registry,
});

const result = await engine.forge(request, { agentId: 'gmi-1', sessionId: 'sess-1' });
if (result.success) {
console.log('Registered tool:', result.toolId);
}

Constructors

Methods

  • Forge a new tool from a request.

    Runs test cases, submits the candidate to the LLM judge, and registers the tool at the 'session' tier if approved. Returns a ForgeResult with the tool ID on success, or an error / rejection verdict on failure.

    Pipeline:

    1. Generate unique tool ID.
    2. Build or validate implementation (compose vs. sandbox).
    3. Execute all declared test cases and collect results.
    4. Submit candidate to the judge for creation review.
    5. If approved: create EmergentTool, register at session tier, index.
    6. If rejected: return failure with the judge's reasoning.

    Parameters

    • request: ForgeToolRequest

      The forge request describing the desired tool.

    • context: {
          agentId: string;
          sessionId: string;
      }

      Caller context containing the agent and session IDs.

      • agentId: string
      • sessionId: string

    Returns Promise<ForgeResult>

    A ForgeResult indicating success or failure.

  • Check if a tool is eligible for promotion and auto-promote if the threshold is met.

    A tool qualifies for promotion when:

    1. It is at the 'session' tier.
    2. Its usage stats meet EmergentConfig.promotionThreshold:
      • totalUses >= threshold.uses
      • confidenceScore >= threshold.confidence

    When eligible, the engine submits the tool to the judge's promotion panel. If both reviewers approve, the tool is promoted to 'agent' tier.

    Parameters

    • toolId: string

      The ID of the tool to check.

    Returns Promise<null | PromotionResult>

    A PromotionResult if promotion was attempted, or null if the tool is not eligible or does not exist.

  • Hydrate a persisted tool back into a live runtime and make it executable.

    This is used by backend/admin control planes to sync shared tools from durable storage into a running ToolOrchestrator after promotion or restart.

    Parameters

    Returns Promise<void>

  • Factory method that creates the four self-improvement tools when config.selfImprovement?.enabled is true.

    Returns an array containing:

    1. AdaptPersonalityTool — bounded HEXACO trait mutation.
    2. ManageSkillsTool — runtime skill enable/disable/search.
    3. CreateWorkflowTool — multi-step tool composition.
    4. SelfEvaluateTool — self-scoring with parameter adjustment.

    Returns an empty array when self-improvement is disabled or the config is absent. Uses dynamic imports to avoid hard compile-time coupling to tool modules that may not yet exist.

    Parameters

    Returns Promise<ITool<any, any>[]>

    Array of 0 or 4 ITool instances.

  • Create an executable ITool wrapper for a forged emergent tool.

    The wrapper performs runtime output validation, usage tracking, and promotion checks after each successful execution.

    Parameters

    Returns ITool<Record<string, unknown>, unknown>