Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic_compaction.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
12#include "engine_handle.h"
13
14#include <entropic/entropic.h>
16
17static auto logger = entropic::log::get("facade.compaction");
18
31
42extern "C" ENTROPIC_EXPORT entropic_error_t
44 entropic_handle_t handle,
45 const char* identity,
46 char** result_json) {
47
48 auto rc = check_compactor(handle);
49 if (rc != ENTROPIC_OK || !handle->engine) {
50 return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_STATE;
51 }
52
53 // Compaction runs through the engine's CompactionManager during
54 // the agentic loop. External compact requires an active session.
55 (void)identity;
56 (void)result_json;
58}
59
71extern "C" ENTROPIC_EXPORT entropic_error_t
73 entropic_handle_t handle,
74 const char* identity,
75 entropic_compactor_fn compactor,
76 void* user_data) {
77
78 auto rc = check_compactor(handle);
79 if (rc != ENTROPIC_OK || !compactor) {
81 }
82
83 logger->info("register_compactor: identity='{}'",
84 identity ? identity : "(global)");
85 handle->compactor_registry->register_compactor(
86 identity ? identity : "", compactor, user_data);
87 return ENTROPIC_OK;
88}
89
99extern "C" ENTROPIC_EXPORT entropic_error_t
101 entropic_handle_t handle,
102 const char* identity) {
103
104 auto rc = check_compactor(handle);
105 if (rc != ENTROPIC_OK) { return rc; }
106
107 handle->compactor_registry->deregister_compactor(
108 identity ? identity : "");
109 return ENTROPIC_OK;
110}
111
122extern "C" ENTROPIC_EXPORT entropic_error_t
124 entropic_handle_t handle,
125 entropic_compactor_fn* compactor,
126 void** user_data) {
127
128 auto rc = check_compactor(handle);
129 if (rc != ENTROPIC_OK || !compactor) {
131 }
132
133 // Default compactor is managed internally by CompactorRegistry.
134 // Consumers wrap by registering a custom compactor that calls
135 // entropic_compact() internally. No raw C function pointer
136 // exposed for the built-in strategy.
137 *compactor = nullptr;
138 if (user_data) { *user_data = nullptr; }
139 return ENTROPIC_OK;
140}
Private definition of the entropic_engine struct.
Public C API for the Entropic inference engine.
int(* entropic_compactor_fn)(const char *messages_json, const char *config_json, char **out_messages, char **out_summary, void *user_data)
Compactor function type.
Definition entropic.h:1966
ENTROPIC_EXPORT entropic_error_t entropic_register_compactor(entropic_handle_t handle, const char *identity, entropic_compactor_fn compactor, void *user_data)
Register a custom compactor for an identity.
ENTROPIC_EXPORT entropic_error_t entropic_get_default_compactor(entropic_handle_t handle, entropic_compactor_fn *compactor, void **user_data)
Get the built-in default compactor function pointer.
ENTROPIC_EXPORT entropic_error_t entropic_deregister_compactor(entropic_handle_t handle, const char *identity)
Deregister a custom compactor for an identity.
static entropic_error_t check_compactor(entropic_handle_t h)
Check handle prerequisites for compaction APIs.
ENTROPIC_EXPORT entropic_error_t entropic_compact(entropic_handle_t handle, const char *identity, char **result_json)
Trigger compaction on current context.
entropic_error_t
Error codes returned by all C API functions.
Definition error.h:35
@ ENTROPIC_OK
Success.
Definition error.h:36
@ ENTROPIC_ERROR_INVALID_ARGUMENT
NULL pointer, empty string, out-of-range value.
Definition error.h:37
@ ENTROPIC_ERROR_INVALID_HANDLE
NULL or destroyed handle (v1.8.9)
Definition error.h:55
@ ENTROPIC_ERROR_INVALID_CONFIG
Config validation failed (missing fields, bad values)
Definition error.h:38
@ ENTROPIC_ERROR_INVALID_STATE
Operation not valid in current state (e.g., generate before activate)
Definition error.h:39
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
Engine handle struct — owns all subsystems.
std::unique_ptr< entropic::CompactorRegistry > compactor_registry
Compaction strategies.
std::unique_ptr< entropic::AgentEngine > engine
Agentic loop (owns conversation state)