11#include <nlohmann/json.hpp>
33 logger->info(
"ToolCallHistory initialized (capacity={})",
capacity);
50 std::unique_lock lock(mutex_);
51 buffer_[head_] = entry;
52 head_ = (head_ + 1) % capacity_;
53 if (count_ < capacity_) {
56 logger->info(
"Recorded: tool='{}', {}/{} slots",
73 std::shared_lock lock(mutex_);
74 size_t n = std::min(
count, count_);
75 std::vector<ToolCallRecord> result;
78 for (
size_t i = 0;
i <
n; ++
i) {
79 size_t idx = (head_ + capacity_ - 1 -
i) % capacity_;
80 result.push_back(buffer_[
idx]);
98 std::shared_lock lock(mutex_);
99 std::vector<ToolCallRecord> result;
100 result.reserve(count_);
102 size_t start = (count_ < capacity_) ? 0
104 for (
size_t i = 0;
i < count_; ++
i) {
105 size_t idx = (start +
i) % capacity_;
106 result.push_back(buffer_[
idx]);
122 j[
"sequence"] =
rec.sequence;
123 j[
"tool_name"] =
rec.tool_name;
124 j[
"params_summary"] =
rec.params_summary;
125 j[
"status"] =
rec.status;
126 j[
"result_summary"] =
rec.result_summary;
127 j[
"elapsed_ms"] =
rec.elapsed_ms;
128 j[
"iteration"] =
rec.iteration;
129 if (!
rec.error_detail.empty()) {
130 j[
"error_detail"] =
rec.error_detail;
146 nlohmann::json arr = nlohmann::json::array();
147 for (
const auto&
rec : entries) {
161 std::shared_lock lock(mutex_);
179 if (!
j.is_object()) {
183 for (
auto it =
j.begin();
it !=
j.end(); ++
it) {
184 if (!result.empty()) {
209 return text.substr(0,
max_len) +
"...";
std::vector< ToolCallRecord > all() const
Get all stored entries (oldest first, insertion order).
ToolCallHistory(size_t capacity=100)
Construct with buffer capacity.
size_t size() const
Current number of stored entries.
void record(const ToolCallRecord &entry)
Record a completed tool call.
std::vector< ToolCallRecord > recent(size_t count) const
Get the N most recent entries (newest first).
std::string to_json(size_t count) const
Serialize recent entries to JSON array string.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
@ count
Sentinel — MUST remain last.
std::string truncate_result(const std::string &text, size_t max_len)
Truncate a string to max_len characters with "..." suffix.
std::string summarize_params(const std::string &args_json)
Extract top-level JSON keys as a comma-separated summary.
static nlohmann::json record_to_json(const ToolCallRecord &rec)
Serialize a single ToolCallRecord to JSON.
In-memory ring buffer of recent tool calls for introspection.