lloyal-agents API Reference
    Preparing search index...

    Class Session

    Session - Trunk lifecycle + conversation delta helpers

    Owns the current "trunk" branch and provides promote() to crown a winner, plus delta helpers that centralize the sep + formatChat + tokenize + prefill pattern for injecting new turns into an ongoing conversation.

    Session does NOT own the SessionContext or BranchStore — the consumer creates those and passes them in. dispose() prunes trunk only.

    const session = new Session({ ctx, store });
    session.trunk = initialBranch;

    // After verification, promote the best attempt
    await session.promote(bestAttempt.branch);

    // Inject a user turn and generate
    await session.prefillUser('What about X?');
    for await (const { text } of session.trunk) {
    process.stdout.write(text);
    }

    // Cleanup
    await session.dispose();
    ctx.dispose();
    Index

    Constructors

    Accessors

    Methods

    • Dispose trunk only — consumer owns ctx and other resources

      Returns Promise<void>

    • Prefill a tool result turn into trunk

      Parameters

      • resultStr: string

        JSON-stringified tool result

      • callId: string

        Tool call ID

      Returns Promise<void>

    • Prefill a user turn into trunk

      Parameters

      • content: string

        User message content

      • opts: { tools?: string } = {}

        Optional tools JSON string

      Returns Promise<void>

    • Promote a winner to trunk — retainOnly + reassign

      Safe even if winner is the only branch (resets topology, no-op on KV).

      Parameters

      Returns Promise<void>