include/entropic/entropic.h

← API

include/entropic/entropic.h

Functions

ENTROPIC_EXPORT entropic_error_t entropic_create(entropic_handle_t *handle)

Create a new engine instance.

Allocates and initializes an engine handle. The engine is idle until entropic_configure() is called.

Parameters
  • handle out — Pointer to receive the new handle. Set to NULL on failure.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_ARGUMENT — handle is NULL. ENTROPIC_ERROR_OUT_OF_MEMORY — allocation failed.
threadsafety
Single-threaded init/destroy.

ENTROPIC_EXPORT entropic_error_t entropic_configure(entropic_handle_t handle, const char *config_json)

Configure the engine from a JSON config string.

Parses the JSON, validates against the config schema, resolves model paths, and prepares the engine for operation. Does NOT load models (that happens on first generate or explicit activate). JSON is used at the C API boundary because it's universal — any language can produce it. Config FILES are YAML (parsed by ryml inside librentropic-config.so). Use entropic_configure_from_file() to load YAML config files directly without manual JSON conversion.

Parameters
  • handle — Engine handle.
  • config_json — JSON string with engine configuration.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — config_json is NULL. ENTROPIC_ERROR_INVALID_CONFIG — config validation failed.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_configure_from_file(entropic_handle_t handle, const char *config_path)

Configure engine from a YAML or JSON config file.

Convenience wrapper that reads the file, parses it (YAML via ryml or JSON via nlohmann/json based on extension), and applies the configuration.

Parameters
  • handle — Engine handle.
  • config_path — Path to YAML (.yaml/.yml) or JSON (.json) config file.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — config_path is NULL. ENTROPIC_ERROR_INVALID_CONFIG — config validation failed. ENTROPIC_ERROR_IO — file not found or unreadable.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_configure_dir(entropic_handle_t handle, const char *project_dir)

Configure engine using layered config resolution.

Loads configuration in priority order (highest wins): Compiled defaults Bundled default (data/default_config.yaml) Global config (~/.entropic/config.yaml) Project config ({project_dir}/config.local.yaml) Environment variables (ENTROPIC_*) This is the recommended configuration path for most consumers. The project_dir also sets the working directory for log files and session state (e.g., ".hello-world", ".entropic").

Parameters
  • handle — Engine handle.
  • project_dir — Project config directory (null-terminated). Contains config.local.yaml and receives session logs. Pass NULL or "" to use only global + bundled defaults.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_CONFIG — config validation failed.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT void entropic_destroy(entropic_handle_t handle)

Destroy an engine instance and free all resources.

Unloads models, closes storage, destroys all child objects. After this call, the handle is invalid. Passing NULL is a no-op.

Parameters
  • handle — Engine handle to destroy (NULL-safe).
threadsafety
Single-threaded init/destroy. Must not race with any other call on the same handle.

ENTROPIC_EXPORT const char * entropic_version(void)

Get the library version string.

Returns the full semver string (e.g., "1.8.9"). The pointer has static lifetime — valid for the entire process.

Returns
  • Static null-terminated version string. Never NULL. Do NOT free.
  • Static version string.
threadsafety
Thread-safe.

ENTROPIC_EXPORT int entropic_api_version(void)

Get the C API version number.

Returns an integer starting at 1. Incremented on breaking changes: signature changes, function removals, enum renumbering, or behavior changes. Adding new functions does NOT increment this value. Compare with ENTROPIC_API_VERSION at compile time for version checks.

Returns
API version integer.
threadsafety
Thread-safe.

ENTROPIC_EXPORT int64_t entropic_seconds_since_last_activity(entropic_handle_t handle)

Seconds since the engine last serviced a run (gh#35, v2.3.0).

Returns the wall-clock seconds delta between now and the entry time of the most recent entropic_run* call on this handle. Returns 0 when no run has ever happened on this handle (no activity to be idle relative to). Intended for host-side idle-exit policies: a headless entropic serve or sassafras-class consumer process can poll this at its own cadence and call entropic_destroy once the engine has been idle for longer than the host's configured threshold. The engine itself does NOT auto-exit — that's a host policy decision.

Parameters
  • handle — Engine handle. May be NULL.
Returns
  • Seconds idle, or 0 if handle is NULL / no activity yet.
  • Seconds since the most recent run on this handle; 0 when the handle is NULL or no run has happened yet.
threadsafety
Thread-safe.

ENTROPIC_EXPORT void * entropic_alloc(size_t size)

Allocate memory using the engine's allocator.

All cross-boundary allocations (hook modified_json, consumer-provided strings that the engine will free) MUST use this function. Paired with entropic_free().

Parameters
  • size — Number of bytes to allocate.
Returns
Pointer to allocated memory, or NULL on failure.
threadsafety
Thread-safe.

ENTROPIC_EXPORT void entropic_free(void *ptr)

Free memory allocated by the engine or entropic_alloc().

All char* return values that transfer ownership MUST be freed with this function. Passing NULL is a no-op.

Parameters
  • ptr — Pointer to free (from engine return value or entropic_alloc).
  • ptr — Pointer to free; NULL is a safe no-op.
threadsafety
Thread-safe.

ENTROPIC_EXPORT entropic_error_t entropic_run(entropic_handle_t handle, const char *input, char **result_json)

Synchronous agentic loop.

Runs the full agentic loop: generate, parse tool calls, execute tools, re-generate until complete. Blocks until the loop finishes or is interrupted via entropic_interrupt().

Parameters
  • handle — Engine handle.
  • input — User message (null-terminated).
  • result_json out — JSON result string. Caller must free with entropic_free().
  • 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).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — engine not configured. ENTROPIC_ERROR_GENERATE_FAILED — inference error. ENTROPIC_ERROR_ALREADY_RUNNING — another run in progress. ENTROPIC_ERROR_INTERRUPTED — cancelled via entropic_interrupt(). ENTROPIC_ERROR_TURN_FAILED — the turn ran but the engine failed it (v2.14.5, gh#209/gh#212): explicit-completion retries exhausted, or the prompt does not fit the tier. The conversation is still delivered (result_json, or the session context for the streaming entry points); entropic_last_error() says why. Text in it is NOT an answer the turn confirmed. This applies to every run entry point that drives the agent loop, including the _as, _session and _messages variants.
  • ENTROPIC_OK on success, error code otherwise.
threadsafety
NOT serialized. gh#109 removed api_mutex from every run entry point so a long turn cannot block entropic_interrupt() from another thread; the pre-2.12.0 claim that this call was "serialized per-handle" was stale from that moment and is what led a consumer to build on a guarantee that did not exist (gh#144). As of 2.12.0 a run entered while another is in flight on the same handle returns ENTROPIC_ERROR_ALREADY_RUNNING rather than racing. Callers wanting to QUEUE rather than be refused must serialize above this layer, as the external MCP bridge does.

ENTROPIC_EXPORT entropic_error_t entropic_run_as(entropic_handle_t handle, const char *tier_or_identity, const char *input, char **result_json)

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 without loading a second model or reconfiguring the handle — so one process can interleave agent kinds (e.g. an "npc" verb-grammar tier and a "companion" free-text tier) on a single resident model. Identical result contract to entropic_run().

Parameters
  • handle — Engine handle.
  • tier_or_identity — Tier name to run this call under (null-terminated).
  • input — User message (null-terminated).
  • result_json out — JSON result string. Caller must free with entropic_free().
  • 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).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — NULL tier/input/result_json. ENTROPIC_ERROR_INVALID_STATE — engine not configured. ENTROPIC_ERROR_IDENTITY_NOT_FOUND — unknown tier name. ENTROPIC_ERROR_GENERATE_FAILED — inference error.
  • ENTROPIC_OK on success; ENTROPIC_ERROR_IDENTITY_NOT_FOUND for an unknown tier; other error codes per entropic_run().
threadsafety
NOT serialized. gh#109 removed api_mutex from every run entry point so a long turn cannot block entropic_interrupt() from another thread; the pre-2.12.0 claim that this call was "serialized per-handle" was stale from that moment and is what led a consumer to build on a guarantee that did not exist (gh#144). As of 2.12.0 a run entered while another is in flight on the same handle returns ENTROPIC_ERROR_ALREADY_RUNNING rather than racing. Callers wanting to QUEUE rather than be refused must serialize above this layer, as the external MCP bridge does.

ENTROPIC_EXPORT 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 requests that share a large prompt prefix (e.g. game agents per tick: a shared constitution/context + a short per-agent suffix) together — the shared prefix is prefilled once and fanned out, each request sampled under its tier's grammar. These are one-shot generations (no agentic tool loop). On a plain-KV model with a real shared prefix and enough sequence slots (configure n_parallel >= n) the batch fast-path engages; otherwise each request runs serially (correct, just without the prefill win).

Parameters
  • handle — Engine handle.
  • tiers — Array of N tier names; an entry may be NULL for the default tier. May be NULL to use the default tier for all.
  • prompts — Array of N user prompt strings (null-terminated).
  • n — Number of requests.
  • result_json out — JSON array of N objects {"content","finish_reason","tool_calls"}, in input order. Caller must free with entropic_free().
  • tiers — C array of N tier names (entries may be NULL → default tier).
  • prompts — C array of N user prompts.
  • n — Request count.
  • result_json out — JSON array of N {content, finish_reason, tool_calls}. Caller frees with entropic_free().
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_ARGUMENT — NULL prompts/result_json or n==0. ENTROPIC_ERROR_INVALID_STATE — engine not configured. ENTROPIC_ERROR_GENERATE_FAILED — inference error.
  • ENTROPIC_OK on success; error codes per entropic_run().
threadsafety
NOT serialized. gh#109 removed api_mutex from every run entry point so a long turn cannot block entropic_interrupt() from another thread; the pre-2.12.0 claim that this call was "serialized per-handle" was stale from that moment and is what led a consumer to build on a guarantee that did not exist (gh#144). As of 2.12.0 a run entered while another is in flight on the same handle returns ENTROPIC_ERROR_ALREADY_RUNNING rather than racing. Callers wanting to QUEUE rather than be refused must serialize above this layer, as the external MCP bridge does.

ENTROPIC_EXPORT 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 agentic loop with token callback.

Same as entropic_run() but invokes on_token for each generated token. The token pointer is valid only for the callback duration — copy if retention is needed.

Parameters
  • handle — Engine handle.
  • input — User message (null-terminated).
  • on_token — Called for each generated token. Must not call back into the entropic API (deadlock risk).
  • user_data — Forwarded to on_token.
  • cancel_flag — Pointer to int. Set to non-zero to cancel. May be NULL.
  • 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.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — engine not configured. ENTROPIC_ERROR_GENERATE_FAILED — inference error. ENTROPIC_ERROR_ALREADY_RUNNING — another run in progress. ENTROPIC_ERROR_CANCELLED — cancelled via cancel_flag. ENTROPIC_ERROR_INTERRUPTED — cancelled via entropic_interrupt(). ENTROPIC_ERROR_TURN_FAILED — the turn ran but the engine failed it (v2.14.5, gh#209/gh#212): explicit-completion retries exhausted, or the prompt does not fit the tier. The conversation is still delivered (result_json, or the session context for the streaming entry points); entropic_last_error() says why. Text in it is NOT an answer the turn confirmed. This applies to every run entry point that drives the agent loop, including the _as, _session and _messages variants.
threadsafety
NOT serialized. gh#109 removed api_mutex from every run entry point so a long turn cannot block entropic_interrupt() from another thread; the pre-2.12.0 claim that this call was "serialized per-handle" was stale from that moment and is what led a consumer to build on a guarantee that did not exist (gh#144). As of 2.12.0 a run entered while another is in flight on the same handle returns ENTROPIC_ERROR_ALREADY_RUNNING rather than racing. Callers wanting to QUEUE rather than be refused must serialize above this layer, as the external MCP bridge does.

ENTROPIC_EXPORT entropic_error_t entropic_run_messages(entropic_handle_t handle, const char *messages_json, char **result_json)

Multimodal-aware agentic run with messages-array input (gh#37).

Identical contract to entropic_run() except the input is a JSON array of message objects (OpenAI-compatible content arrays). Each message may carry content as a string OR as an array of content parts ({"type":"text","text":...} or {"type":"image","path":...,"url":...}). Image content parts survive end-to-end into the inference backend. The existing entropic_run() entry point is preserved unchanged for back-compat; consumers that don't need multimodal input keep using it (no JSON serialize/parse on their fast path). Routing: when any message carries an image part, the orchestrator routes to a tier whose capabilities includes vision. If no such tier is configured, ENTROPIC_ERROR_NO_VISION_TIER is returned with diagnostics identifying the active tier and any vision-capable tiers (if any).

Parameters
  • handle — Engine handle.
  • messages_json — JSON array of message objects (UTF-8, null-terminated).
  • result_json — Out-param: newly allocated JSON result string. Caller frees with entropic_free().
  • messages_json — JSON array of message objects.
  • result_json — Out-param: malloc'd JSON result. Caller frees.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — messages_json / result_json is NULL or malformed. ENTROPIC_ERROR_INVALID_STATE — engine not configured. ENTROPIC_ERROR_NO_VISION_TIER — image content but no vision-capable tier configured (gh#41). ENTROPIC_ERROR_GENERATE_FAILED — inference error.
  • ENTROPIC_OK or one of the documented error codes.
threadsafety
NOT serialized. gh#109 removed api_mutex from every run entry point so a long turn cannot block entropic_interrupt() from another thread; the pre-2.12.0 claim that this call was "serialized per-handle" was stale from that moment and is what led a consumer to build on a guarantee that did not exist (gh#144). As of 2.12.0 a run entered while another is in flight on the same handle returns ENTROPIC_ERROR_ALREADY_RUNNING rather than racing. Callers wanting to QUEUE rather than be refused must serialize above this layer, as the external MCP bridge does.

ENTROPIC_EXPORT 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 variant of entropic_run_messages (gh#37).

Same multimodal input contract as entropic_run_messages, with per-token streaming through on_token. The first token may be delayed by vision-encoder latency when image content is present.

Parameters
  • handle — Engine handle.
  • messages_json — JSON array of message objects.
  • on_token — Per-token callback. Must not call back into API.
  • user_data — Forwarded to on_token.
  • cancel_flag — Optional int* set to non-zero to cancel.
  • on_token — Per-token callback (UTF-8 filtered).
  • cancel_flag — Optional int*; non-zero cancels.
Returns
  • ENTROPIC_OK on success. See entropic_run_messages() for error codes.
  • ENTROPIC_OK or one of the documented error codes.
threadsafety
NOT serialized. gh#109 removed api_mutex from every run entry point so a long turn cannot block entropic_interrupt() from another thread; the pre-2.12.0 claim that this call was "serialized per-handle" was stale from that moment and is what led a consumer to build on a guarantee that did not exist (gh#144). As of 2.12.0 a run entered while another is in flight on the same handle returns ENTROPIC_ERROR_ALREADY_RUNNING rather than racing. Callers wanting to QUEUE rather than be refused must serialize above this layer, as the external MCP bridge does.

ENTROPIC_EXPORT 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.

Fires for every token generated from every entry point — interactive entropic_run_streaming(), non-streaming entropic_run(), and delegate child-loop generations. Runs alongside any per-call on_token callback registered via entropic_run_streaming(). Registration before entropic_configure() is allowed — the observer is wired to the engine when it is constructed. At the end of any entropic_run() or entropic_run_streaming() call, the observer is invoked once with (token="", len=0) as a synthetic completion sentinel so consumers can detect end-of-turn regardless of the entry point. Use case: TUI consumers register this once to observe activity from both interactive input and external MCP bridge requests.

Parameters
  • handle — Engine handle.
  • observer — Token callback (same signature as on_token). NULL to clear.
  • user_data — Forwarded to observer.
  • observer — Token callback (NULL to clear).
Returns
ENTROPIC_OK on success.
threadsafety
The observer may be invoked from the engine thread servicing the current run (serialized per-handle) and from the external-bridge worker thread that drives async MCP ask tasks. Consumer callbacks must be thread-safe.

ENTROPIC_EXPORT entropic_error_t entropic_set_state_observer(entropic_handle_t handle, void(*observer)(int state, void *user_data), void *user_data)

Register an engine state-change observer.

Fires on every AgentState transition. State integers map 1:1 to entropic_agent_state_t. Used by async subscribers (e.g. the external MCP bridge) to project engine-side phases — PLANNING, EXECUTING, WAITING_TOOL, VERIFYING, DELEGATING — onto user-visible task status. Pass observer=NULL to clear.

Parameters
  • handle — Engine handle.
  • observer — State-change callback (state_int, user_data).
  • user_data — Forwarded to observer.
  • observer — State observer (NULL to clear).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
threadsafety
Callback fires on whichever thread is running the turn — a delegated child loop runs INLINE on its parent's thread, there is no separate delegation thread — and with concurrent_sessions on (the v2.13.0 default) several run threads can fire it at once. Must be thread-safe.

ENTROPIC_EXPORT 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 start/end callbacks for constitutional critique generation (gh#50, v2.1.12).

The constitutional validator's critique pass typically runs for 20-30 seconds while AgentState stays parked at EXECUTING (no transition signals it). Consumers that want a "validating response…" UI indicator can register these callbacks to bracket that window precisely. start_cb fires immediately before the synchronous inference_->generate() call inside run_critique(); end_cb fires immediately after it returns (regardless of success or failure). Both fire even when the critique pass produces no violations. The slot is independent of the legacy EngineCallbacks struct — it survives entropic_run_streaming's internal callback shuffle and any entropic_configure* reconstruction (the handle owns the authoritative slot and re-applies it to each newly-built validator). Pass NULL for either callback to opt out of just that edge; pass NULL for both to clear the slot.

Parameters
  • 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 verbatim.
  • user_data — Forwarded to both callbacks.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
threadsafety
Thread-safe. Callbacks may be reassigned at any time; the validator snapshots the slot under a mutex before each fire so an in-flight critique cannot tear a partial reassignment.

ENTROPIC_EXPORT entropic_error_t entropic_interrupt(entropic_handle_t handle)

Interrupt a running generation.

Signals the engine to abort the current entropic_run() or entropic_run_streaming() call. The interrupted call returns ENTROPIC_ERROR_INTERRUPTED. If nothing is running, returns ENTROPIC_ERROR_NOT_RUNNING.

Parameters
  • handle — Engine handle.
  • handle — Engine handle returned by entropic_create.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_NOT_RUNNING — nothing to interrupt.
  • ENTROPIC_OK if interrupted.
threadsafety
Thread-safe. Designed for cross-thread cancellation.

ENTROPIC_EXPORT entropic_error_t entropic_interrupt_session(entropic_handle_t handle, const char *session_key)

Interrupt the run belonging to ONE session (gh#158, v2.13.0).

entropic_interrupt() means "every run on this handle" and keeps that meaning. This means "that one": with concurrent_sessions: true a handle may have several turns in flight, and a host that cancels one client's request must not abort the others. Deliberately does NOT trip the external-transport interrupt latch, which ServerManager::interrupt_external_tools() applies to EVERY transport at once — using it here would abort another session's in-flight MCP call and hand that session an empty result it cannot tell from a real one, which is the defect gh#150 was filed for. The interrupted run's own tool call still aborts, because the run publishes its cancel token to its own thread and the transport polls it per request. Added as a NEW NAMED FUNCTION rather than by changing entropic_interrupt's signature, per REQ-ABI-001. Additive, so ENTROPIC_API_VERSION does NOT move.

Parameters
  • handle — Engine handle.
  • session_key — Session whose run to interrupt; NULL or "" = default.
  • session_key — Session whose run to interrupt; NULL = default.
Returns
  • ENTROPIC_OK when a run was found and flagged. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — handle is not configured. ENTROPIC_ERROR_NOT_RUNNING — that session has no run in flight.
  • ENTROPIC_OK, or NOT_RUNNING when that session has no run.
threadsafety
Thread-safe. Designed for cross-thread cancellation.

ENTROPIC_EXPORT entropic_error_t entropic_queue_user_message(entropic_handle_t handle, const char *message)

Queue a user message to be injected at the next top-level turn boundary.

The queued message is appended to a bounded FIFO inside the engine and consumed automatically when the current top-level turn reaches AgentState::COMPLETE — i.e. when the currently-running entropic_run / entropic_run_streaming / entropic_run_messages* call finishes its agent loop. The engine then immediately seeds a fresh turn with the dequeued message under the same per-call on_token wiring, so streaming consumers see a clean per-turn token stream without protocol changes. The queue is NOT a cancellation primitive: it does not interrupt the in-flight turn. Consumers wanting to stop the current turn should use entropic_interrupt. The queue drain triggers only at top-level COMPLETE. Delegation boundaries (parent loop resuming after a child loop returns) are NOT drain points — injecting a fresh user message there would corrupt the parent's reasoning context.

Parameters
  • handle — Engine handle.
  • message — Null-terminated UTF-8 user input text.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — message is NULL. ENTROPIC_ERROR_INVALID_STATE — no run is currently in flight on this handle (just call entropic_run_streaming directly). ENTROPIC_ERROR_QUEUE_FULL — queue is at message_queue_capacity (default 8). Retry after a turn completes, or call entropic_clear_user_message_queue.
  • ENTROPIC_OK on success; INVALID_HANDLE for a NULL handle, INVALID_ARGUMENT for a NULL message, INVALID_STATE when no run is in flight, QUEUE_FULL when the bounded queue is at capacity.
threadsafety
Thread-safe. Designed to be called from a different thread than the one running the agent loop. 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.

ENTROPIC_EXPORT entropic_error_t entropic_user_message_queue_depth(entropic_handle_t handle, size_t *count)

Query the current depth of the mid-gen user-message queue.

Snapshot value — may be stale by the time the caller reads it if the engine consumes a message concurrently. Intended for consumer UI feedback ("3 queued"), not for synchronization.

Parameters
  • handle — Engine handle.
  • count — Out-param: receives the queue depth.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — count is NULL.
  • ENTROPIC_OK on success (depth 0 when the engine is not built), INVALID_HANDLE for a NULL handle, INVALID_ARGUMENT for a NULL count.
threadsafety
Thread-safe. Query the current depth of the mid-gen user-message queue.

ENTROPIC_EXPORT entropic_error_t entropic_clear_user_message_queue(entropic_handle_t handle)

Drop all queued user messages.

Consumer-initiated retract. Does NOT affect the in-flight turn — only the not-yet-consumed pending messages are discarded.

Parameters
  • handle — Engine handle.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK on success (a benign no-op before configure), ENTROPIC_ERROR_INVALID_HANDLE when handle is NULL.
threadsafety
Thread-safe. Drop all queued user messages.

ENTROPIC_EXPORT entropic_error_t entropic_set_queue_observer(entropic_handle_t handle, void(*observer)(const char *consumed, size_t remaining, void *user_data), void *user_data)

Register an observer for queue-consumption events.

Fires immediately before the engine seeds the next turn with a popped queued message. Lets consumer UIs clear the "queued" badge for the corresponding scrollback item. The consumed buffer is valid only for the callback's duration — copy it if the consumer needs to hold it. remaining reflects the queue depth after the pop (i.e. messages still waiting). Pass observer=NULL to clear.

Parameters
  • handle — Engine handle.
  • observer — Callback (consumed_text, remaining_depth, user_data).
  • user_data — Forwarded to observer.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
threadsafety
Callback fires from the engine thread between turns. Must be thread-safe.

ENTROPIC_EXPORT entropic_error_t entropic_speculative_compat(entropic_handle_t handle, int *compatible, char **diagnostic)

Query whether the configured target/draft pair is compatible for speculative decoding.

Inspects the active main tier (verifier) and the configured draft model (inference.speculative.draft_model) for: target architecture is NOT recurrent (Mamba/RWKV/hybrid) matching tokenizer vocab type, BOS/EOS, vocab size prefix-equal token texts in the overlap range No model state is allocated for the query — purely metadata-level inspection on the already-loaded models. The check is exposed as a separate entrypoint (rather than only at generate time) so consumers can validate a planned pairing during configuration and surface a clear diagnostic before kicking off a turn. 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.

Parameters
  • handle — Engine handle.
  • compatible out — 1 if the pair is compatible, 0 otherwise. Required (must be non-NULL).
  • diagnostic out — On *compatible == 0, a heap-allocated NUL-terminated string identifying the failed rule. On compatible pairs, set to NULL. Caller frees with entropic_free_string. May be NULL if the caller does not want the diagnostic text.
  • 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.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle/compatible is NULL. ENTROPIC_ERROR_INVALID_STATE — engine not configured.
  • ENTROPIC_OK / ENTROPIC_ERROR_INVALID_HANDLE / ENTROPIC_ERROR_INVALID_STATE.

ENTROPIC_EXPORT entropic_error_t entropic_set_residency_observer(entropic_handle_t handle, entropic_residency_observer_t observer, void *user_data)

Register a residency observer on a handle.

Only one observer per handle. Passing observer=NULL clears it. Surface for consumer UIs (Models tabs, dashboards) to track which tier models are currently in VRAM without polling entropic_residency_snapshot. 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.

Parameters
  • handle — Engine handle.
  • observer — Callback, or NULL to clear.
  • user_data — Forwarded to observer.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_INVALID_HANDLE when handle is NULL.

ENTROPIC_EXPORT entropic_error_t entropic_residency_snapshot(entropic_handle_t handle, char **out_json)

Snapshot of the engine's current VRAM residency set.

Returns a JSON object describing every tier-backing model currently resident in VRAM, the engine's VRAM budget, and per-model footprint accounting. Suitable for consumer Models-tab "what is loaded right now" widgets. JSON shape: { "vram_total_bytes":17179869184, "vram_headroom_bytes":2147483648, "vram_budget_bytes":17179869184, "backend":"cuda", "residency":[ { "tier":"lead_explorer", "model_path":"/.../qwen3_6_a3b.gguf", "footprint_bytes":14000000000, "weights_bytes":13100000000, "kv_cache_bytes":450000000, "headroom_bytes":450000000, "last_activation_ms":12345 } ] } last_activation_ms is monotonic milliseconds since engine start at the most recent activation of that tier (lower = older = first LRU eviction candidate). When VRAM capacity is unknown (non-CUDA build, detection failed), vram_total_bytes is 0 and backend is "unknown"; the residency array is still populated. 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.

Parameters
  • handle — Engine handle.
  • out_json out — Heap-allocated NUL-terminated JSON string. Caller frees with entropic_free_string.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle/out_json is NULL. ENTROPIC_ERROR_INVALID_STATE — engine not configured. ENTROPIC_ERROR_OUT_OF_MEMORY — allocation failed.
  • ENTROPIC_OK on success; INVALID_HANDLE for a NULL handle or out_json, INVALID_STATE when no orchestrator exists.

ENTROPIC_EXPORT entropic_error_t entropic_release_model(entropic_handle_t handle, const char *tier_name)

Release a resident model, keeping everything else on the handle.

A loaded model otherwise stays in VRAM for the life of the handle: the engine evicts only when a DIFFERENT tier needs the space, so a host that wants the GPU back had to destroy the handle — which also destroys every session's conversation, re-runs configure and re-registers MCP servers. Weights and conversation state have very different lifetimes; this separates them. Unloads the tier's backend and fires ENTROPIC_RESIDENCY_EVICTED for every tier that was backed by it. KEPT: the handle, its config, its registered MCP servers, all session conversations, and the tier's LoRA adapter REGISTRATIONS — their llama handles are freed with the model and re-bound at the next activation, so a release does not silently deregister an adapter the consumer loaded. The next use reloads lazily through the residency gate, exactly as a models.defer_load first use does (gh#157). There is no idle timer: only the host knows what idle means for its users.

Parameters
  • handle — Engine handle.
  • tier_name — Tier to release, or NULL/"" for EVERY resident model — every tier plus the secondary roles (router, speculative draft) and any MTP head, which the target backend owns and tears down with itself.
  • tier_name — Tier to release, or NULL/"" for every resident model.
Returns
  • ENTROPIC_OK on success — including when the tier was already unloaded, which is a no-op rather than an error. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — engine not configured. ENTROPIC_ERROR_MODEL_NOT_FOUND — no such tier. ENTROPIC_ERROR_ALREADY_RUNNING — a turn is in flight on this handle. Unloading a model mid-generation frees the context the decode is running on, so the call is refused rather than serialized behind the turn.
  • ENTROPIC_OK, INVALID_HANDLE, INVALID_STATE, MODEL_NOT_FOUND or ALREADY_RUNNING.
threadsafety
Claims the handle's turn; concurrent with nothing.

ENTROPIC_EXPORT entropic_error_t entropic_context_clear(entropic_handle_t handle)

Clear conversation history, starting a new session.

Removes all messages (system, user, assistant, tool) from the conversation. The next entropic_run() call starts fresh with only the system prompt.

Parameters
  • handle — Engine handle.
  • handle — Engine handle returned by entropic_create.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_context_get(entropic_handle_t handle, char **messages_json)

Get the current conversation history as a JSON array.

Returns the full message history including system prompt, user messages, assistant responses, and tool call results.

Parameters
  • handle — Engine handle.
  • messages_json out — Output: JSON array of message objects. Each object has "role" and "content" fields. Caller must free with entropic_free().
  • handle — Engine handle returned by entropic_create.
  • messages_json — Out-param: newly allocated JSON string (caller owns; free with entropic_free).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — messages_json is NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_run_session(entropic_handle_t handle, const char *session_key, const char *input, char **result_json)

Run a turn on a named session (gh#144).

The keyed sibling of entropic_run(). A NULL or empty session_key means the default session, so this is exactly entropic_run() in that case. The key is OPAQUE — the engine never interprets it. A consumer hosting one engine for several callers picks whatever identifies a caller for it (a canonical repository path, a hash). Two callers passing the SAME key share a conversation deliberately; that choice belongs to the consumer. Added as a new named function rather than by changing entropic_run's signature, per REQ-ABI-001. It is additive, so ENTROPIC_API_VERSION does not move. Run a turn on a named session (gh#144). The keyed sibling of entropic_run(). A NULL or empty session_key means the default session, so this is exactly entropic_run() in that case. The key is OPAQUE — the engine never interprets it. Two callers that pass the same string deliberately share a conversation; that choice belongs to the consumer, which is the only party that knows what identifies a caller. Added as a NEW NAMED FUNCTION rather than by changing entropic_run's signature, per REQ-ABI-001 and the entropic_run -> _streaming -> _messages -> _as -> _batch lineage, none of which ever modified an existing one. It is additive, so ENTROPIC_API_VERSION does NOT move.

Parameters
  • handle — Engine handle returned by entropic_create.
  • session_key — Session to run under; NULL or "" = default session.
  • input — Null-terminated user input.
  • result_json — Out: newly allocated JSON result (free with entropic_free).
  • handle — Engine handle.
  • input — User input.
  • result_json — Out: JSON result (free with entropic_free).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_ALREADY_RUNNING — a turn is in flight on this handle. One turn at a time: there is one model and one context. Other codes per entropic_run().
  • ENTROPIC_OK, or ENTROPIC_ERROR_ALREADY_RUNNING when a turn is already in flight on this handle.
threadsafety
NOT serialized. A second concurrent run on the same handle is refused rather than queued; a host wanting callers to WAIT must serialize above this layer, as the external MCP bridge does.

ENTROPIC_EXPORT entropic_error_t entropic_run_session_as(entropic_handle_t handle, const char *session_key, const char *tier_or_identity, const char *input, char **result_json)

Run a turn on a named session under a named tier (gh#144).

Parameters
  • handle — Engine handle.
  • session_key — Session to run under; NULL or "" = default session.
  • tier_or_identity — Tier to lock this call to.
  • input — Null-terminated user input.
  • result_json — Out: newly allocated JSON result (free with entropic_free).
  • input — User input.
  • result_json — Out: JSON result (free with entropic_free).
Returns
  • ENTROPIC_OK; ENTROPIC_ERROR_IDENTITY_NOT_FOUND for an unknown tier; ENTROPIC_ERROR_ALREADY_RUNNING when a turn is in flight.
  • ENTROPIC_OK, ENTROPIC_ERROR_IDENTITY_NOT_FOUND for an unknown tier, or ENTROPIC_ERROR_ALREADY_RUNNING.
threadsafety
NOT serialized. See entropic_run_session().

ENTROPIC_EXPORT entropic_error_t entropic_run_session_streaming(entropic_handle_t handle, const char *session_key, const char *input, void(*on_token)(const char *token, size_t len, void *user_data), void *user_data, int *cancel_flag)

Streaming turn on a named session (gh#144).

Streaming turn on a named session (gh#144).

Parameters
  • handle — Engine handle.
  • session_key — Session to run under; NULL or "" = default session.
  • input — Null-terminated user input.
  • on_token — Per-token callback.
  • user_data — Forwarded to on_token.
  • cancel_flag — Optional cancel flag (NULL for none).
  • input — User input.
  • cancel_flag — Optional cancel flag.
Returns
  • ENTROPIC_OK; ENTROPIC_ERROR_CANCELLED when cancelled; ENTROPIC_ERROR_ALREADY_RUNNING when a turn is in flight.
  • ENTROPIC_OK or ENTROPIC_ERROR_ALREADY_RUNNING.
threadsafety
NOT serialized. See entropic_run_session().

ENTROPIC_EXPORT entropic_error_t entropic_run_session_streaming_as(entropic_handle_t handle, const char *session_key, const char *tier_or_identity, const char *input, void(*on_token)(const char *token, size_t len, void *user_data), void *user_data, int *cancel_flag)

Streaming turn on a named session, under a named tier (gh#205).

The streaming counterpart of entropic_run_session_as(): the turn is locked to tier_or_identity with exactly its semantics (the tier's grammar and samplers apply to this turn; its system prompt is seeded only on an empty conversation). This is what lets ONE host serve several output contracts — before it, a streaming caller could not pick a tier at all, so a consumer needing two tiers ran two hosts. A set cancel_flag stops THIS turn only, never another session's (v2.14.0; the same now holds for entropic_run_session_streaming()). Additive: ENTROPIC_API_VERSION does not move. Streaming turn on a named session, under a named tier (gh#205).

Parameters
  • handle — Engine handle.
  • session_key — Session to run under; NULL or "" = default session.
  • tier_or_identity — Tier (or identity) to lock this turn to.
  • input — Null-terminated user input.
  • on_token — Per-token callback.
  • user_data — Forwarded to on_token.
  • cancel_flag — Optional cancel flag (NULL for none).
  • tier_or_identity — Tier to lock this turn to.
  • input — User input.
  • cancel_flag — Optional cancel flag.
Returns
  • ENTROPIC_OK; ENTROPIC_ERROR_CANCELLED when cancelled; ENTROPIC_ERROR_IDENTITY_NOT_FOUND for an unknown tier; ENTROPIC_ERROR_ALREADY_RUNNING when this session has a turn in flight; ENTROPIC_ERROR_INVALID_ARGUMENT for a NULL tier, input or callback.
  • See entropic.h.
threadsafety
NOT serialized. See entropic_run_session().

ENTROPIC_EXPORT entropic_error_t entropic_session_context_get(entropic_handle_t handle, const char *session_key, char **messages_json)

Read one session's conversation as a JSON array (gh#144).

Read one session's conversation as a JSON array (gh#144).

Parameters
  • handle — Engine handle.
  • session_key — Session to read; NULL or "" = default session.
  • messages_json — Out: newly allocated JSON array (free with entropic_free).
  • messages_json — Out: JSON array (free with entropic_free).
Returns
ENTROPIC_OK on success.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_session_context_set(entropic_handle_t handle, const char *session_key, const char *messages_json)

Replace one session's conversation (gh#165, v2.13.0).

The write counterpart entropic_session_context_get never had. Accepts exactly what that call emits, so a host can snapshot on shutdown and restore on start — which is what makes a session survive a process restart, and what makes entropic_release_model (gh#164) usable: weights and conversations get independent lifetimes. Replaces that session's conversation, runs NO turn and touches no model. The only way to get messages in before this was entropic_run_session, which appends and then RUNS — replaying a stored conversation that way re-executes the whole agentic loop per message, tool calls included. Replace one session's conversation (gh#165, v2.13.0). Front validation only; the work is in session_context_set_inner, split out for the knots returns gate.

Parameters
  • handle — Engine handle.
  • session_key — Session to replace; NULL or "" = default session.
  • messages_json — JSON array of message objects, in the shape entropic_session_context_get emits.
  • session_key — Session to replace; NULL = default.
  • messages_json — JSON array of message objects.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL or unconfigured. ENTROPIC_ERROR_INVALID_ARGUMENT — messages_json is NULL or is not a parseable JSON array. ENTROPIC_ERROR_ALREADY_RUNNING — a run on that session is in flight; the conversation was left untouched.
  • ENTROPIC_OK, INVALID_ARGUMENT, or ALREADY_RUNNING.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_session_context_count(entropic_handle_t handle, const char *session_key, size_t *count)

Message count for one session (gh#144).

Message count for one session (gh#144).

Parameters
  • handle — Engine handle.
  • session_key — Session to count; NULL or "" = default session.
  • count — Out: message count.
Returns
ENTROPIC_OK on success.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_session_context_clear(entropic_handle_t handle, const char *session_key)

Clear one session's history, leaving other sessions intact (gh#144).

The unscoped entropic_context_clear() wipes EVERY session, which with more than one caller active is never the right thing. Clear one session's history, leaving other sessions intact (gh#144). The unscoped entropic_context_clear wiped every caller's context, which is why the issue observed it "is not isolation" — with two callers active there was no ordering in which it was correct. gh#158 (v2.13.0): also releases that session's per-session tool state (read-before-write reads, todo list), and only that session's.

Parameters
  • handle — Engine handle.
  • session_key — Session to clear; NULL or "" = default session.
Returns
ENTROPIC_OK on success.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_session_drop(entropic_handle_t handle, const char *session_key)

Forget a session entirely (gh#144).

The default session ("") is cleared rather than erased, so the unscoped accessors remain total. Forget a session entirely (gh#144). gh#158 (v2.13.0): also releases that session's per-session tool state (read-before-write reads, todo list), so dropped sessions leave nothing behind on the servers.

Parameters
  • handle — Engine handle.
  • session_key — Session to drop.
  • session_key — Session to drop; "" is cleared rather than erased.
Returns
ENTROPIC_OK on success.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_session_list(entropic_handle_t handle, char **sessions_json)

List the sessions this handle currently holds (gh#144).

List the sessions this handle currently holds (gh#144). Feeds the bridge's status tool so an operator can see which callers the host is serving, and is what every session test asserts against.

Parameters
  • handle — Engine handle.
  • sessions_json — Out: newly allocated JSON array of {key, messages} (free with entropic_free).
  • sessions_json — Out: JSON array of {key, messages} (free with entropic_free).
Returns
ENTROPIC_OK on success.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_workspace_create(entropic_handle_t handle, const char *name, const char *dir)

Create a named workspace rooted at a directory (gh#166).

One resident model, many projects. A workspace owns its OWN built-in and plugin MCP server instances rooted at dir, its own external MCP servers, and its own delegation sandbox — because a server holds one working directory, and two repositories cannot share one instance. Weights, tiers and identity stay handle-wide, so opening a second repository costs no model reload. Creating a workspace changes nothing for existing sessions: a session that is never bound keeps using mcp.working_dir (else the process cwd) exactly as before. A workspace's filesystem tools are HARD-confined to dir: whatever the host set for mcp.filesystem.allow_outside_root, outside_root_allow or entropic_set_path_approval_callback, a path outside dir is refused ("Path escapes project root: ..."), because outside one workspace is inside another (v2.13.0). outside_root_deny still applies — it can only narrow.

Parameters
  • handle — Engine handle (must be configured).
  • name — Workspace name, unique per handle. Non-empty.
  • dir — Existing directory the workspace's tools resolve against.
  • handle — Engine handle.
  • name — Workspace name.
  • dir — Workspace root directory.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — handle not configured. ENTROPIC_ERROR_INVALID_ARGUMENT — NULL/empty name or dir, a name already in use, or a dir that is not a directory.
  • ENTROPIC_OK, or a typed argument/state error.
threadsafety
Serialized per-handle (api_mutex).

ENTROPIC_EXPORT entropic_error_t entropic_session_bind_workspace(entropic_handle_t handle, const char *session_key, const char *name)

Bind a session to a workspace (gh#166).

Every tool call that session makes — and every delegation sandbox it opens — then resolves against that workspace's root and servers. Binding is ONCE per session. A session that already holds messages is refused: its conversation cites paths relative to the root it was working in, and silently re-rooting it would make every one of those citations wrong without a single error.

Parameters
  • handle — Engine handle (must be configured).
  • session_key — Session key; "" (or NULL) is the default session.
  • name — Workspace name previously passed to entropic_workspace_create.
  • handle — Engine handle.
  • session_key — Session key (NULL or "" = default session).
  • name — Workspace name.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — handle not configured, or the session already holds messages. ENTROPIC_ERROR_INVALID_ARGUMENT — unknown workspace name.
  • ENTROPIC_OK, or a typed argument/state error.
threadsafety
Serialized per-handle (api_mutex).

ENTROPIC_EXPORT entropic_error_t entropic_workspace_set_app_context(entropic_handle_t handle, const char *name, const char *app_context)

Give a workspace its own app_context (gh#179).

One resident model serving several repositories: each workspace's sessions are seeded with the handle's constitution and tier identity, and THIS text in the app_context slot instead of the handle's. Taken verbatim, like app_context: {content: ...} (gh#141). Applies to every session bound to the workspace whose conversation has not started — a started conversation keeps the system message it was seeded with. Bind order does not matter. A delegated child of a bound session gets the workspace's prompt for its tier too. A workspace can also take its text from a file in its root, opt-in, via the workspace_app_context config key (e.g. .entropic/ENTROPIC.md); this call overrides whatever that loaded. Give a workspace its own app_context (gh#179).

Parameters
  • handle — Engine handle (must be configured).
  • name — Workspace name previously passed to entropic_workspace_create().
  • app_context — The workspace's app_context text; "" = no app_context for this workspace; NULL = drop the override and use the handle's.
  • handle — Engine handle.
  • name — Workspace name.
  • app_context — Text; "" = none; NULL = the handle's.
Returns
  • ENTROPIC_OK on success, otherwise the error below.
  • ENTROPIC_OK, or a typed argument/state error.
Return values
  • ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_ERROR_INVALID_STATE — handle not configured.
  • ENTROPIC_ERROR_INVALID_ARGUMENT — NULL/empty or unknown name.
threadsafety
Serialized per-handle (api_mutex).

ENTROPIC_EXPORT entropic_error_t entropic_context_count(entropic_handle_t handle, size_t *count)

Get the number of messages in the conversation.

Parameters
  • handle — Engine handle.
  • count out — Output: number of messages.
  • handle — Engine handle returned by entropic_create.
  • count — Out-param: receives the token count.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — count is NULL.
threadsafety
Thread-safe (read-only).

ENTROPIC_EXPORT entropic_error_t entropic_context_usage(entropic_handle_t handle, size_t *tokens_used, size_t *capacity)

Read current context-window pressure for the active tier.

Returns the same (used, capacity) pair the engine's core.context_manager logs at info level. Cheap — counts tokens across the current conversation against the active tier's context_length. Suitable for ~1 Hz consumer polling (e.g. a "6727/32768 tokens (20%)" UI gauge).

Parameters
  • handle — Engine handle.
  • tokens_used out — Output: tokens currently in the conversation.
  • capacity out — Output: configured context_length for the active tier.
  • tokens_used — Out-param: tokens in the current conversation.
  • capacity — Out-param: active tier's configured context_length.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — either out pointer is NULL. ENTROPIC_ERROR_INVALID_STATE — engine has no active tier (rare; before first tier_lock / configure).
threadsafety
Serialized per-handle (api_mutex).

ENTROPIC_EXPORT entropic_error_t entropic_state_save(entropic_handle_t handle, const char *tier_name, const char *path)

Save a tier's KV-cache state to a file (gh#23 MVP item 13).

Persists the active backend's KV cache (sequence 0) for the named tier to disk. Useful for warm-restart scenarios: save after the system prompt + identity is prefilled, then on a fresh process entropic_state_load skips re-tokenizing + decoding that prefix.

Parameters
  • handle — Engine handle.
  • tier_name — Tier whose backend KV cache to capture.
  • path — Destination file path (will be truncated/created).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — tier_name or path is NULL. ENTROPIC_ERROR_INVALID_STATE — tier not active. ENTROPIC_ERROR_IO — file write failure. ENTROPIC_ERROR_INTERNAL — backend save_state returned false.
threadsafety
Serialized per-handle (api_mutex).

ENTROPIC_EXPORT entropic_error_t entropic_state_load(entropic_handle_t handle, const char *tier_name, const char *path)

Restore a tier's KV-cache state from a file (gh#23 MVP item 13).

Counterpart to entropic_state_save. The model+tier must match the one used at save time (llama.cpp state blobs are not portable).

Parameters
  • handle — Engine handle.
  • tier_name — Tier whose backend KV cache to restore.
  • path — Source file path.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — tier_name or path is NULL. ENTROPIC_ERROR_INVALID_STATE — tier not active. ENTROPIC_ERROR_IO — file read failure or empty file. ENTROPIC_ERROR_INTERNAL — backend restore_state returned false (typically a model/format mismatch with the save site).
threadsafety
Serialized per-handle (api_mutex).

ENTROPIC_EXPORT entropic_error_t entropic_metrics_json(entropic_handle_t handle, char **out)

Get loop metrics from the most recent run as JSON.

Populates *out with a malloc'd JSON string containing flat fields (iterations, tool_calls, tokens_used, errors, duration_ms) and a per_tier object keyed by tier name. Caller must entropic_free(*out).

Parameters
  • handle — Engine handle.
  • out out — Output: malloc'd JSON string. Caller frees via entropic_free().
  • out out — Output JSON; caller frees via entropic_free.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — out is NULL.
threadsafety
Thread-safe (read-only).

ENTROPIC_EXPORT 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 start/complete callbacks for delegations.

Both callbacks are optional. Passing NULL for either clears that slot. A typical consumer registers on_complete to receive patches and (optionally) on_start to gate or audit delegations before they run. Replaces the pre-2.1.5 silent auto-merge-to-develop behavior that caused gh#29 (engine corrupting the user's repo state): the engine never runs git checkout, creates branches, commits or merges in the user's repository, on any path.

Parameters
  • handle — Engine handle.
  • on_start — Pre-delegation gate callback (NULL to clear).
  • on_complete — Post-delegation result callback (NULL to clear).
  • user_data — Pointer forwarded to both callbacks.
  • on_start — Pre-delegation gate (nullable clears).
  • on_complete — Post-delegation result (nullable clears).
  • user_data — Forwarded to both callbacks.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
threadsafety
Serialized per-handle. Callbacks fire on the thread that is running the parent turn — a child loop runs inline on it, not on a thread of its own — so with concurrent_sessions on (the v2.13.0 default) they may fire from several run threads at once and must be thread-safe.

ENTROPIC_EXPORT entropic_error_t entropic_set_path_approval_callback(entropic_handle_t handle, ent_path_approval_cb cb, void *user_data)

Register the approver for filesystem access outside the root.

mcp.filesystem.allow_outside_root is tri-state: false refuses every path outside the root, true serves every one, and optional — the default since v2.13.0 — asks THIS callback. With no callback registered, optional REFUSES, with a tool error beginning outside_root_approval_required: that names the path and says how to configure access. It never fails open. Until v2.13.0 the bundled data/default_config.yaml set the flag to true, so every consumer on bundled defaults gave the model unconfined read and write of the whole filesystem. A host that relied on that must now choose: register this callback, pre-approve directories with outside_root_allow, or set allow_outside_root: true explicitly.

Parameters
  • handle — Engine handle. Registration before entropic_configure* is kept and applied when the servers are built.
  • cb — Approver, or NULL to clear (escapes then refuse).
  • user_data — Pointer forwarded to cb.
  • handle — Engine handle.
  • cb — Approver (NULL clears).
  • user_data — Forwarded to cb.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK, or ENTROPIC_ERROR_INVALID_HANDLE.
threadsafety
Thread-safe. cb fires on the thread running the turn that made the tool call — with concurrent_sessions on, several at once — so it must be thread-safe, and it may block (to ask a person) without holding up other sessions' registration.

ENTROPIC_EXPORT entropic_error_t entropic_validation_set_auto_retry(entropic_handle_t handle, int enabled)

Toggle automatic constitutional revision after rejection.

When enabled is true (the default), the engine immediately injects critique feedback into the conversation and re-streams attempt N+1 after each failing constitutional pass. When enabled is false, the engine instead stops after the first failing critique and surfaces the rejection through entropic_validation_last_result() with verdict paused_pending_consumer. The consumer is then expected to call either entropic_validation_resume_retry() (opt into revision) or entropic_validation_accept_last() (treat the rejected attempt as the final answer).

Parameters
  • handle — Engine handle.
  • enabled — True to restore default auto-revision (the pre-2.1.5 behavior); false to disable it.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_INVALID_HANDLE when handle is NULL.
threadsafety
Thread-safe.

ENTROPIC_EXPORT entropic_error_t entropic_validation_resume_retry(entropic_handle_t handle)

Opt the engine into running the constitutional revision pass.

Resumes auto-revision for the currently paused validation state (set by the most recent entropic_run() when auto-retry was disabled and a critique failed). Runs synchronously and updates the conversation with the revised content. If no validation is paused this is a no-op.

Parameters
  • handle — Engine handle.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — no paused validation.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_INVALID_HANDLE when handle is NULL, ENTROPIC_ERROR_INVALID_STATE when no validator exists.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_validation_accept_last(entropic_handle_t handle)

Finalize the last attempt as the turn's response.

Used after entropic_validation_set_auto_retry(handle, false) has paused the engine on a critique rejection: instructs the engine to keep the rejected attempt as-is (i.e. the user overrode the validator). Clears the paused validation state and updates the last validation result to verdict passed_consumer_override.

Parameters
  • handle — Engine handle.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_STATE — no paused validation.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_INVALID_HANDLE when handle is NULL, ENTROPIC_ERROR_INVALID_STATE when no validator exists.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_set_attempt_boundary_cb(entropic_handle_t handle, ent_validation_attempt_boundary_cb cb, void *user_data)

Register an attempt-boundary callback for the validator.

Fires once per revision pass with the upcoming attempt number. Pass NULL to clear. The callback runs on the engine's generation thread — keep it short and non-blocking.

Parameters
  • handle — Engine handle.
  • cb — Attempt-boundary callback (NULL to clear).
  • user_data — Pointer forwarded to cb.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_INVALID_HANDLE when handle is NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_register_mcp_server(entropic_handle_t handle, const char *name, const char *config_json)

Register an external MCP server at runtime.

Connects to the server immediately. For stdio: spawns child process. For SSE: connects to HTTP endpoint.

Parameters
  • handle — Engine handle.
  • name — Unique server name (null-terminated).
  • config_json — JSON configuration: Stdio: {"command":"...","args":[...],"env":{...}} SSE: {"url":"http://..."}
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — name or config_json is NULL. ENTROPIC_ERROR_SERVER_ALREADY_EXISTS — name already registered. ENTROPIC_ERROR_CONNECTION_FAILED — transport connect failed.
  • ENTROPIC_OK on success; the check_server_mgr code for a bad handle/state, INVALID_ARGUMENT for NULL name/config_json, CONNECTION_FAILED when the transport connect throws.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_deregister_mcp_server(entropic_handle_t handle, const char *name)

Deregister an external MCP server.

Disconnects and removes the server. In-progress tool calls are not interrupted but subsequent calls will fail.

Parameters
  • handle — Engine handle.
  • name — Server name to remove (null-terminated).
  • handle — Engine handle returned by entropic_create.
  • name — MCP server name (must be unique).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — name is NULL. ENTROPIC_ERROR_SERVER_NOT_FOUND — name not registered.
  • ENTROPIC_OK or error code.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_list_mcp_servers(entropic_handle_t handle)

List all MCP servers with status information.

Returns both in-process and external servers.

Parameters
  • handle — Engine handle.
  • handle — Engine handle returned by entropic_create.
Returns
  • JSON string: {"servers":{"name":{...ServerInfo...},...}}. Caller must free with entropic_free(). NULL on error.
  • JSON string (caller frees), or NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_storage_open(entropic_handle_t handle, const char *db_path)

Open or create a SQLite storage backend.

Initializes persistent storage for conversations, delegations, and session logs. The database file is created if it does not exist. Storage is optional — the engine operates in-memory without it.

Parameters
  • handle — Engine handle.
  • db_path — Path to SQLite database file.
  • handle — Engine handle returned by entropic_create.
  • db_path — Filesystem path to the SQLite database file.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — db_path is NULL. ENTROPIC_ERROR_STORAGE_FAILED — database open/init failed.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_storage_close(entropic_handle_t handle)

Close the storage backend and flush pending writes.

No-op if storage was never opened.

Parameters
  • handle — Engine handle.
  • handle — Engine handle returned by entropic_create.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK (no-op if storage not opened).
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_load_identity(entropic_handle_t handle, const char *identity_name)

Load an identity by name from the configuration.

Resolves the identity name against the loaded config, loads the identity's system prompt and tool filter, and sets it as the active identity for subsequent entropic_run() calls.

Parameters
  • handle — Engine handle.
  • identity_name — Null-terminated identity name (e.g., "eng", "lead").
  • handle — Engine handle returned by entropic_create.
  • identity_name — Identity name from configured tier set.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — identity_name is NULL. ENTROPIC_ERROR_IDENTITY_NOT_FOUND — name not in config. ENTROPIC_ERROR_INVALID_CONFIG — identity config malformed.
  • ENTROPIC_OK if identity exists, error otherwise.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_get_identity(entropic_handle_t handle, char **identity_json)

Get the current active identity as a JSON string.

Returns a JSON object with identity name, system prompt hash, allowed_tools list, and phase configuration.

Parameters
  • handle — Engine handle.
  • identity_json out — Output: JSON string. Caller must free with entropic_free().
  • handle — Engine handle returned by entropic_create.
  • identity_json — Out-param: newly allocated JSON string (caller owns; free with entropic_free).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — identity_json is NULL. ENTROPIC_ERROR_IDENTITY_NOT_FOUND — no identity loaded.
  • ENTROPIC_OK on success, error otherwise.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_register_hook(entropic_handle_t handle, entropic_hook_point_t hook_point, entropic_hook_callback_t callback, void *user_data, int priority)

Register a callback for an engine hook point.

Multiple callbacks can be registered for the same hook point. They execute in ascending priority order (0 = highest priority). A pre-hook returning non-zero cancels the operation. A pre-hook returning modified JSON (via context_json out-param) modifies the operation's input.

Parameters
  • handle — Engine handle.
  • hook_point — The hook point to register for.
  • callback — Function pointer invoked when the hook fires.
  • user_data — Opaque pointer passed to callback.
  • priority — Execution priority (0 = first, higher = later).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — callback is NULL. ENTROPIC_ERROR_INVALID_CONFIG — invalid hook_point value.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_deregister_hook(entropic_handle_t handle, entropic_hook_point_t hook_point, entropic_hook_callback_t callback, void *user_data)

Deregister a previously registered hook callback.

Matches on (hook_point, callback, user_data) triple. If no match is found, returns ENTROPIC_OK (idempotent).

Parameters
  • handle — Engine handle.
  • hook_point — The hook point to deregister from.
  • callback — The callback function pointer to remove.
  • user_data — The user_data that was passed during registration.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT 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.

Parameters
  • handle — Engine handle.
  • adapter_name — Unique adapter identifier.
  • adapter_path — Path to the LoRA .gguf file.
  • base_model_path — Base model this adapter targets (must be loaded).
  • scale — LoRA scaling factor (1.0 = full strength).
  • adapter_path — Path to the adapter GGUF.
  • base_model_path — Model path identifying the owning tier.
  • scale — LoRA scale.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_MODEL_NOT_FOUND — base model not loaded. ENTROPIC_ERROR_ADAPTER_LOAD_FAILED — adapter file invalid. ENTROPIC_ERROR_INVALID_CONFIG — adapter already loaded.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_ALREADY_RUNNING when a turn is in flight, else an error code.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_adapter_unload(entropic_handle_t handle, const char *adapter_name)

Unload a LoRA adapter.

Parameters
  • handle — Engine handle.
  • adapter_name — Adapter to unload.
Returns
  • ENTROPIC_OK on success. Idempotent if already COLD. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK on success, error code on failure.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_adapter_swap(entropic_handle_t handle, const char *adapter_name)

Swap the active LoRA adapter.

Parameters
  • handle — Engine handle.
  • adapter_name — Adapter to activate (must be WARM or HOT).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_ADAPTER_NOT_FOUND — adapter not loaded. ENTROPIC_ERROR_ADAPTER_SWAP_FAILED — swap failed. ENTROPIC_ERROR_ADAPTER_CANCELLED — hook cancelled.
  • ENTROPIC_OK on success, error code on failure.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT int entropic_adapter_state(entropic_handle_t handle, const char *adapter_name)

Query adapter state.

Parameters
  • handle — Engine handle.
  • adapter_name — Adapter identifier.
Returns
  • State as int: 0=COLD, 1=WARM, 2=HOT. -1 if not found.
  • AdapterState as int, or -1 on error.
threadsafety
Thread-safe.

ENTROPIC_EXPORT char * entropic_adapter_info(entropic_handle_t handle, const char *adapter_name)

Get adapter info as JSON.

Parameters
  • handle — Engine handle.
  • adapter_name — Adapter identifier.
Returns
  • JSON string with adapter metadata. Caller frees with entropic_free(). NULL if adapter not found.
  • JSON string (caller frees), or NULL on error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_adapter_list(entropic_handle_t handle)

List all adapters as JSON array.

Parameters
  • handle — Engine handle.
Returns
  • JSON array of AdapterInfo objects. Caller frees with entropic_free().
  • JSON array string (caller frees), or NULL on error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_grammar_register(entropic_handle_t handle, const char *key, const char *gbnf_content)

Register a grammar by key from a GBNF content string.

Parameters
  • handle — Engine handle.
  • key — Unique grammar name (null-terminated).
  • gbnf_content — Raw GBNF grammar string (null-terminated).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — key or gbnf_content is NULL. ENTROPIC_ERROR_INVALID_CONFIG — key already exists.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_ALREADY_EXISTS if key already registered.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_grammar_register_file(entropic_handle_t handle, const char *key, const char *path)

Register a grammar from a file path.

Parameters
  • handle — Engine handle.
  • key — Grammar name (if NULL, uses filename stem).
  • path — Path to .gbnf file (null-terminated).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — path is NULL. ENTROPIC_ERROR_INVALID_CONFIG — key already exists. ENTROPIC_ERROR_LOAD_FAILED — file unreadable.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_IO if file unreadable, ENTROPIC_ERROR_ALREADY_EXISTS if key exists.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_grammar_deregister(entropic_handle_t handle, const char *key)

Remove a grammar from the registry.

Parameters
  • handle — Engine handle.
  • key — Grammar name (null-terminated).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — key is NULL. ENTROPIC_ERROR_GRAMMAR_NOT_FOUND — key not registered.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_GRAMMAR_NOT_FOUND if key not registered.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_grammar_get(entropic_handle_t handle, const char *key)

Get grammar content by key.

Parameters
  • handle — Engine handle.
  • key — Grammar name (null-terminated).
Returns
  • GBNF content string. Caller frees with entropic_free(). NULL if key not found.
  • GBNF string (caller frees), or NULL if not found.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_grammar_validate(const char *gbnf_content)

Validate a GBNF grammar string without registering.

Parameters
  • gbnf_content — Raw GBNF string to validate (null-terminated).
Returns
  • NULL on success (valid grammar). Error description string on failure. Caller frees with entropic_free().
  • NULL if valid; error description string (caller frees) if invalid.
threadsafety
Thread-safe.

ENTROPIC_EXPORT char * entropic_grammar_list(entropic_handle_t handle)

List all registered grammars as JSON array.

Parameters
  • handle — Engine handle.
Returns
  • JSON array of grammar metadata objects: [{"key":"compactor","source":"bundled","validated":true}, ...] Content strings are NOT included (use entropic_grammar_get). Caller frees with entropic_free().
  • JSON array string (caller frees), or NULL on error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_profile_register(entropic_handle_t handle, const char *profile_json)

Register a custom GPU resource profile.

Parameters
  • handle — Engine handle.
  • profile_json — JSON string: {"name":"...", "n_batch":N, "n_threads":N, "n_threads_batch":N, "description":"..."}. Only "name" is required; other fields default.
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — profile_json is NULL. ENTROPIC_ERROR_ALREADY_EXISTS — name already registered.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_ALREADY_EXISTS if name exists, ENTROPIC_ERROR_INVALID_ARGUMENT on parse error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_profile_deregister(entropic_handle_t handle, const char *name)

Remove a GPU resource profile.

Parameters
  • handle — Engine handle.
  • name — Profile name (null-terminated).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_PROFILE_NOT_FOUND — name not registered.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_PROFILE_NOT_FOUND if name not registered.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_profile_get(entropic_handle_t handle, const char *name)

Get a profile by name as JSON.

Parameters
  • handle — Engine handle.
  • name — Profile name (null-terminated).
Returns
  • JSON string of GPUResourceProfile fields. NULL if handle is NULL or name not found.
  • JSON string (caller frees), or NULL on error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_profile_list(entropic_handle_t handle)

List all registered profiles as JSON array.

Parameters
  • handle — Engine handle.
Returns
  • JSON array of profile objects. NULL if handle is NULL.
  • JSON array string (caller frees), or NULL on error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT double entropic_throughput_tok_per_sec(entropic_handle_t handle, const char *model_path)

Get current throughput estimate for a model.

Parameters
  • handle — Engine handle.
  • model_path — Path to the model (same key as ModelConfig.path).
Returns
  • Tokens per second (EWMA). 0.0 if no data or handle is NULL.
  • Tokens per second estimate, or 0.0 on error/no data.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT void entropic_throughput_reset(entropic_handle_t handle, const char *model_path)

Reset throughput tracking data for a model.

Parameters
  • handle — Engine handle.
  • model_path — Model path. NULL = reset all models.
  • handle — Engine handle returned by entropic_create.
  • model_path — Path or registry key identifying the model whose throughput should be reset.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT 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.

If the identity has no key set, one is created automatically (enabling enforcement).

Parameters
  • handle — Engine handle.
  • identity_name — Identity/tier name (null-terminated).
  • pattern — Tool pattern string (null-terminated).
  • level — Access level to grant.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — identity_name or pattern is NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT 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.

Parameters
  • handle — Engine handle.
  • identity_name — Identity/tier name (null-terminated).
  • pattern — Tool pattern string (null-terminated).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — identity_name or pattern is NULL. ENTROPIC_ERROR_IDENTITY_NOT_FOUND — identity not registered.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT int entropic_check_mcp_key(entropic_handle_t handle, const char *identity_name, const char *tool_name, entropic_mcp_access_level_t level)

Check if a tool call is authorized for an identity.

Parameters
  • handle — Engine handle.
  • identity_name — Identity/tier name (null-terminated).
  • tool_name — Fully-qualified tool name (null-terminated).
  • level — Required access level.
Returns
1 if authorized, 0 if denied, -1 on error.
threadsafety
Thread-safe.

ENTROPIC_EXPORT char * entropic_list_mcp_keys(entropic_handle_t handle, const char *identity_name)

List all MCP keys for an identity as JSON.

Parameters
  • handle — Engine handle.
  • identity_name — Identity/tier name (null-terminated).
Returns
  • JSON array of key objects. Caller frees with entropic_free(). NULL if identity not found or error.
  • JSON array string (caller frees), or NULL on error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT 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.

The granter must possess the key at >= the granted level.

Parameters
  • handle — Engine handle.
  • granter — Granting identity (null-terminated).
  • grantee — Receiving identity (null-terminated).
  • pattern — Tool pattern to grant (null-terminated).
  • level — Access level to grant.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_IDENTITY_NOT_FOUND — either identity not registered. ENTROPIC_ERROR_PERMISSION_DENIED — granter lacks the key.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_serialize_mcp_keys(entropic_handle_t handle)

Serialize all identity key sets to JSON.

Parameters
  • handle — Engine handle.
Returns
  • JSON object string. Caller frees with entropic_free().
  • JSON string (caller frees), or NULL on error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_deserialize_mcp_keys(entropic_handle_t handle, const char *json)

Deserialize all identity key sets from JSON.

Replaces all current key sets with the deserialized state.

Parameters
  • handle — Engine handle.
  • json — JSON object string.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — json is NULL. ENTROPIC_ERROR_INVALID_CONFIG — parse failure.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_audit_flush(entropic_handle_t handle)

Flush the audit logger to disk immediately.

Parameters
  • handle — Engine handle.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_CONFIG — no audit logger configured.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_audit_count(entropic_handle_t handle, size_t *count)

Get the number of audit log entries recorded this session.

Parameters
  • handle — Engine handle.
  • count out — Output: number of entries recorded.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — count is NULL. ENTROPIC_ERROR_INVALID_CONFIG — no audit logger configured.
threadsafety
Lock-free read.

ENTROPIC_EXPORT entropic_error_t entropic_audit_read(entropic_handle_t handle, const char *path, const char *filter_json, char **result_json)

Read audit log entries from a JSONL file.

Reads and parses entries from an audit.jsonl file. No tool calls are executed — this is inspection only.

Parameters
  • handle — Engine handle.
  • path — Path to audit.jsonl file (null-terminated).
  • filter_json — Filter criteria as JSON, or NULL for no filter. Format: {"caller_id": "eng", "tool_name": "filesystem.*"} All fields optional. Absent fields match everything.
  • result_json out — Output: JSON array of audit entries. Caller must free with entropic_free().
  • path — Filesystem path to the JSONL audit log file.
  • result_json — Out-param: newly allocated JSON string (caller owns; free with entropic_free).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — path or result_json is NULL. ENTROPIC_ERROR_INVALID_CONFIG — path cannot be read.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_create_identity(entropic_handle_t handle, const char *config_json)

Create a dynamic identity.

Parameters
  • handle — Engine handle.
  • config_json — Identity configuration as JSON string. Required fields: "name", "system_prompt", "focus" (array, min 1). Optional fields: "examples", "grammar_id", "auto_chain", "allowed_tools", "bash_commands", "mcp_keys", "adapter_path", "max_output_tokens", "temperature", "repeat_penalty", "enable_thinking", "interstitial", "routable", "explicit_completion", "phases".
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — config_json is NULL. ENTROPIC_ERROR_INVALID_CONFIG — validation failed. ENTROPIC_ERROR_LIMIT_REACHED — max_identities exceeded. ENTROPIC_ERROR_ALREADY_EXISTS — name already taken.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_update_identity(entropic_handle_t handle, const char *name, const char *config_json)

Update a dynamic identity.

Parameters
  • handle — Engine handle.
  • name — Identity name (null-terminated).
  • config_json — Full replacement config as JSON string.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — name or config_json is NULL. ENTROPIC_ERROR_IDENTITY_NOT_FOUND — identity doesn't exist. ENTROPIC_ERROR_PERMISSION_DENIED — identity is static. ENTROPIC_ERROR_INVALID_CONFIG — validation failed.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_destroy_identity(entropic_handle_t handle, const char *name)

Destroy a dynamic identity.

Parameters
  • handle — Engine handle.
  • name — Identity name (null-terminated).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — name is NULL. ENTROPIC_ERROR_IDENTITY_NOT_FOUND — identity doesn't exist. ENTROPIC_ERROR_PERMISSION_DENIED — identity is static. ENTROPIC_ERROR_IN_USE — identity active in delegation.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_get_identity_config(entropic_handle_t handle, const char *name)

Get identity configuration as JSON by name.

Parameters
  • handle — Engine handle.
  • name — Identity name (null-terminated).
Returns
  • JSON string of identity config. Caller frees with entropic_free(). NULL if identity not found or handle is NULL.
  • JSON string (caller frees), or NULL if not found.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_list_identities(entropic_handle_t handle)

List all identity names as JSON array.

Parameters
  • handle — Engine handle.
Returns
  • JSON array of identity name strings. Caller frees with entropic_free(). NULL on error.
  • JSON array string (caller frees), or NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_identity_count(entropic_handle_t handle, size_t *total, size_t *dynamic)

Get identity count.

Parameters
  • handle — Engine handle.
  • total — Output: total identity count (static + dynamic).
  • dynamic — Output: dynamic identity count only. Pass NULL to skip.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — total is NULL.
threadsafety
Thread-safe.

ENTROPIC_EXPORT entropic_error_t entropic_compact(entropic_handle_t handle, const char *identity, char **result_json)

Trigger compaction on the current context.

Forces compaction regardless of threshold. Runs through the full pipeline: PRE_COMPACT hooks -> compactor -> POST_COMPACT hooks.

Parameters
  • handle — Engine handle.
  • identity — Identity context for compactor selection (NULL = current).
  • result_json — Output: compaction result JSON. Caller frees with entropic_free(). NULL if no compaction occurred (e.g., cancelled by hook).
  • handle — Engine handle returned by entropic_create.
  • identity — Identity name from configured tier set.
  • result_json — Out-param: newly allocated JSON string (caller owns; free with entropic_free).
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE ENTROPIC_ERROR_COMPACTION_FAILED
threadsafety
Serialized per-handle.

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.

Replaces the default compaction strategy for the specified identity. Pass identity="" to set a global fallback for all identities without a per-identity compactor. Resolution order: per-identity -> global custom ("") -> built-in default. Only one compactor per identity. Re-registering replaces the previous.

Parameters
  • handle — Engine handle.
  • identity — Identity name, or "" for global fallback.
  • compactor — Compactor function pointer.
  • user_data — Opaque pointer passed to compactor on each call.
  • handle — Engine handle returned by entropic_create.
  • identity — Identity name from configured tier set.
  • compactor — Function pointer to consumer-supplied compactor.
  • user_data — Opaque pointer passed back to the callback.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE ENTROPIC_ERROR_INVALID_CONFIG (NULL compactor)
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_deregister_compactor(entropic_handle_t handle, const char *identity)

Deregister a custom compactor for an identity.

After deregistration, the identity falls back to the global custom compactor (if any), then to the built-in default.

Parameters
  • handle — Engine handle.
  • identity — Identity name, or "" for global fallback.
  • handle — Engine handle returned by entropic_create.
  • identity — Identity name from configured tier set.
Returns
  • ENTROPIC_OK on success (idempotent). ENTROPIC_ERROR_INVALID_HANDLE
  • ENTROPIC_OK on success.
threadsafety
Serialized per-handle.

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.

Useful for consumers that want to wrap the default behavior (e.g., add logging, metrics, or post-processing around it).

Parameters
  • handle — Engine handle.
  • compactor — Output: default compactor function pointer.
  • user_data — Output: user_data to pass to the default compactor.
  • handle — Engine handle returned by entropic_create.
  • compactor — Out-param: receives function pointer to current compactor.
  • user_data — Opaque pointer passed back to the callback.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE ENTROPIC_ERROR_INVALID_ARGUMENT (NULL compactor output)
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT 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.

Runs the token sequence through the model and returns the log-probability of each token given its preceding context. Evaluation-only — no sampling, no generation, no KV cache mutation visible to ongoing generation.

Parameters
  • handle — Engine handle.
  • model_id — Model identifier (tier name or model key).
  • tokens — Array of token IDs to evaluate.
  • n_tokens — Number of tokens (minimum 2).
  • result — Output: logprob result. Caller frees internal arrays with entropic_free_logprob_result().
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE ENTROPIC_ERROR_MODEL_NOT_FOUND (unknown model_id) ENTROPIC_ERROR_MODEL_NOT_ACTIVE (model not ACTIVE) ENTROPIC_ERROR_EVAL_CONTEXT_FULL (exceeds n_ctx) ENTROPIC_ERROR_INVALID_CONFIG (n_tokens < 2) ENTROPIC_ERROR_EVAL_FAILED (llama_decode error)
  • ENTROPIC_OK on success, error code on failure.
threadsafety
Serialized per-model via eval_mutex. Does not block generation on the same model.

ENTROPIC_EXPORT 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 — calls entropic_get_logprobs() internally and returns only the perplexity value.

Parameters
  • handle — Engine handle.
  • model_id — Model identifier (tier name or model key).
  • tokens — Array of token IDs to evaluate.
  • n_tokens — Number of tokens (minimum 2).
  • perplexity — Output: perplexity value.
Returns
  • ENTROPIC_OK on success. Same error codes as entropic_get_logprobs().
  • ENTROPIC_OK on success, error code on failure.
threadsafety
Same as entropic_get_logprobs().

ENTROPIC_EXPORT void entropic_free_logprob_result(entropic_logprob_result_t *result)

Free internal arrays of a logprob result.

Frees the logprobs and tokens arrays, then NULLs the pointers to prevent double-free. The result struct itself is caller-owned and is NOT freed. Frees logprobs and tokens arrays, then NULLs the pointers to prevent double-free. The struct itself is caller-owned.

Parameters
  • result — Pointer to result struct. NULL-safe (no-op).

ENTROPIC_EXPORT entropic_error_t entropic_validation_set_enabled(entropic_handle_t handle, bool enabled)

Enable or disable constitutional validation.

When disabled, the POST_GENERATE hook is deregistered (zero overhead). When re-enabled, it is re-registered.

Parameters
  • handle — Engine handle.
  • enabled — true to enable, false to disable.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_validation_set_identity(entropic_handle_t handle, const char *identity_name, bool enabled)

Set per-identity validation override.

Parameters
  • handle — Engine handle.
  • identity_name — Identity name (null-terminated).
  • enabled — true to enable, false to disable for this identity.
Returns
ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL. ENTROPIC_ERROR_INVALID_ARGUMENT — identity_name is NULL.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT char * entropic_validation_last_result(entropic_handle_t handle)

Get the last validation result as JSON.

Return format: {"was_revised": false, "revision_count": 0, "compliant": true, "violations": [], "tier": "eng"}

Parameters
  • handle — Engine handle.
Returns
  • JSON string with validation metadata from the last generation. NULL if no validation has run. Caller frees with entropic_free().
  • JSON string (caller frees), or NULL if no result.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT int entropic_model_has_vision(entropic_handle_t handle, const char *model_id)

Check if a model has vision capability.

Returns 1 when the specified model has an mmproj loaded (vision encoder active). Returns 0 for text-only models or unknown model_id.

Parameters
  • handle — Engine handle.
  • model_id — Model identifier (tier name, e.g. "primary").
Returns
  • 1 if vision-capable (mmproj loaded), 0 if text-only.
  • 1 if vision-capable, 0 if text-only or error.
threadsafety
Serialized per-handle.

ENTROPIC_EXPORT entropic_error_t entropic_get_diagnostic_prompt(entropic_handle_t handle, char **prompt_out)

Get the diagnostic prompt text for /diagnose command.

Returns the bundled diagnostic prompt that consumers inject as a user message to trigger model self-diagnosis. The prompt instructs the model to call entropic.diagnose and produce structured self-assessment.

Parameters
  • handle — Engine handle.
  • prompt_out out — Output: diagnostic prompt string. Caller must free with entropic_free().
  • handle — Engine handle returned by entropic_create.
  • prompt_out — Out-param: newly allocated JSON string (caller owns; free with entropic_free).
Returns
  • ENTROPIC_OK on success. ENTROPIC_ERROR_INVALID_HANDLE — handle is NULL.
  • ENTROPIC_OK on success, error code on failure.
threadsafety
Serialized per-handle.

Enums

entropic_residency_event_t

Reasons fired by entropic_residency_observer_t .

Stable contract — values are part of the C ABI. New reasons are appended; existing values do not change.

  • ENTROPIC_RESIDENCY_LOADED 0
  • ENTROPIC_RESIDENCY_EVICTED 1
  • ENTROPIC_RESIDENCY_ACTIVATION_SWAP 2

ent_decision_t

Consumer decision returned from delegation callbacks.

Used by both ent_delegation_start_cb (gate the delegation before it runs) and ent_delegation_complete_cb (decide what to do with the resulting patch).

  • ENT_DECISION_ACCEPT 0
  • ENT_DECISION_REJECT 1

ent_path_access_t

What a filesystem tool is about to do with a path.

read_file and list_directory READ; write_file and edit_file WRITE.

  • ENT_PATH_ACCESS_READ 0
  • ENT_PATH_ACCESS_WRITE 1

entropic_mcp_access_level_t

Access level enum for MCP authorization.

  • ENTROPIC_MCP_ACCESS_NONE 0
  • ENTROPIC_MCP_ACCESS_READ 1
  • ENTROPIC_MCP_ACCESS_WRITE 2

Types

typedef void(* entropic_residency_observer_t) (entropic_residency_event_t event, const char *tier_name, const char *model_path, size_t footprint_bytes, void *user_data) hook point

Residency observer callback.

Fires from the engine thread synchronously with the corresponding orchestrator lifecycle transition, while the residency-set mutex is held. The callback MUST NOT call back into entropic on the same handle — keep it short (log / counter increment / queue-and-return).

Parameters
  • event — One of entropic_residency_event_t.
  • tier_name — Tier whose backing model entered/left VRAM. NUL-terminated, valid only for the callback's duration.
  • model_path — Resolved GGUF path for the model. NUL-terminated, valid only for the callback's duration.
  • footprint_bytes — Tracked VRAM footprint (weights + KV + headroom estimate). 0 if the engine could not estimate.
  • user_data — Opaque pointer registered alongside the callback.

typedef ent_delegation_request_t

typedef ent_delegation_result_t

typedef ent_decision_t(* ent_delegation_start_cb) (const ent_delegation_request_t *req, void *user_data) hook point

Callback fired before a delegation runs.

The consumer can return ENT_DECISION_REJECT to abort the delegation before any child loop runs (defense-in-depth gate for user consent or policy enforcement). On REJECT the engine records a failure result and returns control to the parent loop without spawning a child.

Parameters
  • req — Request descriptor (engine-owned, callback-scoped).
  • user_data — Pointer passed to entropic_set_delegation_callbacks.
Returns
ENT_DECISION_ACCEPT to proceed, ENT_DECISION_REJECT to abort.

typedef ent_decision_t(* ent_delegation_complete_cb) (const ent_delegation_result_t *res, void *user_data) hook point

Callback fired after a delegation produces a patch.

Invoked once per delegation (and once per pipeline as a whole — the pipeline shares a single sandbox). The engine discards the sandbox directory regardless of the consumer's return value.

Parameters
  • res — Result descriptor (engine-owned, callback-scoped).
  • user_data — Pointer passed to entropic_set_delegation_callbacks.
Returns
ENT_DECISION_ACCEPT if the consumer took responsibility for the patch (the engine simply discards the sandbox); ENT_DECISION_REJECT to dump the patch to the pending dir for later inspection.

typedef ent_path_approval_request_t

typedef ent_decision_t(* ent_path_approval_cb) (const ent_path_approval_request_t *req, void *user_data) hook point

Host decision for one outside-root filesystem access.

Consulted only under mcp.filesystem.allow_outside_root: optional (the default), and only for a path that is outside the root AND matches neither outside_root_deny (always refused, never asked) nor outside_root_allow (always served, never asked). One call per tool call — the engine remembers nothing between them.

Parameters
  • req — Request descriptor (engine-owned, callback-scoped).
  • user_data — Pointer passed to entropic_set_path_approval_callback.
Returns
ENT_DECISION_ACCEPT to serve this one access; ENT_DECISION_REJECT to refuse it — the model then receives a tool error beginning outside_root_rejected:.

typedef void(* ent_validation_attempt_boundary_cb) (int attempt_n, void *user_data) hook point

Stream-side callback fired between constitutional revision passes.

Lets consumers split rendered output between attempt N and attempt N+1 cleanly instead of inferring boundaries from rejection timing. Fires immediately before the engine begins re-streaming a revised attempt.

Parameters
  • attempt_n — Index of the attempt about to start (1-based — the first revision pass after the original generation is N=1).
  • user_data — Pointer passed to entropic_set_attempt_boundary_cb.

typedef int(* entropic_compactor_fn) (const char *messages_json, const char *config_json, char **out_messages, char **out_summary, void *user_data) hook point

Compactor function type.

A compactor takes a JSON array of messages, a configuration JSON, and produces a compacted JSON array of messages plus a summary string.

Parameters
  • messages_json — JSON array of messages to compact.
  • config_json — Compaction configuration (threshold, identity, etc.).
  • out_messages — Output: compacted messages JSON. Caller frees with entropic_free().
  • out_summary — Output: summary text. Caller frees with entropic_free(). May be NULL.
  • user_data — Opaque pointer from registration.
Returns
0 on success, non-zero on failure.

typedef struct entropic_logprob_result entropic_logprob_result_t

Per-token log-probability result.

Contains per-token log-probabilities for a sequence evaluated against a loaded model. The logprobs array has (n_tokens - 1) entries: logprobs[i] is the log-probability of tokens[i+1] given tokens[0..i]. The struct itself is caller-owned (stack or heap). The internal logprobs and tokens arrays are engine-allocated and must be freed via entropic_free_logprob_result().

Variables

ENTROPIC_EXPORT entropic_error_t

ent_delegation_request_t

Request describing a delegation that is about to run.

const char* ent_delegation_request_t::delegation_id

Short id ("d1", "d2", "pipeline")

const char* ent_delegation_request_t::target_tier

Tier name (e.g. "researcher")

const char* ent_delegation_request_t::task

Task description text.

int ent_delegation_request_t::depth

Delegation depth (1 = top-level child)

int ent_delegation_request_t::is_pipeline

1 for pipeline stages, 0 for single

ent_delegation_result_t

Result of a finalized delegation, delivered to the consumer.

const char* ent_delegation_result_t::delegation_id

Short id (matches request)

const char* ent_delegation_result_t::target_tier

Tier that executed.

int ent_delegation_result_t::success

1 if child reached COMPLETE, 0 otherwise

const char* ent_delegation_result_t::summary

Final summary text from the child.

const char* ent_delegation_result_t::patch

Unified diff (may be empty string)

size_t ent_delegation_result_t::patch_len

Byte length of patch (excluding NUL)

const char* const* ent_delegation_result_t::files_touched

NULL-terminated array of relpaths.

size_t ent_delegation_result_t::files_touched_len

Count (excluding the NULL terminator)

ent_path_approval_request_t

One filesystem access OUTSIDE the project root, awaiting the host's decision.

const char* ent_path_approval_request_t::path

Canonical absolute path outside the root.

const char* ent_path_approval_request_t::root

Canonical project root it lies outside.

const char* ent_path_approval_request_t::tool

Fully-qualified tool ("filesystem.write_file")

ent_path_access_t ent_path_approval_request_t::access

READ or WRITE.

const char* ent_path_approval_request_t::session_key

Session running the call ("" = default)

entropic_logprob_result

Per-token log-probability result.

float* entropic_logprob_result::logprobs

Per-token log-probabilities (N-1 values).

Engine-allocated.

int32_t* entropic_logprob_result::tokens

Input tokens echoed back (N values).

Engine-allocated.

float entropic_logprob_result::perplexity

exp(-mean(logprobs)) over the sequence.

float entropic_logprob_result::total_logprob

Sum of all logprob values.

int entropic_logprob_result::n_tokens

Number of input tokens.

int entropic_logprob_result::n_logprobs

Number of logprob values (n_tokens - 1).