Entropic 2.11.1
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
44extern "C" ENTROPIC_EXPORT entropic_error_t
46 entropic_handle_t handle,
47 const char* identity,
48 char** result_json) {
49
50 auto rc = check_compactor(handle);
51 if (rc != ENTROPIC_OK || !handle->engine) {
52 return rc != ENTROPIC_OK ? rc : ENTROPIC_ERROR_INVALID_STATE;
53 }
54
55 // Compaction runs through the engine's CompactionManager during
56 // the agentic loop. External compact requires an active session.
57 (void)identity;
58 (void)result_json;
60}
61
74extern "C" ENTROPIC_EXPORT entropic_error_t
76 entropic_handle_t handle,
77 const char* identity,
78 entropic_compactor_fn compactor,
79 void* user_data) {
80
81 auto rc = check_compactor(handle);
82 if (rc != ENTROPIC_OK || !compactor) {
84 }
85
86 logger->info("register_compactor: identity='{}'",
87 identity ? identity : "(global)");
88 handle->compactor_registry->register_compactor(
89 identity ? identity : "", compactor, user_data);
90 return ENTROPIC_OK;
91}
92
103extern "C" ENTROPIC_EXPORT entropic_error_t
105 entropic_handle_t handle,
106 const char* identity) {
107
108 auto rc = check_compactor(handle);
109 if (rc != ENTROPIC_OK) { return rc; }
110
111 handle->compactor_registry->deregister_compactor(
112 identity ? identity : "");
113 return ENTROPIC_OK;
114}
115
127extern "C" ENTROPIC_EXPORT entropic_error_t
129 entropic_handle_t handle,
130 entropic_compactor_fn* compactor,
131 void** user_data) {
132
133 auto rc = check_compactor(handle);
134 if (rc != ENTROPIC_OK || !compactor) {
136 }
137
138 // Default compactor is managed internally by CompactorRegistry.
139 // Consumers wrap by registering a custom compactor that calls
140 // entropic_compact() internally. No raw C function pointer
141 // exposed for the built-in strategy.
142 *compactor = nullptr;
143 if (user_data) { *user_data = nullptr; }
144 return ENTROPIC_OK;
145}
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:2299
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:37
@ ENTROPIC_OK
Success.
Definition error.h:38
@ ENTROPIC_ERROR_INVALID_ARGUMENT
NULL pointer, empty string, out-of-range value.
Definition error.h:39
@ ENTROPIC_ERROR_INVALID_HANDLE
NULL or destroyed handle (v1.8.9)
Definition error.h:57
@ ENTROPIC_ERROR_INVALID_CONFIG
Config validation failed (missing fields, bad values)
Definition error.h:40
@ ENTROPIC_ERROR_INVALID_STATE
Operation not valid in current state (e.g., generate before activate)
Definition error.h:41
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)