Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
audit_entry.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
10
11#include <nlohmann/json.hpp>
12
13static auto logger = entropic::log::get("storage.audit_entry");
14
15namespace entropic {
16
24static std::string extract_parent_id(const nlohmann::json& j) {
25 if (j.contains("parent_conversation_id") &&
26 !j["parent_conversation_id"].is_null()) {
27 return j["parent_conversation_id"].get<std::string>();
28 }
29 return "";
30}
31
40 const nlohmann::json& result, AuditEntry& entry) {
41 entry.result_status = result.at("status").get<std::string>();
42 entry.result_content = result.at("content").get<std::string>();
43 entry.elapsed_ms = result.at("elapsed_ms").get<double>();
44}
45
53nlohmann::json audit_entry_to_json(const AuditEntry& entry) {
54 nlohmann::json j;
55 j["caller_id"] = entry.caller_id;
56 j["tool_name"] = entry.tool_name;
57 j["params"] = nlohmann::json::parse(
58 entry.params_json.empty() ? "{}" : entry.params_json);
59 j["result"]["status"] = entry.result_status;
60 j["result"]["content"] = entry.result_content;
61 j["result"]["elapsed_ms"] = entry.elapsed_ms;
62 j["directives"] = nlohmann::json::parse(
63 entry.directives_json.empty() ? "[]" : entry.directives_json);
64 j["delegation_depth"] = entry.delegation_depth;
65 j["iteration"] = entry.iteration;
66 j["parent_conversation_id"] = entry.parent_conversation_id.empty()
67 ? nlohmann::json(nullptr)
68 : nlohmann::json(entry.parent_conversation_id);
69 return j;
70}
71
80bool audit_entry_from_json(const nlohmann::json& j, AuditEntry& entry) {
81 try {
82 entry.caller_id = j.at("caller_id").get<std::string>();
83 entry.tool_name = j.at("tool_name").get<std::string>();
84 entry.params_json = j.at("params").dump();
85 parse_result_fields(j.at("result"), entry);
86 entry.directives_json = j.at("directives").dump();
87 entry.delegation_depth = j.at("delegation_depth").get<int>();
88 entry.iteration = j.at("iteration").get<int>();
90 return true;
91 } catch (const nlohmann::json::exception& e) {
92 logger->warn("Failed to parse audit entry: {}", e.what());
93 return false;
94 }
95}
96
97} // namespace entropic
AuditEntry struct and JSON serialization for JSONL audit log.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
Activate model on GPU (WARM → ACTIVE).
bool audit_entry_from_json(const nlohmann::json &j, AuditEntry &entry)
Deserialize AuditEntry fields from a JSON object.
static void parse_result_fields(const nlohmann::json &result, AuditEntry &entry)
Parse the result sub-object from JSON into AuditEntry fields.
static std::string extract_parent_id(const nlohmann::json &j)
Extract optional parent_conversation_id from JSON.
nlohmann::json audit_entry_to_json(const AuditEntry &entry)
Serialize AuditEntry fields to a JSON object.
A single audit log entry for one MCP tool call.
Definition audit_entry.h:30
int delegation_depth
Current delegation depth (0 = lead)
Definition audit_entry.h:38
std::string result_content
Tool result text (full, never truncated)
Definition audit_entry.h:35
double elapsed_ms
Tool execution duration in milliseconds.
Definition audit_entry.h:36
std::string parent_conversation_id
Parent conversation ID (empty for lead)
Definition audit_entry.h:40
int iteration
Engine loop iteration number.
Definition audit_entry.h:39
std::string params_json
Tool parameters as JSON string (never truncated)
Definition audit_entry.h:33
std::string tool_name
Fully-qualified tool name (e.g., "filesystem.write_file")
Definition audit_entry.h:32
std::string result_status
"success", "error", or "timeout"
Definition audit_entry.h:34
std::string caller_id
Identity/tier name (e.g., "eng", "qa", "lead")
Definition audit_entry.h:31
std::string directives_json
Directives array as JSON string ("[]" if none)
Definition audit_entry.h:37