11#include <nlohmann/json.hpp>
31 : capacity_(capacity) {
32 buffer_.resize(capacity);
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]);
146 nlohmann::json arr = nlohmann::json::array();
147 for (
const auto& rec : entries) {
161 std::shared_lock lock(mutex_);
178 auto j = nlohmann::json::parse(args_json);
179 if (!j.is_object()) {
183 for (
auto it = j.begin(); it != j.end(); ++it) {
184 if (!result.empty()) {
206 if (text.size() <= max_len) {
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).
@ 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.