11#include <nlohmann/json.hpp>
26 : capacity_(capacity) {
27 buffer_.resize(capacity);
28 logger->info(
"ToolCallHistory initialized (capacity={})", capacity);
38 std::unique_lock lock(mutex_);
39 buffer_[head_] = entry;
40 head_ = (head_ + 1) % capacity_;
41 if (count_ < capacity_) {
44 logger->info(
"Recorded: tool='{}', {}/{} slots",
56 std::shared_lock lock(mutex_);
57 size_t n = std::min(count, count_);
58 std::vector<ToolCallRecord> result;
61 for (
size_t i = 0; i < n; ++i) {
62 size_t idx = (head_ + capacity_ - 1 - i) % capacity_;
63 result.push_back(buffer_[idx]);
75 std::shared_lock lock(mutex_);
76 std::vector<ToolCallRecord> result;
77 result.reserve(count_);
79 size_t start = (count_ < capacity_) ? 0
81 for (
size_t i = 0; i < count_; ++i) {
82 size_t idx = (start + i) % capacity_;
83 result.push_back(buffer_[idx]);
118 auto entries = (count == 0) ?
all() :
recent(count);
119 nlohmann::json arr = nlohmann::json::array();
120 for (
const auto& rec : entries) {
133 std::shared_lock lock(mutex_);
146 auto j = nlohmann::json::parse(args_json);
147 if (!j.is_object()) {
151 for (
auto it = j.begin(); it != j.end(); ++it) {
152 if (!result.empty()) {
172 if (text.size() <= max_len) {
175 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).
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.