Skip to content

Class: SessionToolLedger

Makaio Framework


Makaio Framework / ai-adapters-core / SessionToolLedger

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:173

Agent-scoped ledger that tracks every MCP tool’s injection, discovery, and call history within a single agent lifecycle.

One instance is created per agent factory call and discarded when the agent is torn down. If the adapter switches connectors mid-session (e.g. model swap), the same ledger is passed to the new connector so history is preserved across the connector boundary.

Follows the same plain-class, no-bus pattern as ToolCallTracker.

new SessionToolLedger(): SessionToolLedger

SessionToolLedger

getAllEntries(): readonly ToolLedgerEntry[]

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:280

Return all tracked entries regardless of state.

readonly ToolLedgerEntry[]

Snapshot of all ledger entries

ISessionToolLedger.getAllEntries


getCallCount(toolFullName): number

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:263

Return the total call count for a tool, or 0 if not tracked.

string

The namespaced tool name

number

Call count (0 for unknown tools)

ISessionToolLedger.getCallCount


getEntry(toolFullName): ToolLedgerEntry | undefined

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:272

Return a single ledger entry by full name, or undefined if not tracked.

string

The namespaced tool name

ToolLedgerEntry | undefined

The entry, or undefined

ISessionToolLedger.getEntry


getInjectedTools(): readonly ToolLedgerEntry[]

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:254

Return all entries where injected === true.

readonly ToolLedgerEntry[]

Snapshot of currently-injected tool entries

ISessionToolLedger.getInjectedTools


recordCall(toolFullName, turnNumber): void

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:234

Record one mcp_call invocation for a tool. Implies discovery: also sets discovered and firstDiscoveredAtTurn if unset.

string

The namespaced tool name, e.g. “github__create_issue”

number

The current turn number

void

ISessionToolLedger.recordCall


recordDiscovery(toolFullName, turnNumber): void

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:220

Record that the model discovered a tool. Applies first-discovery semantics: firstDiscoveredAtTurn is only set once.

string

The namespaced tool name, e.g. “github__create_issue”

number

The current turn number

void

ISessionToolLedger.recordDiscovery


recordInjection(tools, turnNumber): void

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:196

Replace the current injection set with the provided list. Tools absent from the new list have their injected flag cleared (eviction sweep).

readonly object[]

The new set of directly-injected tools

number

The current turn number

void

ISessionToolLedger.recordInjection


suggestInjectionSet(context, _currentTurnNumber): Promise<readonly object[]>

Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:292

Phase 1 pass-through: return context.directTools mapped to ToolListItem format. Phase 2 will replace this with a scoring heuristic that factors in call history and discovery patterns.

LedgerSessionContext

Current session context providing direct and discoverable tools

number

The current turn number (reserved for Phase 2 scoring heuristics)

Promise<readonly object[]>

Suggested list of tools to inject for the next turn

ISessionToolLedger.suggestInjectionSet