Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::AgentEngine Class Reference

Core agent execution engine. More...

#include <entropic/core/engine.h>

Classes

struct  DelegationCallbacks
 Grouped consumer-registered delegation callbacks (gh#29). More...
 

Public Member Functions

 AgentEngine (const InferenceInterface &inference, const LoopConfig &loop_config, const CompactionConfig &compaction_config)
 Construct an agent engine.
 
std::vector< Messagerun (std::vector< Message > messages)
 Run the engine on a set of messages.
 
void set_callbacks (const EngineCallbacks &callbacks)
 Set callback functions for loop events.
 
void set_tool_executor (const ToolExecutionInterface &tool_exec)
 Set the tool execution interface.
 
void set_tier_resolution (const TierResolutionInterface &tier_res)
 Set the tier resolution interface for delegation.
 
void set_storage (const StorageInterface &storage)
 Set the storage interface for persistence.
 
void set_hooks (const HookInterface &hooks)
 Set the hook dispatch interface.
 
void set_project_dir (const std::filesystem::path &project_dir)
 Set the configured project directory (gh#31, v2.1.6).
 
void set_stream_observer (TokenCallback observer, void *user_data)
 Set the global stream observer.
 
void set_validation_provider (char *(*provider)(void *), void *user_data)
 Register a JSON provider for the validation block in ON_COMPLETE hook context.
 
void set_delegation_callbacks (ent_decision_t(*on_start)(const ent_delegation_request_t *, void *), ent_decision_t(*on_complete)(const ent_delegation_result_t *, void *), void *user_data)
 Register delegation start/complete callbacks (gh#29, v2.1.5).
 
DelegationCallbacks delegation_callbacks_snapshot () const
 Atomically snapshot the registered delegation callbacks.
 
void set_external_interrupt (void(*cb)(void *user_data), void *user_data)
 Register a callback invoked alongside interrupt().
 
void run_loop (LoopContext &ctx)
 Run the engine loop on a pre-built context.
 
const TierResolutionInterfacetier_resolution () const
 Get the tier resolution interface.
 
void interrupt ()
 Interrupt the running loop (thread-safe).
 
void reset_interrupt ()
 Reset interrupt flag for next run.
 
void pause ()
 Pause generation (thread-safe).
 
void cancel_pause ()
 Cancel pause and interrupt completely.
 
std::pair< int, int > context_usage (const std::vector< Message > &messages) const
 Get context usage for a message list.
 
EngineCallbackscallbacks ()
 Get mutable reference to engine callbacks.
 
const LoopConfigloop_config () const
 Get loop configuration.
 
DirectiveProcessordirective_processor ()
 Get directive processor for external hook wiring.
 
LoopMetrics last_loop_metrics () const
 Get metrics from the most recent completed run.
 
std::unordered_map< std::string, LoopMetricsper_tier_metrics () const
 Per-tier aggregated metrics since engine start.
 
void set_system_prompt (const std::string &prompt)
 Set the system prompt for conversation state.
 
void set_session_logger (SessionLogger *logger)
 Set session logger for model transcript logging.
 
std::vector< Messagerun_turn (const std::string &input)
 Run a single conversation turn (stateful).
 
std::vector< Messagerun_turn (std::vector< Message > new_messages)
 Run a single conversation turn from a pre-built message list (gh#37).
 
void seed_system_prompt (const std::vector< Message > &new_messages)
 Prepend the configured system prompt if this turn needs it.
 
bool prepare_next_turn (std::vector< Message > &pending)
 Pull the next queued user message into pending (gh#40).
 
int run_streaming (const std::string &input, TokenCallback on_token, void *user_data, int *cancel_flag)
 Run a streaming conversation turn (stateful).
 
int run_streaming (std::vector< Message > new_messages, TokenCallback on_token, void *user_data, int *cancel_flag)
 Streaming conversation turn from a pre-built message list (gh#37).
 
void clear_conversation ()
 Clear conversation history.
 
size_t message_count () const
 Get conversation message count.
 
const std::vector< Message > & get_messages () const
 Get conversation messages (read-only).
 
bool queue_user_message (const std::string &message)
 Append a user message to the mid-gen queue.
 
size_t user_message_queue_depth () const
 Snapshot of the queue depth.
 
void clear_user_message_queue ()
 Drop all queued user messages.
 
void set_message_queue_capacity (int cap)
 Set the runtime capacity of the mid-gen queue.
 
bool is_running () const
 Whether a top-level run_turn is currently in progress.
 
void set_queue_observer (void(*observer)(const char *, size_t, void *), void *user_data)
 Register an observer that fires when a queued user message is consumed and seeded as the next turn.
 
void set_state_observer (void(*observer)(int state, void *user_data), void *user_data)
 Register a persistent state-transition observer.
 
ToolExecutorHooks build_directive_hooks ()
 Build ToolExecutorHooks wired to this engine's DirectiveProcessor.
 
void set_tier_info (const std::string &name, const ChildContextInfo &info)
 Store pre-resolved tier context info.
 
void set_relay_single_delegate (const std::string &name)
 Mark a tier as relay-on-single-delegate.
 
void set_handoff_rules (const std::unordered_map< std::string, std::vector< std::string > > &rules)
 Store handoff rules for tier delegation.
 
bool tier_requires_explicit_completion (const std::string &tier) const
 Check if a tier requires an explicit entropic.complete / entropic.delegate tool call to conclude its turn.
 
bool is_delegation_cycle (const LoopContext &ctx, const std::string &target) const
 Check whether pending delegation would close a cycle.
 
bool is_delegation_repeat_blocked (const LoopContext &ctx, const std::string &target) const
 Predicate: should this delegation be blocked because the same target has just failed too many times? (gh#64)
 
int64_t seconds_since_last_activity () const
 gh#35: seconds since the engine last serviced a run().
 
bool fold_complete_into_assistant (LoopContext &ctx, const Message &tool_result_msg) const
 gh#68 (v2.3.4): fold entropic.complete summary into the prior assistant message, suppressing the JSON tool-result user message that would otherwise land in history.
 

Static Public Attributes

static constexpr int MAX_DELEGATION_DEPTH = 2
 Max delegation nesting depth (0=root, 1=child, 2=max).
 

Detailed Description

Core agent execution engine.

Owns all engine subsystems: ResponseGenerator, ContextManager, CompactionManager, DirectiveProcessor. Implements the agentic loop (plan-act-observe-repeat) with proper state management and termination conditions.

Version
1.8.6

Definition at line 62 of file engine.h.

Constructor & Destructor Documentation

◆ AgentEngine()

entropic::AgentEngine::AgentEngine ( const InferenceInterface &  inference,
const LoopConfig loop_config,
const CompactionConfig compaction_config 
)

Construct an agent engine.

Parameters
inferenceInference interface (function pointers).
loop_configLoop configuration.
compaction_configCompaction configuration.
Version
1.8.4
Parameters
inferenceInference interface.
loop_configLoop configuration.
compaction_configCompaction configuration.

Definition at line 133 of file engine.cpp.

Member Function Documentation

◆ build_directive_hooks()

ToolExecutorHooks entropic::AgentEngine::build_directive_hooks ( )

Build ToolExecutorHooks wired to this engine's DirectiveProcessor.

Returns hooks with process_directives bridged to directive_processor(). Eliminates the need for facade bridge functions.

Returns
Configured ToolExecutorHooks.
Version
2.0.2
Returns
Configured hooks.

Definition at line 2934 of file engine.cpp.

◆ callbacks()

EngineCallbacks & entropic::AgentEngine::callbacks ( )
inline

Get mutable reference to engine callbacks.

Used by ToolExecutor which holds a reference that survives set_callbacks() reassignment (same pattern as ResponseGenerator).

Returns
Reference to internal callbacks member. @utility
Version
2.0.1

Definition at line 304 of file engine.h.

◆ cancel_pause()

void entropic::AgentEngine::cancel_pause ( )

Cancel pause and interrupt completely.

Cancel pause and interrupt.

Version
1.8.4

Definition at line 862 of file engine.cpp.

◆ clear_conversation()

void entropic::AgentEngine::clear_conversation ( )

Clear conversation history.

Version
2.0.2

Definition at line 2786 of file engine.cpp.

◆ clear_user_message_queue()

void entropic::AgentEngine::clear_user_message_queue ( )

Drop all queued user messages.

Drop all queued messages atomically.

@threadsafety Thread-safe.

Version
2.1.10

Definition at line 2847 of file engine.cpp.

◆ context_usage()

std::pair< int, int > entropic::AgentEngine::context_usage ( const std::vector< Message > &  messages) const

Get context usage for a message list.

Get context usage.

Parameters
messagesMessage list.
Returns
(tokens_used, max_tokens).
Version
1.8.4
Parameters
messagesMessage list.
Returns
(tokens_used, max_tokens).

Definition at line 875 of file engine.cpp.

◆ delegation_callbacks_snapshot()

AgentEngine::DelegationCallbacks entropic::AgentEngine::delegation_callbacks_snapshot ( ) const

Atomically snapshot the registered delegation callbacks.

Hot path is execute_pending_delegation / execute_pending_pipeline: they grab the triple under the mutex once and pass it forward to the per-call DelegationManager. Prevents a torn read where the consumer reassigns the callbacks mid-delegation. (Hardening landed alongside the 2.1.5 verification pass.)

Returns
Copy of the current callback struct. @utility
Version
2.1.5
Returns
Copy of the current callback triple.

Definition at line 249 of file engine.cpp.

◆ directive_processor()

DirectiveProcessor & entropic::AgentEngine::directive_processor ( )
inline

Get directive processor for external hook wiring.

Returns
Reference to internal directive processor. @utility
Version
2.0.1

Definition at line 320 of file engine.h.

◆ fold_complete_into_assistant()

bool entropic::AgentEngine::fold_complete_into_assistant ( LoopContext ctx,
const Message tool_result_msg 
) const

gh#68 (v2.3.4): fold entropic.complete summary into the prior assistant message, suppressing the JSON tool-result user message that would otherwise land in history.

gh#68 fold logic — see header.

Returns true when the message was folded (caller should NOT push it). Returns false when the message should be pushed as-is.

Conservative — only folds when ALL of:

  1. msg.metadata["tool_name"] == "entropic.complete"
  2. ctx.messages.back() exists and has role == "assistant"
  3. that assistant message has empty content (typically the post-strip body when the model emitted only a tool_call)
  4. ctx.metadata["explicit_completion_summary"] is populated (set by dir_complete before this runs)

If the model also emitted prose around the tool_call, the assistant body is non-empty and we leave both messages alone to avoid silently overwriting legitimate text.

Public so unit tests can exercise the predicate without spinning the full engine loop + mocking the tool executor.

@utility

Version
2.3.4

@utility

Version
2.3.7

Definition at line 710 of file engine.cpp.

◆ get_messages()

const std::vector< Message > & entropic::AgentEngine::get_messages ( ) const

Get conversation messages (read-only).

Get conversation messages.

Returns
Const reference to message vector.
Version
2.0.2
Returns
Const reference to messages.

Definition at line 2807 of file engine.cpp.

◆ interrupt()

void entropic::AgentEngine::interrupt ( )

Interrupt the running loop (thread-safe).

Interrupt the running loop.

Version
1.8.4

Callable from any thread and polled per-token on the generation path, so interrupt() runs many times for a single Ctrl+C. Log only on the 0→1 transition to avoid flooding the session log. (P1-4, 2.0.6-rc16)

Definition at line 808 of file engine.cpp.

◆ is_delegation_cycle()

bool entropic::AgentEngine::is_delegation_cycle ( const LoopContext ctx,
const std::string &  target 
) const

Check whether pending delegation would close a cycle.

Detect delegation cycles via ancestor chain check.

Exposed for unit tests. (P1-9, 2.0.6-rc16)

Parameters
ctxLoop context (ancestor chain + locked tier).
targetProposed delegation target tier.
Returns
true if target is already in the ancestor chain or matches the active locked_tier. @utility
Version
2.0.6-rc16

Targets already present in delegation_ancestor_tiers or matching the active locked_tier would re-enter an ancestor loop, which the depth cap only catches after repeated waste. (P1-9, 2.0.6-rc16)

Parameters
ctxLoop context.
targetPending delegation target tier name.
Returns
true if target would close a cycle. @utility
Version
2.0.6-rc16

Definition at line 684 of file engine.cpp.

◆ is_delegation_repeat_blocked()

bool entropic::AgentEngine::is_delegation_repeat_blocked ( const LoopContext ctx,
const std::string &  target 
) const

Predicate: should this delegation be blocked because the same target has just failed too many times? (gh#64)

gh#64: predicate for the consecutive-failure cap.

Returns true when target matches ctx.last_failed_delegation_target and ctx.consecutive_failed_delegations >= loop_config_.max_consecutive_failed_delegations. Exposed so tests can exercise the guard without spinning a full child loop.

Parameters
ctxActive loop context.
targetProposed delegation target tier.
Returns
true if the delegation should be rejected before dispatch. @utility
Version
2.3.0

See header. @utility

Version
2.3.0

Definition at line 698 of file engine.cpp.

◆ is_running()

bool entropic::AgentEngine::is_running ( ) const
inline

Whether a top-level run_turn is currently in progress.

Used by the facade to reject entropic_queue_user_message with ENTROPIC_ERROR_INVALID_STATE when there is no in-flight turn to "queue behind." Thread-safe (atomic load).

Returns
true while a top-level run_turn is executing. @utility
Version
2.1.10

Definition at line 539 of file engine.h.

◆ last_loop_metrics()

LoopMetrics entropic::AgentEngine::last_loop_metrics ( ) const
inline

Get metrics from the most recent completed run.

Returns a copy of the LoopMetrics snapped at the end of the last call to run() or run_turn(). Zero-initialized before any run has completed. Thread-safe: read-only copy is returned. (P2-15)

Returns
LoopMetrics from last run. @utility
Version
2.0.6-rc16

Definition at line 333 of file engine.h.

◆ loop_config()

const LoopConfig & entropic::AgentEngine::loop_config ( ) const
inline

Get loop configuration.

Returns
Const reference to loop config. @utility
Version
2.0.1

Definition at line 312 of file engine.h.

◆ message_count()

size_t entropic::AgentEngine::message_count ( ) const

Get conversation message count.

Returns
Number of messages.
Version
2.0.2
Returns
Number of messages.

Definition at line 2797 of file engine.cpp.

◆ pause()

void entropic::AgentEngine::pause ( )

Pause generation (thread-safe).

Pause generation.

Version
1.8.4

Definition at line 852 of file engine.cpp.

◆ per_tier_metrics()

std::unordered_map< std::string, LoopMetrics > entropic::AgentEngine::per_tier_metrics ( ) const
inline

Per-tier aggregated metrics since engine start.

Keys are tier names ("lead", "eng", etc.). Values accumulate iterations/tool_calls/tokens_used/errors and sum duration_ms across every run_loop entered with that locked_tier. Empty map before any run. (P2-15 follow-up, 2.0.6-rc16.2)

Returns
Copy of the per-tier metrics map. @utility
Version
2.0.6-rc16.2

Definition at line 348 of file engine.h.

◆ prepare_next_turn()

bool entropic::AgentEngine::prepare_next_turn ( std::vector< Message > &  pending)

Pull the next queued user message into pending (gh#40).

Extracted from run_turn's drain loop. Pops one queued message, fires ON_QUEUE_CONSUMED, and replaces pending with it.

Parameters
pendingOut: cleared and set to the next user turn.
Returns
true if a queued message was dequeued; false if empty.
Parameters
pendingOut: cleared and set to the next user turn.
Returns
true if a queued message was dequeued; false if empty.

Definition at line 2603 of file engine.cpp.

◆ queue_user_message()

bool entropic::AgentEngine::queue_user_message ( const std::string &  message)

Append a user message to the mid-gen queue.

Enqueue a user message subject to the configured cap.

Bounded FIFO. Enforces LoopConfig::message_queue_capacity. Drained between top-level run_turn invocations from inside run_turn itself — never at child-delegation boundaries.

Parameters
messageUser input to enqueue.
Returns
true if enqueued; false if the queue is at capacity. @threadsafety Thread-safe.
Version
2.1.10

Definition at line 2818 of file engine.cpp.

◆ reset_interrupt()

void entropic::AgentEngine::reset_interrupt ( )

Reset interrupt flag for next run.

Reset interrupt flag.

Version
1.8.4

Definition at line 843 of file engine.cpp.

◆ run()

std::vector< Message > entropic::AgentEngine::run ( std::vector< Message messages)

Run the engine on a set of messages.

Run the engine on initial messages.

Parameters
messagesInitial messages (system + user).
Returns
Final messages including all generated content.
Version
1.8.4
Parameters
messagesSystem + user messages.
Returns
Final messages.

Definition at line 370 of file engine.cpp.

◆ run_loop()

void entropic::AgentEngine::run_loop ( LoopContext ctx)

Run the engine loop on a pre-built context.

Used by DelegationManager for child loops. Public so the delegation manager (same .so) can invoke it.

Parameters
ctxLoop context to execute.
Version
1.8.6
Parameters
ctxLoop context to execute.

Definition at line 342 of file engine.cpp.

◆ run_streaming() [1/2]

int entropic::AgentEngine::run_streaming ( const std::string &  input,
TokenCallback  on_token,
void *  user_data,
int *  cancel_flag 
)

Run a streaming conversation turn (stateful).

Same as run_turn but with streaming token output. Owns the StreamThinkFilter, cancel polling, and session logger wiring.

Parameters
inputUser input string.
on_tokenConsumer token callback (receives filtered UTF-8).
user_dataConsumer callback context.
cancel_flagPolled per-token, nullable.
Returns
0 on success, 1 if cancelled, 2 on error.
Version
2.0.2
Parameters
inputUser input.
on_tokenConsumer callback (filtered, UTF-8 aligned).
user_dataConsumer context.
cancel_flagPolled per-token, nullable.
Returns
0=OK, 1=cancelled, 2=error.

Definition at line 2656 of file engine.cpp.

◆ run_streaming() [2/2]

int entropic::AgentEngine::run_streaming ( std::vector< Message new_messages,
TokenCallback  on_token,
void *  user_data,
int *  cancel_flag 
)

Streaming conversation turn from a pre-built message list (gh#37).

Multimodal-aware streaming run_turn overload (gh#37, v2.1.8).

Multimodal-aware streaming overload. Same content_parts preservation semantics as run_turn(vector<Message>), with token callback wiring identical to the single-string streaming variant.

Parameters
new_messagesMessages to add this turn.
on_tokenConsumer token callback (filtered UTF-8).
user_dataConsumer callback context.
cancel_flagPolled per-token, nullable.
Returns
0 on success, 1 if cancelled, 2 on error.
Version
2.1.8

Mirrors the single-string streaming variant — same stream filter, cancel polling, session logger wiring — but consumes a pre-built message list with content_parts preserved.

Parameters
new_messagesMessages to add this turn.
on_tokenFiltered token callback.
user_dataConsumer context.
cancel_flagPer-token cancel poll, nullable.
Returns
0=OK, 1=cancelled, 2=error.

Definition at line 2735 of file engine.cpp.

◆ run_turn() [1/2]

std::vector< Message > entropic::AgentEngine::run_turn ( const std::string &  input)

Run a single conversation turn (stateful).

Manages conversation history internally. Appends user message, runs the agentic loop, appends result messages.

Parameters
inputUser input string.
Returns
Full result messages from engine.
Version
2.0.2

gh#40 (v2.1.10): after the agent loop reaches top-level COMPLETE, drains any messages enqueued mid-generation via queue_user_message as additional turns under the same call.

Parameters
inputUser input string.
Returns
Result messages from engine.

Definition at line 2523 of file engine.cpp.

◆ run_turn() [2/2]

std::vector< Message > entropic::AgentEngine::run_turn ( std::vector< Message new_messages)

Run a single conversation turn from a pre-built message list (gh#37).

Run a stateful turn, draining any queued user messages (gh#40).

Multimodal-aware overload. Each message in new_messages is appended to the engine's conversation history with its content_parts preserved (no string flattening). The agentic loop runs over the full conversation; replies are appended to history and returned.

If the conversation is currently empty AND none of new_messages carries role == "system", the engine prepends its configured system_prompt_ first — matching the single-string overload's behavior.

Parameters
new_messagesMessages to add this turn (typically one user message; may include a system message on first turn).
Returns
Full result messages from the engine loop.
Version
2.1.8
Parameters
new_messagesMessages to add this turn.
Returns
Full result messages from the engine loop.

Definition at line 2622 of file engine.cpp.

◆ seconds_since_last_activity()

int64_t entropic::AgentEngine::seconds_since_last_activity ( ) const

gh#35: seconds since the engine last serviced a run().

gh#35: idle accessor.

Updated at the entry of every run()/run_turn() call. Hosts that want an idle-exit policy poll this and tear down the engine when the value exceeds their threshold. Returned as int64 (epoch seconds delta) so consumers can compare against any unit.

Returns
Seconds since last activity. Returns 0 if no run has ever happened (no activity to be idle relative to). @utility
Version
2.3.0

See header. @utility

Version
2.3.0

Definition at line 730 of file engine.cpp.

◆ seed_system_prompt()

void entropic::AgentEngine::seed_system_prompt ( const std::vector< Message > &  new_messages)

Prepend the configured system prompt if this turn needs it.

Multimodal-aware run_turn overload (gh#37, v2.1.8).

Extracted from run_turn to keep it knots-clean. Seeds conversation_ with system_prompt_ only when the conversation is empty and the caller didn't supply its own system message.

Parameters
new_messagesThe messages the caller is adding this turn.

Takes a pre-built list of messages and preserves their content_parts end-to-end (no string flattening). Each input message is appended verbatim to the engine's conversation history before the agent loop runs. If the conversation is empty and the caller did not supply a system message, the engine's configured system_prompt_ is prepended first — matching the single-string overload's first-turn behavior.

Parameters
new_messagesMessages to add this turn.
Returns
Result messages from the loop.

Prepend the configured system prompt if this turn needs it.

Parameters
new_messagesThe messages the caller is adding this turn.

Definition at line 2581 of file engine.cpp.

◆ set_callbacks()

void entropic::AgentEngine::set_callbacks ( const EngineCallbacks callbacks)

Set callback functions for loop events.

Parameters
callbacksCallback configuration.
Version
1.8.4
Parameters
callbacksCallback configuration.

Definition at line 158 of file engine.cpp.

◆ set_delegation_callbacks()

void entropic::AgentEngine::set_delegation_callbacks ( ent_decision_t(*)(const ent_delegation_request_t *, void *)  on_start,
ent_decision_t(*)(const ent_delegation_result_t *, void *)  on_complete,
void *  user_data 
)

Register delegation start/complete callbacks (gh#29, v2.1.5).

Replaces the pre-2.1.5 silent auto-merge-to-parent behavior. The engine stores these C-style function pointers and forwards them into every DelegationManager it constructs (one per pending delegation or pipeline). Null callbacks are honored: on_start null = always ACCEPT; on_complete null = default-deny (write patch to ~/.entropic/sandbox/<session>/pending/<id>.patch).

Parameters
on_startPre-delegation gate (nullable clears).
on_completePost-delegation result (nullable clears).
user_dataForwarded to both callbacks.
Version
2.1.5
Parameters
on_startPre-delegation gate (nullable).
on_completePost-delegation result (nullable).
user_dataForwarded to both callbacks.

Definition at line 232 of file engine.cpp.

◆ set_external_interrupt()

void entropic::AgentEngine::set_external_interrupt ( void(*)(void *user_data)  cb,
void *  user_data 
)

Register a callback invoked alongside interrupt().

Register external transport interrupt callback.

Used to propagate Ctrl+C into external MCP transports so in-flight tool calls do not run to completion. Facade wires this to ServerManager::interrupt_external_tools(). (P1-10, 2.0.6-rc16)

Parameters
cbCallback (nullable).
user_dataForwarded to cb.
Version
2.0.6-rc16

Facade wires this to ServerManager::interrupt_external_tools so AgentEngine::interrupt() unwinds tool dispatches within ~100ms. (P1-10, 2.0.6-rc16)

Parameters
cbCallback (nullable).
user_dataForwarded to cb.

Definition at line 832 of file engine.cpp.

◆ set_handoff_rules()

void entropic::AgentEngine::set_handoff_rules ( const std::unordered_map< std::string, std::vector< std::string > > &  rules)

Store handoff rules for tier delegation.

Store handoff rules.

Parameters
rulesMap of source tier → valid target tiers.
Version
2.0.2
Parameters
rulesSource tier → valid targets.

Definition at line 2979 of file engine.cpp.

◆ set_hooks()

void entropic::AgentEngine::set_hooks ( const HookInterface &  hooks)

Set the hook dispatch interface.

Parameters
hooksHook dispatch interface (wired by facade).
Version
1.9.1
Parameters
hooksHook dispatch interface.

Definition at line 201 of file engine.cpp.

◆ set_message_queue_capacity()

void entropic::AgentEngine::set_message_queue_capacity ( int  cap)

Set the runtime capacity of the mid-gen queue.

Update the runtime cap (in-place on LoopConfig).

If cap is less than the current depth, excess pending messages are kept (no truncation) but no new enqueues succeed until the queue drains below the new cap. cap of 0 disables enqueue while leaving the queue otherwise functional.

Parameters
capNew capacity. @threadsafety Thread-safe.
Version
2.1.10

Definition at line 2861 of file engine.cpp.

◆ set_project_dir()

void entropic::AgentEngine::set_project_dir ( const std::filesystem::path &  project_dir)

Set the configured project directory (gh#31, v2.1.6).

Store the project_dir resolved by entropic_configure_dir.

The facade calls this from entropic_configure_dir after the layered config loader has resolved the project root. get_repo_dir() uses this value in preference to std::filesystem::current_path(), so consumers whose launcher cwd differs from the target project (the common case for wrapper CLIs and IDE plugins) still snapshot the right tree into the sandbox.

Pre-2.1.6 the engine used CWD unconditionally, silently ignoring the project_dir argument to entropic_configure_dir. Setting an empty path resets the override so get_repo_dir() falls back to CWD (preserves the no-configure-dir caller's behavior).

Parameters
project_dirProject root (empty resets to CWD fallback). @threadsafety Serialized per-handle via the facade's api_mutex.
Version
2.1.6

gh#31 (v2.1.6). See engine.h for rationale. Resets the cache so a subsequent get_repo_dir() call picks up the new value even if a previous lookup already settled on the CWD fallback.

Parameters
project_dirProject root (empty resets to CWD fallback).

Definition at line 2329 of file engine.cpp.

◆ set_queue_observer()

void entropic::AgentEngine::set_queue_observer ( void(*)(const char *, size_t, void *)  observer,
void *  user_data 
)

Register an observer that fires when a queued user message is consumed and seeded as the next turn.

Persistent slot setter; survives set_callbacks() shuffles.

Persistent across set_callbacks() reassignments — the streaming entry points overwrite the EngineCallbacks struct per-call, so the queue observer needs a dedicated slot to survive both streaming and non-streaming runs.

Parameters
observerCallback (consumed_text, remaining_depth, ud). Pass nullptr to clear.
user_dataForwarded to observer. @threadsafety Thread-safe.
Version
2.1.10

Definition at line 2900 of file engine.cpp.

◆ set_relay_single_delegate()

void entropic::AgentEngine::set_relay_single_delegate ( const std::string &  name)

Mark a tier as relay-on-single-delegate.

When this tier is the active (lead) tier and exactly one delegate completes successfully, the delegate's summary is used as the final output without lead re-generating. Avoids redundant re-synthesis of already user-ready delegate responses.

Parameters
nameTier name (typically "lead").
Version
2.0.11
Parameters
nameTier name.

Definition at line 2969 of file engine.cpp.

◆ set_session_logger()

void entropic::AgentEngine::set_session_logger ( SessionLogger log)

Set session logger for model transcript logging.

Parameters
loggerNon-owning pointer (nullable). Must outlive engine.
Version
2.0.2
Parameters
logNon-owning pointer (nullable).

Definition at line 2507 of file engine.cpp.

◆ set_state_observer()

void entropic::AgentEngine::set_state_observer ( void(*)(int state, void *user_data)  observer,
void *  user_data 
)

Register a persistent state-transition observer.

Wire the persistent state-observer slot.

The legacy path (EngineCallbacks::on_state_change) is wiped for the duration of run_streaming because that method replaces the full callback struct to install its token sink. This persistent slot survives every set_callbacks() shuffle so consumers (notably the external MCP bridge that the entropic_set_state_observer docstring names) actually see transitions during streaming runs.

Fires alongside the legacy on_state_change slot — neither supersedes the other. Pass nullptr to clear.

Parameters
observerState-change callback.
user_dataForwarded to observer. @threadsafety Thread-safe.
Version
2.1.10

Forwarded to ResponseGenerator so the PAUSED transition that ResponseGenerator emits during handle_pause also reaches the persistent slot. The legacy EngineCallbacks::on_state_change remains supported in parallel for in-tree callers (tests etc.).

Definition at line 2918 of file engine.cpp.

◆ set_storage()

void entropic::AgentEngine::set_storage ( const StorageInterface storage)

Set the storage interface for persistence.

Parameters
storageStorage callbacks (wired by facade). Nullable — engine works without storage (in-memory only mode).
Version
1.8.8
Parameters
storageStorage callbacks (nullable).

Definition at line 190 of file engine.cpp.

◆ set_stream_observer()

void entropic::AgentEngine::set_stream_observer ( TokenCallback  observer,
void *  user_data 
)

Set the global stream observer.

Fires for every token from every generation path — batch entropic_run, entropic_run_streaming, and delegate child-loop generations. Persists across per-call EngineCallbacks reassignment.

Parameters
observerToken callback (nullable clears).
user_dataForwarded to observer.
Version
2.0.6-rc16

Delegates to ResponseGenerator which owns the choke point for every generation path (streaming, batch, and child-loop delegations).

Parameters
observerToken callback (nullable).
user_dataForwarded to observer.

Definition at line 219 of file engine.cpp.

◆ set_system_prompt()

void entropic::AgentEngine::set_system_prompt ( const std::string &  prompt)

Set the system prompt for conversation state.

Parameters
promptAssembled system prompt string.
Version
2.0.2
Parameters
promptAssembled system prompt.

Definition at line 2497 of file engine.cpp.

◆ set_tier_info()

void entropic::AgentEngine::set_tier_info ( const std::string &  name,
const ChildContextInfo info 
)

Store pre-resolved tier context info.

Called at configure time. The engine uses this data for delegation instead of external TierResolutionInterface callbacks.

Parameters
nameTier name.
infoPre-resolved context info (system prompt, tools, etc.).
Version
2.0.2
Parameters
nameTier name.
infoContext info.

Definition at line 2956 of file engine.cpp.

◆ set_tier_resolution()

void entropic::AgentEngine::set_tier_resolution ( const TierResolutionInterface tier_res)

Set the tier resolution interface for delegation.

Set tier resolution interface for delegation.

Parameters
tier_resTier resolution callbacks (wired by facade).
Version
1.8.6
Parameters
tier_resTier resolution callbacks.

Definition at line 179 of file engine.cpp.

◆ set_tool_executor()

void entropic::AgentEngine::set_tool_executor ( const ToolExecutionInterface tool_exec)

Set the tool execution interface.

Parameters
tool_execTool execution interface (wired by facade).
Version
1.8.5
Parameters
tool_execTool execution interface.

Definition at line 168 of file engine.cpp.

◆ set_validation_provider()

void entropic::AgentEngine::set_validation_provider ( char *(*)(void *)  provider,
void *  user_data 
)

Register a JSON provider for the validation block in ON_COMPLETE hook context.

Register validation JSON provider for ON_COMPLETE context.

The callback returns a malloc'd JSON object describing the validator's most recent result: {ran, verdict, violations, revisions_applied} The engine copies and frees the returned buffer. NULL return or nullptr callback means no validation block is emitted. (E3, 2.0.6-rc17)

Parameters
providerJSON builder (nullable clears).
user_dataForwarded to provider.
Version
2.0.6-rc17
Parameters
providerJSON builder callback (nullable).
user_dataForwarded to provider.

Definition at line 261 of file engine.cpp.

◆ tier_requires_explicit_completion()

bool entropic::AgentEngine::tier_requires_explicit_completion ( const std::string &  tier) const

Check if a tier requires an explicit entropic.complete / entropic.delegate tool call to conclude its turn.

Check if a tier contractually requires explicit completion.

Exposed for unit tests. (P1-6, 2.0.6-rc16)

Parameters
tierTier name.
Returns
true if the tier has explicit_completion=true. @utility
Version
2.0.6-rc16

Delegates to the TierResolutionInterface, falling back to false when no resolver is wired (preserves legacy behavior in tests that omit tier metadata).

Parameters
tierTier name.
Returns
true if the tier's explicit_completion flag is set. @utility
Version
2.0.6-rc16.1

Definition at line 663 of file engine.cpp.

◆ tier_resolution()

const TierResolutionInterface & entropic::AgentEngine::tier_resolution ( ) const

Get the tier resolution interface.

Returns
Tier resolution interface reference.
Version
1.8.6
Returns
Tier resolution interface.

Definition at line 273 of file engine.cpp.

◆ user_message_queue_depth()

size_t entropic::AgentEngine::user_message_queue_depth ( ) const

Snapshot of the queue depth.

Read queue depth under the queue mutex.

@threadsafety Thread-safe.

Version
2.1.10

Definition at line 2837 of file engine.cpp.

Member Data Documentation

◆ MAX_DELEGATION_DEPTH

constexpr int entropic::AgentEngine::MAX_DELEGATION_DEPTH = 2
staticconstexpr

Max delegation nesting depth (0=root, 1=child, 2=max).

Version
1.8.6

Definition at line 66 of file engine.h.


The documentation for this class was generated from the following files: