Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::ToolCallHistory Class Reference

Fixed-size ring buffer of recent tool calls. More...

#include <entropic/mcp/tool_call_history.h>

Public Member Functions

 ToolCallHistory (size_t capacity=100)
 Construct with buffer capacity.
 
void record (const ToolCallRecord &entry)
 Record a completed tool call.
 
std::vector< ToolCallRecordrecent (size_t count) const
 Get the N most recent entries (newest first).
 
std::vector< ToolCallRecordall () const
 Get all stored entries (oldest first, insertion order).
 
std::string to_json (size_t count) const
 Serialize recent entries to JSON array string.
 
size_t size () const
 Current number of stored entries.
 

Detailed Description

Fixed-size ring buffer of recent tool calls.

Capacity set at construction (default 100). When full, oldest entries are overwritten. Thread-safe reads via shared_mutex.

Usage
ToolCallHistory history(100);
history.record({.sequence=1, .tool_name="fs.read", ...});
auto last5 = history.recent(5); // newest first
auto all = history.all(); // oldest first
Fixed-size ring buffer of recent tool calls.
std::vector< ToolCallRecord > all() const
Get all stored entries (oldest first, insertion order).
Version
1.9.12

Definition at line 62 of file tool_call_history.h.

Constructor & Destructor Documentation

◆ ToolCallHistory()

entropic::ToolCallHistory::ToolCallHistory ( size_t  capacity = 100)
explicit

Construct with buffer capacity.

Parameters
capacityMaximum entries to retain (default 100).
Version
1.9.12

The buffer is allocated once, up front, and never grows — this is a bounded diagnostic window (backing entropic.diagnose / entropic.inspect and the validator's retry enrichment), explicitly NOT the audit log.

Parameters
capacityMaximum entries to retain (default 100). @req REQ-MCP-020
Version
1.9.12

Definition at line 30 of file tool_call_history.cpp.

Member Function Documentation

◆ all()

std::vector< ToolCallRecord > entropic::ToolCallHistory::all ( ) const

Get all stored entries (oldest first, insertion order).

Get all stored entries in insertion (oldest-first) order.

Returns
Vector of all records.
Version
1.9.12

Shared-lock read. Handles both the not-yet-wrapped case (start at 0) and the wrapped case (start at the write head, which is the oldest surviving slot).

Returns
Every retained record oldest-first — at most capacity entries, the older ones having been overwritten. @req REQ-MCP-020
Version
1.9.12

Definition at line 97 of file tool_call_history.cpp.

◆ recent()

std::vector< ToolCallRecord > entropic::ToolCallHistory::recent ( size_t  count) const

Get the N most recent entries (newest first).

Parameters
countMaximum entries to return.
Returns
Vector of records, newest first.
Version
1.9.12

Takes the shared (reader) half of the mutex so several readers can run concurrently alongside a single writer.

Parameters
countMaximum entries to return; clamped to the stored count.
Returns
Up to count records ordered newest-first, walking the ring backwards from the write head; empty when nothing is stored. @req REQ-MCP-020
Version
1.9.12

Definition at line 72 of file tool_call_history.cpp.

◆ record()

void entropic::ToolCallHistory::record ( const ToolCallRecord entry)

Record a completed tool call.

Parameters
entryTool call record to store.
Version
1.9.12

Takes the unique (writer) half of the shared_mutex. When the buffer is full the oldest record is overwritten in place, so size saturates at capacity rather than growing.

Parameters
entryTool call record — sequence, fully-qualified tool name, key-only params summary, status, truncated result summary, elapsed ms, error detail and loop iteration. @req REQ-MCP-020
Version
2.0.0

Definition at line 49 of file tool_call_history.cpp.

◆ size()

size_t entropic::ToolCallHistory::size ( ) const

Current number of stored entries.

Returns
Entry count (<= capacity).
Version
1.9.12
Returns
Number of retained records under a shared lock — rises to capacity and then stays there as older entries are overwritten. @req REQ-MCP-020
Version
1.9.12

Definition at line 160 of file tool_call_history.cpp.

◆ to_json()

std::string entropic::ToolCallHistory::to_json ( size_t  count) const

Serialize recent entries to JSON array string.

Parameters
countMaximum entries to include (0 = all).
Returns
JSON array of ToolCallRecord objects.
Version
1.9.12
Parameters
countMaximum entries; 0 means "all", oldest-first.
Returns
Valid JSON array string honouring the count limit — oldest-first for count 0, newest-first otherwise; "[]" when nothing is stored. @req REQ-MCP-020
Version
1.9.12

Definition at line 144 of file tool_call_history.cpp.


The documentation for this class was generated from the following files: