|
Entropic 2.9.4
Local-first agentic inference engine
|
librentropic facade — C API implementation. More...
#include "engine_handle.h"#include <entropic/config/loader.h>#include <entropic/mcp/servers/entropic_server.h>#include <entropic/entropic.h>#include <entropic/prompts/manager.h>#include <entropic/types/logging.h>#include "llama_cpp_backend.h"#include <entropic/inference/interface_factory.h>#include <entropic/inference/orchestrator.h>#include <entropic/interfaces/i_inference_backend.h>#include <entropic/types/messages_json.h>#include "json_serializers.h"#include "utf8_safe.h"#include "../inference/tool_call_serialize.h"#include <nlohmann/json.hpp>#include <atomic>#include <cstdlib>#include <fstream>#include <vector>#include <cstring>#include <filesystem>#include <new>#include <stdexcept>#include <string>
Go to the source code of this file.
Functions | |
| template<typename Fn > | |
| static entropic_error_t | c_api_try (entropic_handle_t handle, Fn &&fn) |
| Run a C-API entry-point body inside an exception barrier. | |
| static char * | alloc_cstr (const char *src) |
| Allocate a C string copy via the engine allocator. | |
| static char * | alloc_cstr (const std::string &src) |
| Allocate a C string copy from std::string. | |
| const char * | entropic_last_error (entropic_handle_t handle) |
| Read the per-handle last_error under api_mutex. | |
| static entropic_error_t | check_orchestrator (entropic_handle_t h) |
| Check handle prerequisites for orchestrator APIs. | |
| static entropic_error_t | check_mcp_auth (entropic_handle_t h) |
| Check handle prerequisites for MCP auth APIs. | |
| static entropic_error_t | check_identity (entropic_handle_t h) |
| Check handle prerequisites for identity manager APIs. | |
| static entropic::InferenceBackend * | require_active_backend (entropic_handle_t h, const char *tier_name) |
| Resolve tier name to an ACTIVE backend, or throw. | |
| entropic_error_t | entropic_create (entropic_handle_t *handle) |
| Create a new engine instance. | |
| static std::vector< std::string > | resolve_allowed_tools (entropic_engine *h, const std::string &tier) |
| Post-parse config setup: load bundled models, set configured. | |
| static std::vector< std::string > | filter_tools (const nlohmann::json &all_tools, const std::vector< std::string > &allowed) |
| Filter tool definitions by allowed list. | |
| static int | facade_get_tool_prompt (const char *tier, char **result, void *user_data) |
| Build formatted tool prompt for a tier. | |
| static void | wire_external_interrupt (entropic_handle_t h) |
| Wire engine interrupt propagation into MCP transports (P1-10). | |
| static void | rewire_stream_observer (entropic_handle_t h) |
| Propagate any pre-configure stream observer to the new engine. | |
| static void | rewire_queue_observer (entropic_handle_t h) |
| Propagate any pre-configure queue observer to the new engine. | |
| static void | rewire_state_observer (entropic_handle_t h) |
| Propagate any pre-configure state observer to the new engine. | |
| static void | rewire_critique_callbacks (entropic_handle_t h) |
| Propagate pre-configure critique callbacks to a newly- constructed ConstitutionalValidator (gh#50, v2.1.12). | |
| static void | rewire_observers (entropic_handle_t h) |
| Re-bind every pre-configure observer to the new engine. | |
| static void | populate_tier_info (entropic_handle_t h, const std::filesystem::path &data_dir, const std::string &shared_prefix) |
| Register per-tier ChildContextInfo with the engine. | |
| static bool | si_create_delegation (const char *parent_id, const char *delegating_tier, const char *target_tier, const char *task, int max_turns, std::string &delegation_id, std::string &child_conversation_id, void *user_data) |
| Initialize persistence: storage + session logger. | |
| static bool | si_create_conversation (const char *title, std::string &conversation_id, void *user_data) |
| StorageInterface bridge: create_conversation trampoline. | |
| static bool | si_complete_delegation (const char *delegation_id, const char *status, const char *summary, void *user_data) |
| StorageInterface bridge: complete_delegation trampoline. | |
| static bool | si_save_conversation (const char *conversation_id, const char *messages_json, void *user_data) |
| StorageInterface bridge: save_conversation trampoline. | |
| static bool | si_save_snapshot (const char *conversation_id, const char *messages_json, void *user_data) |
| StorageInterface bridge: save_snapshot trampoline. | |
| static bool | si_load_delegation_with_messages (const char *delegation_id, std::string &result_json, void *user_data) |
| StorageInterface bridge: load_delegation_with_messages. | |
| static entropic::StorageInterface | build_storage_iface (entropic::SqliteStorageBackend *sb) |
Build a populated StorageInterface bound to sb. | |
| static void | init_persistence (entropic_handle_t h) |
| Initialize persistence: storage + session logger + StorageInterface. | |
| static std::vector< std::string > | collect_delegatable_tiers (const entropic::ParsedConfig &config) |
| Collect valid delegation targets from handoff_rules. | |
| static void | init_mcp_servers (entropic_handle_t h, const std::filesystem::path &data_dir) |
| Initialize MCP servers with resolved working directory. | |
| static std::string | build_shared_prompt_prefix (entropic_handle_t h, const std::filesystem::path &data_dir) |
| Build shared system prompt prefix (constitution + app_context). | |
| static void | thread_frontmatter_sampler (entropic::TierConfig &tc, const entropic::prompts::IdentityFrontmatter &fm) |
| Cache per-tier frontmatter fields (allowed_tools, validation_rules, relay). | |
| static void | apply_identity_frontmatter (entropic_handle_t h, const std::string &name, const entropic::prompts::IdentityFrontmatter &fm) |
| Apply a parsed identity's frontmatter to the engine handle. | |
| static void | cache_tier_allowed_tools (entropic_handle_t h, const std::filesystem::path &data_dir) |
| Cache per-tier frontmatter fields from identity files. | |
| static void | thread_frontmatter_samplers (entropic_handle_t h, const std::filesystem::path &data_dir) |
| Thread per-tier frontmatter SAMPLERS into config pre-orchestrator. | |
| static char * | tool_history_json_thunk (size_t count, void *ud) |
| Wire the ToolExecutor and attach it to the engine. | |
| static void | wire_tool_executor (entropic_handle_t h) |
| Wire the ToolExecutor and attach it to the engine. | |
| static char * | sp_get_validation (void *ud) |
| Return the validator's last verdict as JSON for ON_COMPLETE. | |
| static void | wire_hooks_and_validator (entropic_handle_t h, entropic::InferenceInterface &iface, const std::string &constitution_text) |
| Wire hook dispatch and attach the constitutional validator. | |
| static char * | sp_get_config (void *ud) |
| State provider: get_config. | |
| static std::string | build_assembled_prompt_for_tier (entropic_engine *h, const std::string &tier_name) |
| Build the assembled system prompt the engine would send for a given tier (constitution + app_context + identity body + tool defs). | |
| static char * | sp_get_identities (void *ud) |
| State provider: get_identities. | |
| static char * | sp_get_tools (void *ud) |
| State provider: get_tools. | |
| static char * | sp_get_history (int max_entries, void *ud) |
| State provider: get_history — conversation context snapshot. | |
| static char * | sp_get_residency (void *ud) |
| State provider: get_residency — VRAM residency snapshot. | |
| static char * | sp_get_state (void *ud) |
| State provider: get_state (runtime environment). | |
| static char * | sp_get_metrics (void *ud) |
| State provider: get_metrics. | |
| static char * | sp_get_docs (const char *section, void *ud) |
| State provider: get_docs. | |
| static char * | sp_search_delegations (const char *query, int max_results, void *ud) |
| State provider: search_delegations (gh#32, v2.1.6). | |
| static char * | sp_load_delegation_conversation (const char *delegation_id, void *ud) |
| State provider: load_delegation_conversation (gh#32, v2.1.6). | |
| static void | wire_state_provider (entropic_handle_t h) |
| Wire state provider to the EntropicServer. | |
| static void | wire_tier_validation_rules (entropic_handle_t h) |
| Pass per-identity validation rules to the validator. | |
| static entropic::LoopConfig | build_loop_config (entropic_handle_t h) |
| Build LoopConfig from parsed config. | |
| static void | start_external_bridge (entropic_handle_t h) |
| Start the external MCP bridge if enabled in config. | |
| static entropic_error_t | reject_if_configured (entropic_handle_t h) |
| Post-parse config setup: subsystem construction + wiring. | |
| static entropic_error_t | init_orchestrator (entropic_handle_t h, const std::filesystem::path &data_dir) |
| Shared body of all entropic_configure* entry points. | |
| static void | init_engine_and_interfaces (entropic_handle_t h, const std::filesystem::path &data_dir) |
| Build the engine + inference interfaces (configure step 2). | |
| static void | wire_prompts_and_persistence (entropic_handle_t h, const std::filesystem::path &data_dir) |
| Assemble prompts + wire validation/persistence (config step 3). | |
| static entropic_error_t | configure_common (entropic_handle_t h) |
| Shared body of all entropic_configure* entry points. | |
| static entropic_error_t | do_configure_json (entropic_handle_t handle, const char *config_json) |
entropic_configure body — wrapped by c_api_try in the public entry. | |
| entropic_error_t | entropic_configure (entropic_handle_t handle, const char *config_json) |
| Configure the engine from a JSON/YAML config string. | |
| static entropic_error_t | do_configure_from_file (entropic_handle_t handle, const char *config_path) |
entropic_configure_from_file body — wrapped by c_api_try. | |
| entropic_error_t | entropic_configure_from_file (entropic_handle_t handle, const char *config_path) |
| Configure the engine from a YAML config file. | |
| static entropic_error_t | do_configure_dir (entropic_handle_t handle, const char *project_dir) |
entropic_configure_dir body — wrapped by c_api_try. | |
| entropic_error_t | entropic_configure_dir (entropic_handle_t handle, const char *project_dir) |
| Configure using layered resolution (project dir). | |
| void | entropic_destroy (entropic_handle_t handle) |
| Destroy an engine instance. | |
| const char * | entropic_version (void) |
| Get the library version string. | |
| int | entropic_api_version (void) |
| Get the plugin API version number. | |
| int64_t | entropic_seconds_since_last_activity (entropic_handle_t handle) |
| gh#35: idle-time accessor for host-side idle-exit policies. | |
| void * | entropic_alloc (size_t size) |
| Allocate memory using the engine's allocator. | |
| void | entropic_free (void *ptr) |
| Free memory allocated by the engine. | |
| entropic_error_t | entropic_run (entropic_handle_t handle, const char *input, char **result_json) |
| Single-turn blocking agentic run. | |
| static entropic_error_t | run_as_inner (entropic_handle_t handle, const char *tier, const char *input, char **result_json) |
| Run + serialize for entropic_run_as (gh#99). | |
| entropic_error_t | entropic_run_as (entropic_handle_t handle, const char *tier_or_identity, const char *input, char **result_json) |
| Single-turn blocking run under a named tier (gh#99). | |
| static std::string | serialize_batch_results (const std::vector< entropic::GenerationResult > &results) |
| Serialize batch results to a JSON array string (gh#98). | |
| static std::vector< std::vector< entropic::Message > > | build_batch_messages (entropic_handle_t handle, const char **tiers, const char **prompts, size_t n, std::vector< std::string > &tiers_out) |
| Build per-request messages for entropic_run_batch (gh#98). | |
| entropic_error_t | entropic_run_batch (entropic_handle_t handle, const char **tiers, const char **prompts, size_t n, char **result_json) |
| Same-prefix batch run on a shared resident model (gh#98). | |
| entropic_error_t | entropic_run_streaming (entropic_handle_t handle, const char *input, void(*on_token)(const char *token, size_t len, void *user_data), void *user_data, int *cancel_flag) |
| Streaming generation — delegates entirely to engine. | |
| static std::vector< entropic::Message > | parse_and_check_vision (entropic_handle_t handle, const char *messages_json, entropic_error_t &out_rc) |
| Parse messages_json and check vision-tier availability (gh#37/gh#41). | |
| static entropic_error_t | run_messages_inner (entropic_handle_t handle, const char *messages_json, char **result_json) |
| Blocking multimodal run (gh#37, v2.1.8). | |
| entropic_error_t | entropic_run_messages (entropic_handle_t handle, const char *messages_json, char **result_json) |
| Blocking multimodal agentic run (gh#37, v2.1.8). | |
| static entropic_error_t | run_messages_stream_inner (entropic_handle_t handle, const char *messages_json, void(*on_token)(const char *token, size_t len, void *user_data), void *user_data, int *cancel_flag) |
| Streaming multimodal run (gh#37, v2.1.8). | |
| entropic_error_t | entropic_run_messages_streaming (entropic_handle_t handle, const char *messages_json, void(*on_token)(const char *token, size_t len, void *user_data), void *user_data, int *cancel_flag) |
| Streaming multimodal agentic run (gh#37, v2.1.8). | |
| entropic_error_t | entropic_set_stream_observer (entropic_handle_t handle, void(*observer)(const char *token, size_t len, void *user_data), void *user_data) |
| Set a global stream observer callback. | |
| entropic_error_t | entropic_validation_set_auto_retry (entropic_handle_t handle, int enabled) |
| Toggle automatic constitutional revision. | |
| entropic_error_t | entropic_validation_resume_retry (entropic_handle_t handle) |
| Resume a paused constitutional revision pass. | |
| entropic_error_t | entropic_validation_accept_last (entropic_handle_t handle) |
| Accept the last paused attempt as the final answer. | |
| entropic_error_t | entropic_set_attempt_boundary_cb (entropic_handle_t handle, ent_validation_attempt_boundary_cb cb, void *user_data) |
| Register attempt-boundary callback on the validator. | |
| entropic_error_t | entropic_set_delegation_callbacks (entropic_handle_t handle, ent_delegation_start_cb on_start, ent_delegation_complete_cb on_complete, void *user_data) |
| Register delegation start/complete callbacks (gh#29, v2.1.5). | |
| entropic_error_t | entropic_set_state_observer (entropic_handle_t handle, void(*observer)(int state, void *user_data), void *user_data) |
| Register a state-change observer on the handle. | |
| entropic_error_t | entropic_set_critique_callbacks (entropic_handle_t handle, void(*start_cb)(void *user_data), void(*end_cb)(void *user_data), void *user_data) |
| Register critique start/end callbacks on the handle (gh#50, v2.1.12). | |
| entropic_error_t | entropic_interrupt (entropic_handle_t handle) |
| Interrupt a running generation (thread-safe). | |
| entropic_error_t | entropic_queue_user_message (entropic_handle_t handle, const char *message) |
| Enqueue a follow-up user message while a run is in flight. | |
| entropic_error_t | entropic_user_message_queue_depth (entropic_handle_t handle, size_t *count) |
| Snapshot the mid-gen queue depth. | |
| entropic_error_t | entropic_clear_user_message_queue (entropic_handle_t handle) |
| Drop all queued mid-gen user messages. | |
| entropic_error_t | entropic_set_queue_observer (entropic_handle_t handle, void(*observer)(const char *, size_t, void *), void *user_data) |
| Register the queue-consumption observer. | |
| entropic_error_t | entropic_context_clear (entropic_handle_t handle) |
| Clear conversation history. | |
| entropic_error_t | entropic_context_get (entropic_handle_t handle, char **messages_json) |
| Get conversation as JSON array. | |
| entropic_error_t | entropic_context_count (entropic_handle_t handle, size_t *count) |
| Get conversation message count. | |
| entropic_error_t | entropic_context_usage (entropic_handle_t handle, size_t *tokens_used, size_t *capacity) |
| Read current context-window pressure (gh#39, v2.1.8). | |
| static entropic_error_t | do_state_save (entropic_handle_t handle, const char *tier_name, const char *path) |
| Save tier's KV cache to file body (gh#23 v2.3.25). | |
| entropic_error_t | entropic_state_save (entropic_handle_t handle, const char *tier_name, const char *path) |
| Save a tier's KV cache to a file (gh#23 v2.3.25, MVP item 13). | |
| static bool | read_state_file (const char *path, std::vector< uint8_t > &out_buf) |
| Load tier's KV cache from file body (gh#23 v2.3.25). | |
| static entropic_error_t | do_state_load (entropic_handle_t handle, const char *tier_name, const char *path) |
| Load tier's KV cache from file body (gh#23 v2.3.25). | |
| entropic_error_t | entropic_state_load (entropic_handle_t handle, const char *tier_name, const char *path) |
| Restore a tier's KV cache from a file (gh#23 v2.3.25). | |
| entropic_error_t | entropic_metrics_json (entropic_handle_t handle, char **out) |
| Get loop metrics as JSON (flat + per_tier). | |
| entropic_error_t | entropic_adapter_load (entropic_handle_t handle, const char *adapter_name, const char *adapter_path, const char *base_model_path, float scale) |
| Load a LoRA adapter into RAM. | |
| entropic_error_t | entropic_adapter_unload (entropic_handle_t handle, const char *adapter_name) |
| Unload a LoRA adapter. | |
| entropic_error_t | entropic_adapter_swap (entropic_handle_t handle, const char *adapter_name) |
| Swap active LoRA adapter. | |
| int | entropic_adapter_state (entropic_handle_t handle, const char *adapter_name) |
| Query adapter lifecycle state. | |
| char * | entropic_adapter_info (entropic_handle_t handle, const char *adapter_name) |
| Get adapter info as JSON string. | |
| char * | entropic_adapter_list (entropic_handle_t handle) |
| List all known adapters as a JSON array. | |
| entropic_error_t | entropic_grammar_register (entropic_handle_t handle, const char *key, const char *gbnf_content) |
| Register a grammar by key with GBNF content. | |
| entropic_error_t | entropic_grammar_register_file (entropic_handle_t handle, const char *key, const char *path) |
| Register a grammar from a GBNF file. | |
| entropic_error_t | entropic_grammar_deregister (entropic_handle_t handle, const char *key) |
| Remove a grammar from the registry. | |
| char * | entropic_grammar_get (entropic_handle_t handle, const char *key) |
| Get grammar GBNF content by key. | |
| char * | entropic_grammar_validate (const char *gbnf_content) |
| Validate a GBNF grammar string without registering. | |
| char * | entropic_grammar_list (entropic_handle_t handle) |
| List all registered grammars as a JSON array. | |
| entropic_error_t | entropic_profile_register (entropic_handle_t handle, const char *profile_json) |
| Register a custom GPU resource profile from JSON. | |
| entropic_error_t | entropic_profile_deregister (entropic_handle_t handle, const char *name) |
| Remove a GPU resource profile by name. | |
| char * | entropic_profile_get (entropic_handle_t handle, const char *name) |
| Get a GPU resource profile by name as JSON. | |
| char * | entropic_profile_list (entropic_handle_t handle) |
| List all registered profile names as a JSON array. | |
| double | entropic_throughput_tok_per_sec (entropic_handle_t handle, const char *model_path) |
| Get EWMA throughput estimate in tokens per second. | |
| void | entropic_throughput_reset (entropic_handle_t handle, const char *model_path) |
| Reset throughput tracking data. | |
| entropic_error_t | entropic_grant_mcp_key (entropic_handle_t handle, const char *identity_name, const char *pattern, entropic_mcp_access_level_t level) |
| Grant an MCP tool key to an identity. | |
| entropic_error_t | entropic_revoke_mcp_key (entropic_handle_t handle, const char *identity_name, const char *pattern) |
| Revoke an MCP tool key from an identity. | |
| int | entropic_check_mcp_key (entropic_handle_t handle, const char *identity_name, const char *tool_name, entropic_mcp_access_level_t level) |
| Check MCP key authorization for an identity. | |
| char * | entropic_list_mcp_keys (entropic_handle_t handle, const char *identity_name) |
| List MCP keys for an identity as JSON array. | |
| entropic_error_t | entropic_grant_mcp_key_from (entropic_handle_t handle, const char *granter, const char *grantee, const char *pattern, entropic_mcp_access_level_t level) |
| Grant a key from one identity to another. | |
| char * | entropic_serialize_mcp_keys (entropic_handle_t handle) |
| Serialize all identity key sets to JSON. | |
| entropic_error_t | entropic_deserialize_mcp_keys (entropic_handle_t handle, const char *json) |
| Deserialize all identity key sets from JSON. | |
| entropic_error_t | entropic_create_identity (entropic_handle_t handle, const char *config_json) |
| Create a dynamic identity from JSON config. | |
| entropic_error_t | entropic_update_identity (entropic_handle_t handle, const char *name, const char *config_json) |
| Update an existing dynamic identity. | |
| entropic_error_t | entropic_destroy_identity (entropic_handle_t handle, const char *name) |
| Destroy a dynamic identity. | |
| char * | entropic_get_identity_config (entropic_handle_t handle, const char *name) |
| Get identity config as JSON by name. | |
| char * | entropic_list_identities (entropic_handle_t handle) |
| List all identity names as JSON array. | |
| entropic_error_t | entropic_identity_count (entropic_handle_t handle, size_t *total, size_t *dynamic) |
| Get identity count (total and dynamic). | |
| entropic_error_t | entropic_get_logprobs (entropic_handle_t handle, const char *model_id, const int32_t *tokens, int n_tokens, entropic_logprob_result_t *result) |
| Evaluate per-token log-probabilities for a token sequence. | |
| entropic_error_t | entropic_compute_perplexity (entropic_handle_t handle, const char *model_id, const int32_t *tokens, int n_tokens, float *perplexity) |
| Compute perplexity for a token sequence. | |
| void | entropic_free_logprob_result (entropic_logprob_result_t *result) |
| Free internal arrays of a logprob result. | |
| int | entropic_model_has_vision (entropic_handle_t handle, const char *model_id) |
| Check if a model has vision (multimodal) capability. | |
| entropic_error_t | entropic_validation_set_enabled (entropic_handle_t handle, bool enabled) |
| Enable or disable constitutional validation globally. | |
| entropic_error_t | entropic_validation_set_identity (entropic_handle_t handle, const char *identity_name, bool enabled) |
| Set per-identity validation override. | |
| char * | entropic_validation_last_result (entropic_handle_t handle) |
| Get last validation result as JSON. | |
| entropic_error_t | entropic_get_diagnostic_prompt (entropic_handle_t handle, char **prompt_out) |
| Get diagnostic prompt text for /diagnose command (stub). | |
| entropic_error_t | entropic_speculative_compat (entropic_handle_t handle, int *compatible, char **diagnostic) |
| Query speculative-decoding compatibility for the configured target/draft pair. | |
| entropic_error_t | entropic_set_residency_observer (entropic_handle_t handle, entropic_residency_observer_t observer, void *user_data) |
| Register a residency observer on the orchestrator. | |
| entropic_error_t | entropic_residency_snapshot (entropic_handle_t handle, char **out_json) |
| Return the engine's current residency-set snapshot as JSON. | |
Variables | |
| static auto | s_log = entropic::log::get("facade") |
| static thread_local std::string | s_last_error_cache |
| static thread_local char | s_pre_create_error [512] = "" |
librentropic facade — C API implementation.
Owns the EntropicEngine handle struct and implements lifecycle (create/configure/destroy), generation, and subsystem stubs. Stubs are wired to real subsystems across Phases 0-5.
Definition in file entropic.cpp.
|
static |
Allocate a C string copy via the engine allocator.
Uses entropic_alloc so the caller can free with entropic_free(). Returns NULL on allocation failure (OOM).
| src | Source string (null-terminated). |
Definition at line 106 of file entropic.cpp.
|
static |
Allocate a C string copy from std::string.
| src | Source string. |
Definition at line 121 of file entropic.cpp.
|
static |
Apply a parsed identity's frontmatter to the engine handle.
| h | Engine handle. |
| name | Tier name. |
| fm | Parsed frontmatter. |
Definition at line 876 of file entropic.cpp.
|
static |
Build the assembled system prompt the engine would send for a given tier (constitution + app_context + identity body + tool defs).
Returns "" on any failure.
Demo ask #3 (v2.1.0). Static parts only — does NOT include the per-turn iteration / validation reminders, since those are runtime-dependent. Runtime augmentations live in ResponseGenerator::inject_engine_state_reminder.
@utility
Definition at line 1171 of file entropic.cpp.
|
static |
Build per-request messages for entropic_run_batch (gh#98).
Each request becomes [system(tier prompt), user(prompt)] so same-tier requests share a prompt prefix the backend can prefill once.
| handle | Engine handle (for per-tier system prompts). | |
| tiers | C array of tier names (entries may be NULL → default). | |
| prompts | C array of user prompts. | |
| n | Request count. | |
| [out] | tiers_out | Normalized tier strings ("" for NULL/default). |
Definition at line 2102 of file entropic.cpp.
|
static |
Build LoopConfig from parsed config.
| h | Engine handle with config populated. |
Definition at line 1478 of file entropic.cpp.
|
static |
Build shared system prompt prefix (constitution + app_context).
| h | Engine handle with config loaded. |
| data_dir | Bundled data directory. |
Definition at line 802 of file entropic.cpp.
|
static |
Build a populated StorageInterface bound to sb.
gh#32 (v2.1.6): pre-2.1.6 nothing called AgentEngine::set_storage so the engine's StorageInterface fields were all nullptr and the delegation/compaction storage paths were dead code. This builder closes that gap.
| sb | Storage backend (non-owning). |
AgentEngine::set_storage. Definition at line 704 of file entropic.cpp.
|
static |
Run a C-API entry-point body inside an exception barrier.
gh#74 (v2.3.13): every extern "C" function in this translation unit MUST guarantee that no C++ exception escapes back into the caller (per docs/architecture-cpp.md's "exceptions do not cross
.so boundaries" rule). Wraps the body in try/catch and maps the three exception families we've actually seen to documented error codes:
std::filesystem::filesystem_error → ENTROPIC_ERROR_IOnlohmann::json::exception → ENTROPIC_ERROR_INVALID_CONFIGstd::exception → ENTROPIC_ERROR_INTERNALThe handle's last_error is populated with what() when handle is non-null so consumers can read it via entropic_last_error(). Logs at error level on every catch so the operator sees the exception type alongside the C error code that surfaced.
Rolled out incrementally — v2.3.13 covers the three configure entry points that gh#74 reported as visibly leaking. Other extern-C functions can wrap their bodies the same way as needed.
| handle | Engine handle for last_error write (may be NULL). |
| fn | Body returning the natural success / error code. |
fn()'s return value on no exception; mapped error code otherwise. @utility Definition at line 75 of file entropic.cpp.
|
static |
Cache per-tier frontmatter fields from identity files.
| h | Engine handle with config + engine constructed. |
| data_dir | Bundled data directory. |
Definition at line 903 of file entropic.cpp.
|
static |
Check handle prerequisites for identity manager APIs.
| h | Engine handle. |
Definition at line 194 of file entropic.cpp.
|
static |
Check handle prerequisites for MCP auth APIs.
| h | Engine handle. |
Definition at line 179 of file entropic.cpp.
|
static |
Check handle prerequisites for orchestrator APIs.
| h | Engine handle. |
Definition at line 164 of file entropic.cpp.
|
static |
Collect valid delegation targets from handoff_rules.
Only tiers that appear as TARGETS in handoff_rules are included. Sources are excluded — a tier should not appear in its own delegate enum (self-delegation creates a worktree cycle for no purpose and confuses small models).
When handoff_rules is empty, falls back to all configured tiers except the default tier (preserves delegation for simple configs that define multiple tiers without explicit routing).
| config | Parsed engine config. |
Definition at line 759 of file entropic.cpp.
|
static |
Shared body of all entropic_configure* entry points.
Definition at line 1679 of file entropic.cpp.
|
static |
entropic_configure_dir body — wrapped by c_api_try.
Definition at line 1796 of file entropic.cpp.
|
static |
entropic_configure_from_file body — wrapped by c_api_try.
Definition at line 1747 of file entropic.cpp.
|
static |
entropic_configure body — wrapped by c_api_try in the public entry.
Definition at line 1710 of file entropic.cpp.
|
static |
Load tier's KV cache from file body (gh#23 v2.3.25).
Definition at line 2801 of file entropic.cpp.
|
static |
Save tier's KV cache to file body (gh#23 v2.3.25).
Definition at line 2742 of file entropic.cpp.
| char * entropic_adapter_info | ( | entropic_handle_t | handle, |
| const char * | adapter_name | ||
| ) |
Get adapter info as JSON string.
Get adapter info as JSON.
Returns a JSON object with name, state, scale, ram_bytes, path, tier_name, and base_model_path. Caller frees with entropic_free().
Definition at line 3009 of file entropic.cpp.
| char * entropic_adapter_list | ( | entropic_handle_t | handle | ) |
List all known adapters as a JSON array.
List all adapters as JSON array.
Returns a JSON array of objects, each with name, state, scale, and tier_name. Caller frees with entropic_free().
Definition at line 3038 of file entropic.cpp.
| entropic_error_t entropic_adapter_load | ( | entropic_handle_t | handle, |
| const char * | adapter_name, | ||
| const char * | adapter_path, | ||
| const char * | base_model_path, | ||
| float | scale | ||
| ) |
Load a LoRA adapter into RAM.
Requires a configured engine. The adapter_manager needs llama_model* pointers that are only available from a loaded backend, so this delegates through the orchestrator's backend for the given tier. base_model_path is resolved to a tier via model path matching.
Definition at line 2865 of file entropic.cpp.
| int entropic_adapter_state | ( | entropic_handle_t | handle, |
| const char * | adapter_name | ||
| ) |
Query adapter lifecycle state.
Query adapter state.
Returns the AdapterState as an integer: 0=COLD, 1=WARM, 2=HOT. Returns -1 if the handle is invalid or adapter name not found.
Definition at line 2981 of file entropic.cpp.
| entropic_error_t entropic_adapter_swap | ( | entropic_handle_t | handle, |
| const char * | adapter_name | ||
| ) |
Swap active LoRA adapter.
Swap the active LoRA adapter.
Adapter swap requires llama_context* for activation/deactivation. The C API cannot safely provide this — use tier-based adapter configuration for lifecycle management.
Definition at line 2946 of file entropic.cpp.
| entropic_error_t entropic_adapter_unload | ( | entropic_handle_t | handle, |
| const char * | adapter_name | ||
| ) |
Unload a LoRA adapter.
Adapter unload requires llama_context* for deactivation if HOT. The C API cannot safely provide this — use tier-based adapter configuration for lifecycle management.
Definition at line 2908 of file entropic.cpp.
| void * entropic_alloc | ( | size_t | size | ) |
Allocate memory using the engine's allocator.
Definition at line 1925 of file entropic.cpp.
| int entropic_api_version | ( | void | ) |
Get the plugin API version number.
Get the C API version number.
Definition at line 1904 of file entropic.cpp.
| int entropic_check_mcp_key | ( | entropic_handle_t | handle, |
| const char * | identity_name, | ||
| const char * | tool_name, | ||
| entropic_mcp_access_level_t | level | ||
| ) |
Check MCP key authorization for an identity.
Check if a tool call is authorized for an identity.
Definition at line 3480 of file entropic.cpp.
| entropic_error_t entropic_clear_user_message_queue | ( | entropic_handle_t | handle | ) |
Drop all queued mid-gen user messages.
Drop all queued user messages.
Definition at line 2626 of file entropic.cpp.
| entropic_error_t entropic_compute_perplexity | ( | entropic_handle_t | handle, |
| const char * | model_id, | ||
| const int32_t * | tokens, | ||
| int | n_tokens, | ||
| float * | perplexity | ||
| ) |
Compute perplexity for a token sequence.
Convenience wrapper — resolves the tier backend and calls InferenceBackend::compute_perplexity().
Definition at line 3792 of file entropic.cpp.
| entropic_error_t entropic_configure | ( | entropic_handle_t | handle, |
| const char * | config_json | ||
| ) |
Configure the engine from a JSON/YAML config string.
Configure the engine from a JSON config string.
Definition at line 1730 of file entropic.cpp.
| entropic_error_t entropic_configure_dir | ( | entropic_handle_t | handle, |
| const char * | project_dir | ||
| ) |
Configure using layered resolution (project dir).
Configure engine using layered config resolution.
Loads bundled default → global → project config.local.yaml → env. Sets config.log_dir to project_dir if not already set. gh#31 (v2.1.6): propagates project_dir to AgentEngine::set_project_dir so sandbox snapshots use the configured tree rather than CWD.
Definition at line 1839 of file entropic.cpp.
| entropic_error_t entropic_configure_from_file | ( | entropic_handle_t | handle, |
| const char * | config_path | ||
| ) |
Configure the engine from a YAML config file.
Configure engine from a YAML or JSON config file.
Definition at line 1779 of file entropic.cpp.
| entropic_error_t entropic_context_clear | ( | entropic_handle_t | handle | ) |
Clear conversation history.
Clear conversation history, starting a new session.
| handle | Engine handle returned by entropic_create. |
Definition at line 2668 of file entropic.cpp.
| entropic_error_t entropic_context_count | ( | entropic_handle_t | handle, |
| size_t * | count | ||
| ) |
Get conversation message count.
Get the number of messages in the conversation.
| handle | Engine handle returned by entropic_create. |
| count | Out-param: receives the token count. |
Definition at line 2701 of file entropic.cpp.
| entropic_error_t entropic_context_get | ( | entropic_handle_t | handle, |
| char ** | messages_json | ||
| ) |
Get conversation as JSON array.
Get the current conversation history as a JSON array.
| handle | Engine handle returned by entropic_create. |
| messages_json | Out-param: newly allocated JSON string (caller owns; free with entropic_free). |
Definition at line 2683 of file entropic.cpp.
| entropic_error_t entropic_context_usage | ( | entropic_handle_t | handle, |
| size_t * | tokens_used, | ||
| size_t * | capacity | ||
| ) |
Read current context-window pressure (gh#39, v2.1.8).
Read current context-window pressure for the active tier.
Mirrors the Context: N/M tokens (P%) line emitted by core.context_manager. Reads from the engine's existing context_usage(messages) helper against the current conversation.
| handle | Engine handle. |
| tokens_used | Out-param: tokens in the current conversation. |
| capacity | Out-param: active tier's configured context_length. |
Definition at line 2723 of file entropic.cpp.
| entropic_error_t entropic_create | ( | entropic_handle_t * | handle | ) |
Create a new engine instance.
Allocates the engine handle struct and initializes Phase 0 members (hook_registry, api_mutex, last_error, state flags). Subsystem pointers remain null until entropic_configure().
Definition at line 241 of file entropic.cpp.
| entropic_error_t entropic_create_identity | ( | entropic_handle_t | handle, |
| const char * | config_json | ||
| ) |
Create a dynamic identity from JSON config.
Create a dynamic identity.
Definition at line 3594 of file entropic.cpp.
| entropic_error_t entropic_deserialize_mcp_keys | ( | entropic_handle_t | handle, |
| const char * | json | ||
| ) |
Deserialize all identity key sets from JSON.
Definition at line 3573 of file entropic.cpp.
| void entropic_destroy | ( | entropic_handle_t | handle | ) |
Destroy an engine instance.
Destroy an engine instance and free all resources.
Tears down subsystems in reverse creation order. Each subsystem pointer is null-safe. After this call, the handle is invalid.
Definition at line 1858 of file entropic.cpp.
| entropic_error_t entropic_destroy_identity | ( | entropic_handle_t | handle, |
| const char * | name | ||
| ) |
Destroy a dynamic identity.
Definition at line 3657 of file entropic.cpp.
| void entropic_free | ( | void * | ptr | ) |
Free memory allocated by the engine.
Free a string allocated by the server.
Free memory allocated by the engine or entropic_alloc().
@utility
Definition at line 1935 of file entropic.cpp.
| void entropic_free_logprob_result | ( | entropic_logprob_result_t * | result | ) |
Free internal arrays of a logprob result.
Frees logprobs and tokens arrays, then NULLs the pointers to prevent double-free. The struct itself is caller-owned.
@utility
Definition at line 3824 of file entropic.cpp.
| entropic_error_t entropic_get_diagnostic_prompt | ( | entropic_handle_t | handle, |
| char ** | prompt_out | ||
| ) |
Get diagnostic prompt text for /diagnose command (stub).
Get the diagnostic prompt text for /diagnose command.
| handle | Engine handle returned by entropic_create. |
| prompt_out | Out-param: newly allocated JSON string (caller owns; free with entropic_free). |
Definition at line 3938 of file entropic.cpp.
| char * entropic_get_identity_config | ( | entropic_handle_t | handle, |
| const char * | name | ||
| ) |
Get identity config as JSON by name.
Get identity configuration as JSON by name.
Definition at line 3675 of file entropic.cpp.
| entropic_error_t entropic_get_logprobs | ( | entropic_handle_t | handle, |
| const char * | model_id, | ||
| const int32_t * | tokens, | ||
| int | n_tokens, | ||
| entropic_logprob_result_t * | result | ||
| ) |
Evaluate per-token log-probabilities for a token sequence.
Resolves model_id as a tier name, retrieves the backend, and delegates to InferenceBackend::evaluate_logprobs(). The result arrays are engine-allocated — free with entropic_free_logprob_result().
Definition at line 3747 of file entropic.cpp.
| entropic_error_t entropic_grammar_deregister | ( | entropic_handle_t | handle, |
| const char * | key | ||
| ) |
Remove a grammar from the registry.
Delegates to GrammarRegistry::deregister(). Bundled grammars can also be removed (allows overriding defaults).
Definition at line 3134 of file entropic.cpp.
| char * entropic_grammar_get | ( | entropic_handle_t | handle, |
| const char * | key | ||
| ) |
Get grammar GBNF content by key.
Get grammar content by key.
Returns the raw GBNF content string for the named grammar. Caller frees with entropic_free().
Definition at line 3164 of file entropic.cpp.
| char * entropic_grammar_list | ( | entropic_handle_t | handle | ) |
List all registered grammars as a JSON array.
List all registered grammars as JSON array.
Returns metadata for each grammar: key, source, validated flag, and error string. Content is omitted for efficiency. Caller frees with entropic_free().
Definition at line 3214 of file entropic.cpp.
| entropic_error_t entropic_grammar_register | ( | entropic_handle_t | handle, |
| const char * | key, | ||
| const char * | gbnf_content | ||
| ) |
Register a grammar by key with GBNF content.
Register a grammar by key from a GBNF content string.
Delegates to GrammarRegistry::register_grammar(). The grammar is validated on registration; invalid grammars are still stored with error metadata.
Definition at line 3068 of file entropic.cpp.
| entropic_error_t entropic_grammar_register_file | ( | entropic_handle_t | handle, |
| const char * | key, | ||
| const char * | path | ||
| ) |
Register a grammar from a GBNF file.
Register a grammar from a file path.
Delegates to GrammarRegistry::register_from_file(). File is read, validated, and stored under the given key.
Definition at line 3101 of file entropic.cpp.
| char * entropic_grammar_validate | ( | const char * | gbnf_content | ) |
Validate a GBNF grammar string without registering.
Stateless validation — does not require a handle or loaded model. Delegates to GrammarRegistry::validate().
Definition at line 3193 of file entropic.cpp.
| entropic_error_t entropic_grant_mcp_key | ( | entropic_handle_t | handle, |
| const char * | identity_name, | ||
| const char * | pattern, | ||
| entropic_mcp_access_level_t | level | ||
| ) |
Grant an MCP tool key to an identity.
Definition at line 3440 of file entropic.cpp.
| entropic_error_t entropic_grant_mcp_key_from | ( | entropic_handle_t | handle, |
| const char * | granter, | ||
| const char * | grantee, | ||
| const char * | pattern, | ||
| entropic_mcp_access_level_t | level | ||
| ) |
Grant a key from one identity to another.
Definition at line 3530 of file entropic.cpp.
| entropic_error_t entropic_identity_count | ( | entropic_handle_t | handle, |
| size_t * | total, | ||
| size_t * | dynamic | ||
| ) |
Get identity count (total and dynamic).
Get identity count.
Definition at line 3720 of file entropic.cpp.
| entropic_error_t entropic_interrupt | ( | entropic_handle_t | handle | ) |
Interrupt a running generation (thread-safe).
Interrupt a running generation.
| handle | Engine handle returned by entropic_create. |
Definition at line 2571 of file entropic.cpp.
| const char * entropic_last_error | ( | entropic_handle_t | handle | ) |
Read the per-handle last_error under api_mutex.
Get the last error message for a handle.
Pre-v2.2.6 the public symbol lived in src/types/error.cpp and ignored its handle parameter (v1.8.0 TODO never done). Moved here because the private engine_handle struct is only visible in the facade. Returns a thread-local cache copy so the pointer stays valid until the same thread reads again — matches the v1.8.0 contract documented in include/entropic/types/error.h.
@utility
Definition at line 150 of file entropic.cpp.
| char * entropic_list_identities | ( | entropic_handle_t | handle | ) |
List all identity names as JSON array.
Definition at line 3701 of file entropic.cpp.
| char * entropic_list_mcp_keys | ( | entropic_handle_t | handle, |
| const char * | identity_name | ||
| ) |
List MCP keys for an identity as JSON array.
List all MCP keys for an identity as JSON.
Definition at line 3501 of file entropic.cpp.
| entropic_error_t entropic_metrics_json | ( | entropic_handle_t | handle, |
| char ** | out | ||
| ) |
Get loop metrics as JSON (flat + per_tier).
Get loop metrics from the most recent run as JSON.
Reuses the state-provider sp_get_metrics builder so handle_status and the entropic.inspect tool return the same shape. (P2-15 follow-up, 2.0.6-rc16.2)
| handle | Engine handle. | |
| [out] | out | Output JSON; caller frees via entropic_free. |
Definition at line 2843 of file entropic.cpp.
| int entropic_model_has_vision | ( | entropic_handle_t | handle, |
| const char * | model_id | ||
| ) |
Check if a model has vision (multimodal) capability.
Check if a model has vision capability.
Resolves model_id as a tier name, retrieves the backend, and queries BackendCapability::VISION. Returns 1 if the model has an mmproj loaded, 0 if text-only.
Definition at line 3848 of file entropic.cpp.
| entropic_error_t entropic_profile_deregister | ( | entropic_handle_t | handle, |
| const char * | name | ||
| ) |
Remove a GPU resource profile by name.
Remove a GPU resource profile.
Delegates to ProfileRegistry::deregister(). Bundled profiles can be removed.
Definition at line 3290 of file entropic.cpp.
| char * entropic_profile_get | ( | entropic_handle_t | handle, |
| const char * | name | ||
| ) |
Get a GPU resource profile by name as JSON.
Get a profile by name as JSON.
Returns the profile as a JSON object with name, n_batch, n_threads, n_threads_batch, and description. Falls back to "balanced" if name not found (see ProfileRegistry::get). Caller frees with entropic_free().
Definition at line 3322 of file entropic.cpp.
| char * entropic_profile_list | ( | entropic_handle_t | handle | ) |
List all registered profile names as a JSON array.
List all registered profiles as JSON array.
Returns a sorted JSON array of profile name strings. Caller frees with entropic_free().
Definition at line 3356 of file entropic.cpp.
| entropic_error_t entropic_profile_register | ( | entropic_handle_t | handle, |
| const char * | profile_json | ||
| ) |
Register a custom GPU resource profile from JSON.
Register a custom GPU resource profile.
Parses the JSON string into a GPUResourceProfile and delegates to ProfileRegistry::register_profile(). Required JSON fields: "name". Optional: "n_batch", "n_threads", "n_threads_batch", "description".
Definition at line 3250 of file entropic.cpp.
| entropic_error_t entropic_queue_user_message | ( | entropic_handle_t | handle, |
| const char * | message | ||
| ) |
Enqueue a follow-up user message while a run is in flight.
Queue a user message to be injected at the next top-level turn boundary.
Pure passthrough to the engine's thread-safe queue primitive. Does NOT take api_mutex — entropic_run_streaming holds nothing while the agent loop is running, so this call must be lock-disjoint from the run path to avoid deadlock. The engine's per-queue mutex guarantees thread safety on the queue itself.
Definition at line 2592 of file entropic.cpp.
| entropic_error_t entropic_residency_snapshot | ( | entropic_handle_t | handle, |
| char ** | out_json | ||
| ) |
Return the engine's current residency-set snapshot as JSON.
Snapshot of the engine's current VRAM residency set.
Delegates to ModelOrchestrator::residency_snapshot_json which holds the swap mutex briefly for a consistent read of the loaded tier set and footprint accounting. The returned string is heap-allocated and must be freed by the caller with entropic_free_string.
Definition at line 4066 of file entropic.cpp.
| entropic_error_t entropic_revoke_mcp_key | ( | entropic_handle_t | handle, |
| const char * | identity_name, | ||
| const char * | pattern | ||
| ) |
Revoke an MCP tool key from an identity.
Definition at line 3461 of file entropic.cpp.
| entropic_error_t entropic_run | ( | entropic_handle_t | handle, |
| const char * | input, | ||
| char ** | result_json | ||
| ) |
Single-turn blocking agentic run.
Synchronous agentic loop.
Appends the user input to the conversation, runs the engine loop synchronously to completion (or interrupt/error), and returns the serialized result.
| handle | Engine handle returned by entropic_create. |
| input | Null-terminated user input string. |
| result_json | Out-parameter receiving a newly allocated JSON result string (caller owns, free with entropic_free). |
Definition at line 1955 of file entropic.cpp.
| entropic_error_t entropic_run_as | ( | entropic_handle_t | handle, |
| const char * | tier_or_identity, | ||
| const char * | input, | ||
| char ** | result_json | ||
| ) |
Single-turn blocking run under a named tier (gh#99).
Single-turn agentic run under a named tier (gh#99).
Per-call tier/grammar/identity selection on the shared resident model: runs input under tier_or_identity's grammar + system prompt + samplers with no 2nd model load and no reconfigure. Same result contract as entropic_run().
| handle | Engine handle returned by entropic_create. |
| tier_or_identity | Tier name to run this call under. |
| input | Null-terminated user input string. |
| result_json | Out: newly allocated JSON result (caller frees with entropic_free). |
Definition at line 2045 of file entropic.cpp.
| entropic_error_t entropic_run_batch | ( | entropic_handle_t | handle, |
| const char ** | tiers, | ||
| const char ** | prompts, | ||
| size_t | n, | ||
| char ** | result_json | ||
| ) |
Same-prefix batch run on a shared resident model (gh#98).
Runs N independent same-prefix requests together: the shared prompt prefix is prefilled once and fanned out, each request sampled under its tier's grammar. One-shot generations (no agentic loop) — suited to per-tick game agents. Results are returned as a single JSON array string.
| handle | Engine handle. | |
| tiers | C array of N tier names (entries may be NULL → default tier). | |
| prompts | C array of N user prompts. | |
| n | Request count. | |
| [out] | result_json | JSON array of N {content, finish_reason, tool_calls}. Caller frees with entropic_free(). |
Definition at line 2145 of file entropic.cpp.
| entropic_error_t entropic_run_messages | ( | entropic_handle_t | handle, |
| const char * | messages_json, | ||
| char ** | result_json | ||
| ) |
Blocking multimodal agentic run (gh#37, v2.1.8).
Multimodal-aware agentic run with messages-array input (gh#37).
Front-line argument validation, then dispatches to run_messages_inner() under a try/catch that maps unexpected exceptions to ENTROPIC_ERROR_GENERATE_FAILED. See the public declaration in entropic.h for the full error matrix.
| handle | Engine handle. |
| messages_json | JSON array of message objects. |
| result_json | Out-param: malloc'd JSON result. Caller frees. |
Definition at line 2305 of file entropic.cpp.
| entropic_error_t entropic_run_messages_streaming | ( | entropic_handle_t | handle, |
| const char * | messages_json, | ||
| void(*)(const char *token, size_t len, void *user_data) | on_token, | ||
| void * | user_data, | ||
| int * | cancel_flag | ||
| ) |
Streaming multimodal agentic run (gh#37, v2.1.8).
Streaming variant of entropic_run_messages (gh#37).
Streaming sibling of entropic_run_messages. Same validation
| handle | Engine handle. |
| messages_json | JSON array of message objects. |
| on_token | Per-token callback (UTF-8 filtered). |
| user_data | Forwarded to on_token. |
| cancel_flag | Optional int*; non-zero cancels. |
Definition at line 2368 of file entropic.cpp.
| entropic_error_t entropic_run_streaming | ( | entropic_handle_t | handle, |
| const char * | input, | ||
| void(*)(const char *token, size_t len, void *user_data) | on_token, | ||
| void * | user_data, | ||
| int * | cancel_flag | ||
| ) |
Streaming generation — delegates entirely to engine.
Streaming agentic loop with token callback.
| handle | Engine handle returned by entropic_create. |
| input | User message to generate a response for. |
| on_token | Callback invoked for each generated token. |
| user_data | Opaque pointer passed back to the callback. |
| cancel_flag | Optional pointer; set *cancel_flag to non-zero from another thread to stop generation. |
Definition at line 2194 of file entropic.cpp.
| int64_t entropic_seconds_since_last_activity | ( | entropic_handle_t | handle | ) |
gh#35: idle-time accessor for host-side idle-exit policies.
Seconds since the engine last serviced a run (gh#35, v2.3.0).
@utility
Definition at line 1913 of file entropic.cpp.
| char * entropic_serialize_mcp_keys | ( | entropic_handle_t | handle | ) |
Serialize all identity key sets to JSON.
Definition at line 3552 of file entropic.cpp.
| entropic_error_t entropic_set_attempt_boundary_cb | ( | entropic_handle_t | handle, |
| ent_validation_attempt_boundary_cb | cb, | ||
| void * | user_data | ||
| ) |
Register attempt-boundary callback on the validator.
Register an attempt-boundary callback for the validator.
Definition at line 2460 of file entropic.cpp.
| entropic_error_t entropic_set_critique_callbacks | ( | entropic_handle_t | handle, |
| void(*)(void *user_data) | start_cb, | ||
| void(*)(void *user_data) | end_cb, | ||
| void * | user_data | ||
| ) |
Register critique start/end callbacks on the handle (gh#50, v2.1.12).
Register start/end callbacks for constitutional critique generation (gh#50, v2.1.12).
Saves the callback pair on the handle (the authoritative slot) and re-applies to the current ConstitutionalValidator if one is already constructed. Subsequent entropic_configure* calls rebuild the validator; the rewire_critique_callbacks helper re-applies this slot from the handle automatically.
| handle | Engine handle. |
| start_cb | Pre-critique callback (NULL to disable). |
| end_cb | Post-critique callback (NULL to disable). |
| user_data | Forwarded to both callbacks. |
Definition at line 2547 of file entropic.cpp.
| entropic_error_t entropic_set_delegation_callbacks | ( | entropic_handle_t | handle, |
| ent_delegation_start_cb | on_start, | ||
| ent_delegation_complete_cb | on_complete, | ||
| void * | user_data | ||
| ) |
Register delegation start/complete callbacks (gh#29, v2.1.5).
Register start/complete callbacks for delegations.
| handle | Engine handle. |
| on_start | Pre-delegation gate (nullable clears). |
| on_complete | Post-delegation result (nullable clears). |
| user_data | Forwarded to both callbacks. |
Definition at line 2481 of file entropic.cpp.
| entropic_error_t entropic_set_queue_observer | ( | entropic_handle_t | handle, |
| void(*)(const char *, size_t, void *) | observer, | ||
| void * | user_data | ||
| ) |
Register the queue-consumption observer.
Stores on the handle so pre-configure registration is preserved, then forwards to the engine if it exists. The engine member is the source of truth at fire time — set_callbacks() shuffles in the streaming path do not touch this slot.
Definition at line 2646 of file entropic.cpp.
| entropic_error_t entropic_set_residency_observer | ( | entropic_handle_t | handle, |
| entropic_residency_observer_t | observer, | ||
| void * | user_data | ||
| ) |
Register a residency observer on the orchestrator.
Register a residency observer on a handle.
Stores the C callback + user_data on the handle and bridges to the orchestrator's std::function slot via a small capture lambda. The orchestrator fires the lambda synchronously on each load / evict / activation_swap transition; the lambda forwards to the C callback with the residency-event enum, tier name, model path, and footprint.
Definition at line 4024 of file entropic.cpp.
| entropic_error_t entropic_set_state_observer | ( | entropic_handle_t | handle, |
| void(*)(int state, void *user_data) | observer, | ||
| void * | user_data | ||
| ) |
Register a state-change observer on the handle.
Register an engine state-change observer.
v2.1.10 (gh#40 fallout): routes through the engine's persistent state_observer slot rather than the legacy EngineCallbacks.on_state_change. The legacy path is wiped by run_streaming's set_callbacks() shuffle, which silently broke the documented external-MCP-bridge use case for streaming runs.
| handle | Engine handle. |
| observer | State observer (NULL to clear). |
| user_data | Forwarded to observer. |
Definition at line 2510 of file entropic.cpp.
| entropic_error_t entropic_set_stream_observer | ( | entropic_handle_t | handle, |
| void(*)(const char *token, size_t len, void *user_data) | observer, | ||
| void * | user_data | ||
| ) |
Set a global stream observer callback.
| handle | Engine handle. |
| observer | Token callback (NULL to clear). |
| user_data | Forwarded to observer. |
Definition at line 2398 of file entropic.cpp.
| entropic_error_t entropic_speculative_compat | ( | entropic_handle_t | handle, |
| int * | compatible, | ||
| char ** | diagnostic | ||
| ) |
Query speculative-decoding compatibility for the configured target/draft pair.
Query whether the configured target/draft pair is compatible for speculative decoding.
Delegates to ModelOrchestrator::check_speculative_compat(). The orchestrator owns both sides of the pairing (active main tier as target, "draft" role on the secondary loader as draft) and runs the architecture + tokenizer rules from entropic::speculative::check_compat.
| handle | Engine handle. |
| compatible | Required out-param: 1 when compatible. |
| diagnostic | Optional out-param: heap-allocated diagnostic string on incompatibility (NULL on compatible pair). Caller frees with entropic_free_string. |
Definition at line 3990 of file entropic.cpp.
| entropic_error_t entropic_state_load | ( | entropic_handle_t | handle, |
| const char * | tier_name, | ||
| const char * | path | ||
| ) |
Restore a tier's KV cache from a file (gh#23 v2.3.25).
Restore a tier's KV-cache state from a file (gh#23 MVP item 13).
Definition at line 2817 of file entropic.cpp.
| entropic_error_t entropic_state_save | ( | entropic_handle_t | handle, |
| const char * | tier_name, | ||
| const char * | path | ||
| ) |
Save a tier's KV cache to a file (gh#23 v2.3.25, MVP item 13).
Save a tier's KV-cache state to a file (gh#23 MVP item 13).
Definition at line 2761 of file entropic.cpp.
| void entropic_throughput_reset | ( | entropic_handle_t | handle, |
| const char * | model_path | ||
| ) |
Reset throughput tracking data.
Reset throughput tracking data for a model.
Clears all recorded samples. model_path is accepted for API compatibility but the orchestrator tracks a single global throughput.
| handle | Engine handle returned by entropic_create. |
| model_path | Path or registry key identifying the model whose throughput should be reset. |
Definition at line 3414 of file entropic.cpp.
| double entropic_throughput_tok_per_sec | ( | entropic_handle_t | handle, |
| const char * | model_path | ||
| ) |
Get EWMA throughput estimate in tokens per second.
Get current throughput estimate for a model.
Delegates to ThroughputTracker::tok_per_sec(). Returns the smoothed estimate from recent generations. model_path is accepted for API compatibility but the orchestrator tracks a single global throughput (one tracker, not per-model).
Definition at line 3386 of file entropic.cpp.
| entropic_error_t entropic_update_identity | ( | entropic_handle_t | handle, |
| const char * | name, | ||
| const char * | config_json | ||
| ) |
Update an existing dynamic identity.
Update a dynamic identity.
Definition at line 3625 of file entropic.cpp.
| entropic_error_t entropic_user_message_queue_depth | ( | entropic_handle_t | handle, |
| size_t * | count | ||
| ) |
Snapshot the mid-gen queue depth.
Query the current depth of the mid-gen user-message queue.
Definition at line 2612 of file entropic.cpp.
| entropic_error_t entropic_validation_accept_last | ( | entropic_handle_t | handle | ) |
Accept the last paused attempt as the final answer.
Finalize the last attempt as the turn's response.
Definition at line 2447 of file entropic.cpp.
| char * entropic_validation_last_result | ( | entropic_handle_t | handle | ) |
Get last validation result as JSON.
Get the last validation result as JSON.
Definition at line 3914 of file entropic.cpp.
| entropic_error_t entropic_validation_resume_retry | ( | entropic_handle_t | handle | ) |
Resume a paused constitutional revision pass.
Opt the engine into running the constitutional revision pass.
Definition at line 2434 of file entropic.cpp.
| entropic_error_t entropic_validation_set_auto_retry | ( | entropic_handle_t | handle, |
| int | enabled | ||
| ) |
Toggle automatic constitutional revision.
Toggle automatic constitutional revision after rejection.
Definition at line 2420 of file entropic.cpp.
| entropic_error_t entropic_validation_set_enabled | ( | entropic_handle_t | handle, |
| bool | enabled | ||
| ) |
Enable or disable constitutional validation globally.
Enable or disable constitutional validation.
Definition at line 3876 of file entropic.cpp.
| entropic_error_t entropic_validation_set_identity | ( | entropic_handle_t | handle, |
| const char * | identity_name, | ||
| bool | enabled | ||
| ) |
Set per-identity validation override.
Definition at line 3893 of file entropic.cpp.
| const char * entropic_version | ( | void | ) |
Get the library version string.
Definition at line 1894 of file entropic.cpp.
|
static |
Build formatted tool prompt for a tier.
gh#87 (v2.7.0): returns the per-tier-filtered tool defs as a structured MCP JSON array ([{name, description, inputSchema}, ...]), NOT an adapter-formatted prompt string. The defs flow into params.tools and common_chat renders them in the model's native format — so no adapter format_tools and no system-message string injection. The field's contract ("tool definitions for tier") is unchanged; only the payload shape evolved from formatted-prompt to structured-JSON.
| tier | Tier name. |
| result | Output: heap-allocated JSON-array string. Caller frees. |
| user_data | Engine handle. |
Definition at line 368 of file entropic.cpp.
|
static |
Filter tool definitions by allowed list.
| all_tools | Parsed JSON array of all tool definitions. |
| allowed | Allowed tool names (empty = no filter). |
Definition at line 336 of file entropic.cpp.
|
static |
Build the engine + inference interfaces (configure step 2).
Extracted from configure_common to keep it knots-clean. Creates the MCP-auth + identity managers, the per-handle orchestrator interface (gh#58), the AgentEngine, and rewires observers/interrupt/tools.
| h | Engine handle. |
| data_dir | Resolved data directory. |
Definition at line 1606 of file entropic.cpp.
|
static |
Initialize MCP servers with resolved working directory.
| h | Engine handle with config loaded. |
| data_dir | Bundled data directory path. |
Definition at line 782 of file entropic.cpp.
|
static |
Shared body of all entropic_configure* entry points.
Construct the orchestrator + grammar fallback for a handle.
Extracted from configure_common in v2.2.9 to keep SLOC under the knots gate after v2.2.6's per-handle InterfaceContext wiring grew the body past 50 lines.
Definition at line 1578 of file entropic.cpp.
|
static |
Initialize persistence: storage + session logger + StorageInterface.
Definition at line 722 of file entropic.cpp.
|
static |
Parse messages_json and check vision-tier availability (gh#37/gh#41).
Parses the wire-format messages array via the shared utility and, if any message carries image content_parts, verifies that the orchestrator has at least one tier whose capabilities includes "vision". Returns the parsed vector on success; throws on parse failure (caller catches and maps to ENTROPIC_ERROR_*).
| handle | Engine handle (already validated by caller). | |
| messages_json | Caller-provided JSON array string. | |
| [out] | out_rc | Set to ENTROPIC_OK on success, or to a specific error code (NO_VISION_TIER) when validation fails. |
Definition at line 2241 of file entropic.cpp.
|
static |
Register per-tier ChildContextInfo with the engine.
Extracted from configure_common to keep that function under the 50-SLOC quality gate. Iterates the configured tiers, resolves each identity file, and registers the assembled context with the engine.
| h | Engine handle (engine must be constructed). |
| data_dir | Resolved data directory for identity files. |
| shared_prefix | Prefix assembled from constitution + app context. @utility |
Definition at line 522 of file entropic.cpp.
|
static |
Load tier's KV cache from file body (gh#23 v2.3.25).
Read the entire contents of path into out_buf.
Definition at line 2785 of file entropic.cpp.
|
static |
Post-parse config setup: subsystem construction + wiring.
v2.1.10 (gh#40 + fallout): observer rewiring at engine construction is bundled into rewire_observers so pre-configure stream, queue, and state observers all survive engine construction AND the EngineCallbacks shuffle that run_streaming performs.
| h | Engine handle with config populated. |
Refuse a second configure on the same handle (gh#58).
Re-configure would leak raw pointers captured during the first pass into subsystems that already wired against the original orchestrator/engine/mcp_auth.
Definition at line 1556 of file entropic.cpp.
|
static |
Resolve tier name to an ACTIVE backend, or throw.
| h | Engine handle (must have orchestrator). |
| tier_name | Tier name string. |
| std::runtime_error | if tier not found or not active. |
Definition at line 213 of file entropic.cpp.
|
static |
Post-parse config setup: load bundled models, set configured.
| h | Engine handle. |
Pre-load bundled models from default locations.
Tries compile-time and source-tree data dirs before config is parsed, so registry keys resolve during config loading.
| h | Engine handle. |
Resolve allowed_tools list for a tier.
Checks identity config first, then model config fallback. Empty result means all tools are allowed (no filter).
| h | Engine handle. |
| tier | Tier name. |
Definition at line 310 of file entropic.cpp.
|
static |
Propagate pre-configure critique callbacks to a newly- constructed ConstitutionalValidator (gh#50, v2.1.12).
Same pattern as rewire_state_observer: the handle owns the authoritative slot; configure_common reconstructs the validator each call, so the rewire helper re-applies the consumer's registered callbacks after every (re)construction.
| h | Engine handle with validator just constructed (or NULL). @utility |
Definition at line 482 of file entropic.cpp.
|
static |
Re-bind every pre-configure observer to the new engine.
Aggregates the three rewire helpers so configure_common stays under the SLOC ceiling. (gh#40 fallout, v2.1.10)
| h | Engine handle with engine just constructed. @utility |
Definition at line 502 of file entropic.cpp.
|
static |
Propagate any pre-configure queue observer to the new engine.
Sibling of rewire_stream_observer for the mid-gen queue consumption callback (gh#40, v2.1.10). Re-binds the handle-stored observer when the AgentEngine is constructed so observers never miss queue-consumption events on a late-bound engine.
| h | Engine handle with engine just constructed. @utility |
Definition at line 443 of file entropic.cpp.
|
static |
Propagate any pre-configure state observer to the new engine.
gh#40 fallout (v2.1.10): pre-existing behavior wired the observer via engine->set_callbacks(), which is wiped by run_streaming. Re-bind through the persistent slot so pre-configure registrations survive engine construction AND streaming runs.
| h | Engine handle with engine just constructed. @utility |
Definition at line 462 of file entropic.cpp.
|
static |
Propagate any pre-configure stream observer to the new engine.
Handles the edge case where a caller registers a stream observer before entropic_configure() — the handle stores it on arrival, and this helper re-binds it when the AgentEngine is constructed so observers never miss tokens on a late-bound engine. (P0-1)
| h | Engine handle with engine just constructed. @utility |
Definition at line 424 of file entropic.cpp.
|
static |
Run + serialize for entropic_run_as (gh#99).
Extracted so entropic_run_as stays within the knots returns gate. @utility
Definition at line 2002 of file entropic.cpp.
|
static |
Blocking multimodal run (gh#37, v2.1.8).
Inner blocking-run dispatch — no front validation (gh#37).
Caller has already verified handle, args, and engine pointer. Parses messages, runs the multimodal vision check, dispatches the turn, serializes the result, and fires the synthetic stream-observer completion sentinel. Returns the canonical entropic_error_t status — single exit.
Definition at line 2273 of file entropic.cpp.
|
static |
Streaming multimodal run (gh#37, v2.1.8).
Inner streaming dispatch — no front validation (gh#37).
Definition at line 2333 of file entropic.cpp.
|
static |
Serialize batch results to a JSON array string (gh#98).
| results | Per-request generation results. |
Definition at line 2074 of file entropic.cpp.
|
static |
StorageInterface bridge: complete_delegation trampoline.
@callback
Definition at line 605 of file entropic.cpp.
|
static |
StorageInterface bridge: create_conversation trampoline.
Forwards AgentEngine::run's root-conversation creation to the SqliteStorageBackend. Pre-v2.1.12 (gh#48) the interface had no create_conversation callback, so the root conversation row was never inserted and every subsequent delegation's FK to conversations(id) failed silently against the empty parent id.
@callback
Definition at line 590 of file entropic.cpp.
|
static |
Initialize persistence: storage + session logger.
| h | Engine handle with config.log_dir set. |
StorageInterface bridge: create_delegation trampoline.
Translates the engine's StorageInterface callback into a call against SqliteStorageBackend::create_delegation. gh#32 (v2.1.6) closes a pre-existing wiring gap: the engine declared the interface but the facade never populated it, so per-delegation storage records were silently dropped. This is the bridge that finally connects them.
@callback
Definition at line 563 of file entropic.cpp.
|
static |
StorageInterface bridge: load_delegation_with_messages.
Resolves delegation id → child_conversation_id → conversation messages, then returns the composed JSON with target_tier and messages at the top level. Used by entropic.resume_delegation (gh#32, v2.1.6).
@callback
Definition at line 658 of file entropic.cpp.
|
static |
StorageInterface bridge: save_conversation trampoline.
@callback
Definition at line 621 of file entropic.cpp.
|
static |
StorageInterface bridge: save_snapshot trampoline.
@callback
Definition at line 637 of file entropic.cpp.
|
static |
|
static |
|
static |
State provider: get_history — conversation context snapshot.
@callback
Returns the current conversation as a JSON array of {role, content_preview, token_count_est} objects, suitable for context_inspect MCP tool and inspect –target history. (P2-16)
Content previews are truncated at 200 bytes on a UTF-8 codepoint boundary via entropic::facade::utf8_safe_substr — byte-indexed truncation would slice multi-byte codepoints and cause arr.dump() below to throw nlohmann::json::type_error.316 (gh#56).
| max_entries | Maximum messages to return (0 = all). |
| ud | Engine handle. |
Definition at line 1256 of file entropic.cpp.
|
static |
State provider: get_identities.
Returns an array of objects per tier: [{"name":"lead","assembled_prompt":"…"}, ...]
The assembled_prompt is the static system prompt the engine would send for that tier (constitution + app_context + identity body + tool defs), excluding per-turn runtime augmentations. Demo ask #3: lets entropic.inspect identity <tier> return what the model actually sees, without running inference. (v2.1.0)
@callback
Definition at line 1214 of file entropic.cpp.
|
static |
State provider: get_metrics.
Returns LoopMetrics from the most recent run plus a per-tier accumulator as JSON. Flat fields: iterations, tool_calls, tokens_used, errors, duration_ms (all zero before any run). The per_tier object maps tier name → metrics since engine start. (P2-15 + follow-up)
@callback
Definition at line 1342 of file entropic.cpp.
|
static |
State provider: get_residency — VRAM residency snapshot.
@callback
Backs the engine's introspection surface for "what models are
loaded right now". Mirrors the C ABI entropic_residency_snapshot JSON schema. Returns an empty residency object when the orchestrator is not yet constructed (pre-configure). (gh#57)
| ud | Engine handle. |
Definition at line 1293 of file entropic.cpp.
|
static |
State provider: get_state (runtime environment).
@callback
Definition at line 1308 of file entropic.cpp.
|
static |
|
static |
Return the validator's last verdict as JSON for ON_COMPLETE.
Shape: {ran, verdict, violations[], revisions_applied}. Verdict is a string from {passed, revised, rejected_reverted_length, rejected_max_revisions}. Returns malloc'd buffer; engine frees. (E3, 2.0.6-rc17)
| ud | entropic_engine handle. |
Definition at line 1041 of file entropic.cpp.
|
static |
State provider: load_delegation_conversation (gh#32, v2.1.6).
Delegates to the engine-facing StorageInterface bridge so both surfaces stay in lockstep.
@callback
Definition at line 1409 of file entropic.cpp.
|
static |
State provider: search_delegations (gh#32, v2.1.6).
Substring-search past delegation result summaries via the SQLite storage backend. Returns NULL if no storage is configured.
@callback
Definition at line 1387 of file entropic.cpp.
|
static |
Start the external MCP bridge if enabled in config.
Creates an ExternalBridge listening on a unix domain socket so external MCP clients (Claude Code, etc.) can talk to the running engine without spawning a separate process.
| h | Engine handle (must be fully configured). |
Definition at line 1520 of file entropic.cpp.
|
static |
Cache per-tier frontmatter fields (allowed_tools, validation_rules, relay).
| h | Engine handle with config + engine constructed. |
| data_dir | Bundled data directory. |
Thread frontmatter sampler optionals into a tier config.
gh#82/gh#85: each knob copies only when the frontmatter set it, so the orchestrator's per-tier resolution can apply it as the tier baseline. Extracted from apply_identity_frontmatter to keep that function under the cognitive-complexity gate.
| tc | Tier config (mutated). |
| fm | Parsed identity frontmatter. @utility |
Definition at line 838 of file entropic.cpp.
|
static |
Thread per-tier frontmatter SAMPLERS into config pre-orchestrator.
gh#94 (v2.7.3): the orchestrator snapshots h->config BY VALUE in init_orchestrator() (config_ = config). The engine-bound frontmatter wiring (cache_tier_allowed_tools → apply_identity_frontmatter) necessarily runs LATER, after the engine exists. Threading sampler knobs there left them in h->config but never in the orchestrator's frozen copy, so every tier silently ran GenerationParams defaults regardless of frontmatter. This pass threads ONLY the dependency-free sampler knobs into each tier BEFORE init_orchestrator, so the snapshot carries them. The engine-dependent wiring (allowed_tools, relay_single_delegate, tool_executor) stays in wire_prompts_and_persistence.
| h | Engine handle (config tiers mutated in place). |
| data_dir | Bundled data directory (identity file resolution). |
Definition at line 948 of file entropic.cpp.
|
static |
Wire the ToolExecutor and attach it to the engine.
| h | Engine handle with engine + server_manager constructed. |
C-safe accessor for ToolExecutor's history (P1-11).
Extracted to satisfy the 3-return complexity gate.
| count | Max entries to serialize. |
| ud | ToolExecutor pointer. |
Definition at line 985 of file entropic.cpp.
|
static |
Wire engine interrupt propagation into MCP transports (P1-10).
Extracted from configure_common to keep that function under the 50-SLOC quality gate. On first interrupt(), the lambda calls ServerManager::interrupt_external_tools() which trips the cancel flag in every StdioTransport so in-flight reads return within ~100ms.
| h | Engine handle with engine and server_manager constructed. @utility |
Definition at line 404 of file entropic.cpp.
|
static |
Wire hook dispatch and attach the constitutional validator.
Bridges the handle's HookRegistry to the engine's HookInterface (function-pointer indirection required by the .so boundary). If constitutional validation is enabled and constitution text was loaded, constructs and attaches the validator as a POST_GENERATE hook.
| h | Engine handle with engine constructed. |
| iface | Inference interface (passed to validator for critique generation). |
| constitution_text | Constitution text (may be empty). |
Definition at line 1099 of file entropic.cpp.
|
static |
Assemble prompts + wire validation/persistence (config step 3).
Extracted from configure_common to keep it knots-clean.
| h | Engine handle. |
| data_dir | Resolved data directory. |
Definition at line 1654 of file entropic.cpp.
|
static |
Wire state provider to the EntropicServer.
v2.2.4 (gh#57): registers the additional get_residency callback so the engine's introspection surface reflects the current VRAM residency set alongside config/identities/tools/history/metrics.
| h | Engine handle with all subsystems constructed. |
Definition at line 1434 of file entropic.cpp.
|
static |
Pass per-identity validation rules to the validator.
| h | Engine handle with validator + tier_validation_rules populated. |
Definition at line 1464 of file entropic.cpp.
|
static |
Wire the ToolExecutor and attach it to the engine.
Constructs the ToolExecutor from existing subsystems, builds the ToolExecutionInterface bridge (process_tool_calls + history_json thunk), and registers it with the AgentEngine.
| h | Engine handle with engine + server_manager constructed. |
Definition at line 1009 of file entropic.cpp.
|
static |
Definition at line 134 of file entropic.cpp.
|
static |
Definition at line 42 of file entropic.cpp.
|
static |
Definition at line 135 of file entropic.cpp.