Class: SessionToolLedger
Makaio Framework / ai-adapters-core / SessionToolLedger
Class: SessionToolLedger
Section titled “Class: 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.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SessionToolLedger():
SessionToolLedger
Returns
Section titled “Returns”SessionToolLedger
Methods
Section titled “Methods”getAllEntries()
Section titled “getAllEntries()”getAllEntries(): readonly
ToolLedgerEntry[]
Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:280
Return all tracked entries regardless of state.
Returns
Section titled “Returns”readonly ToolLedgerEntry[]
Snapshot of all ledger entries
Implementation of
Section titled “Implementation of”ISessionToolLedger.getAllEntries
getCallCount()
Section titled “getCallCount()”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.
Parameters
Section titled “Parameters”toolFullName
Section titled “toolFullName”string
The namespaced tool name
Returns
Section titled “Returns”number
Call count (0 for unknown tools)
Implementation of
Section titled “Implementation of”ISessionToolLedger.getCallCount
getEntry()
Section titled “getEntry()”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.
Parameters
Section titled “Parameters”toolFullName
Section titled “toolFullName”string
The namespaced tool name
Returns
Section titled “Returns”ToolLedgerEntry | undefined
The entry, or undefined
Implementation of
Section titled “Implementation of”getInjectedTools()
Section titled “getInjectedTools()”getInjectedTools(): readonly
ToolLedgerEntry[]
Defined in: ../../../adapters/core/src/agent/session-tool-ledger.ts:254
Return all entries where injected === true.
Returns
Section titled “Returns”readonly ToolLedgerEntry[]
Snapshot of currently-injected tool entries
Implementation of
Section titled “Implementation of”ISessionToolLedger.getInjectedTools
recordCall()
Section titled “recordCall()”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.
Parameters
Section titled “Parameters”toolFullName
Section titled “toolFullName”string
The namespaced tool name, e.g. “github__create_issue”
turnNumber
Section titled “turnNumber”number
The current turn number
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”recordDiscovery()
Section titled “recordDiscovery()”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.
Parameters
Section titled “Parameters”toolFullName
Section titled “toolFullName”string
The namespaced tool name, e.g. “github__create_issue”
turnNumber
Section titled “turnNumber”number
The current turn number
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”ISessionToolLedger.recordDiscovery
recordInjection()
Section titled “recordInjection()”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).
Parameters
Section titled “Parameters”readonly object[]
The new set of directly-injected tools
turnNumber
Section titled “turnNumber”number
The current turn number
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”ISessionToolLedger.recordInjection
suggestInjectionSet()
Section titled “suggestInjectionSet()”suggestInjectionSet(
context,_currentTurnNumber):Promise<readonlyobject[]>
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.
Parameters
Section titled “Parameters”context
Section titled “context”Current session context providing direct and discoverable tools
_currentTurnNumber
Section titled “_currentTurnNumber”number
The current turn number (reserved for Phase 2 scoring heuristics)
Returns
Section titled “Returns”Promise<readonly object[]>
Suggested list of tools to inject for the next turn