Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
engine.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
24#pragma once
25
26#include <entropic/entropic.h> // for ent_decision_t and ent_delegation_* (gh#29, v2.1.5)
33#include <entropic/core/sandbox.h> // gh#33 (v2.1.6): engine-owned session sandbox
38
39#include <atomic>
40#include <deque>
41#include <filesystem>
42#include <map>
43#include <memory>
44#include <mutex>
45#include <optional>
46#include <string>
47#include <unordered_map>
48#include <unordered_set>
49#include <vector>
50
51#include <nlohmann/json_fwd.hpp> // gh#32 (v2.1.6) resume payload type
52
53namespace entropic {
54
66public:
69 static constexpr int MAX_DELEGATION_DEPTH = 2;
70
78 AgentEngine(const InferenceInterface& inference,
81
93 ent_decision_t (*start)(const ent_delegation_request_t*, void*)
94 = nullptr;
95 ent_decision_t (*complete)(const ent_delegation_result_t*, void*)
96 = nullptr;
97 void* user_data = nullptr;
98 };
99
108 std::vector<Message> run(std::vector<Message> messages,
109 const std::string& tier_override = "");
110
117
124
131
138 void set_storage(const StorageInterface& storage);
139
145 void set_hooks(const HookInterface& hooks);
146
166 void set_project_dir(const std::filesystem::path& project_dir);
167
182
196 void set_dir_swap(ScopedSandbox::SwapDirFn swap_fn, void* user_data);
197
210 std::filesystem::path resolve_session_root(
211 const std::string& session_key);
212
227 SandboxManager* sandbox_for_session(const std::string& session_key);
228
242 std::vector<std::string> isolation_unsafe_tools(
243 const LoopContext& ctx, const std::string& target_tier);
244
256 void set_stream_observer(TokenCallback observer, void* user_data);
257
273 void set_validation_provider(char* (*provider)(void*),
274 void* user_data);
275
294 void* user_data);
295
310
323 void set_external_interrupt(void (*cb)(void* user_data),
324 void* user_data);
325
340 void set_external_reset(void (*cb)(void* user_data),
341 void* user_data);
342
361 void run_loop(LoopContext& ctx, bool inherit_interrupt = false);
362
369
374 void interrupt();
375
380 void reset_interrupt();
381
386 void pause();
387
392 void cancel_pause();
393
400 std::pair<int, int> context_usage(
401 const std::vector<Message>& messages) const;
402
413 EngineCallbacks& callbacks() { return callbacks_; }
414
421 const LoopConfig& loop_config() const { return loop_config_; }
422
429 DirectiveProcessor& directive_processor() { return directive_processor_; }
430
450
469 std::unordered_map<std::string, LoopMetrics> per_tier_metrics() const;
470
471 // ── Conversation state (v2.0.2) ─────────────────────────
472
478 void set_system_prompt(const std::string& prompt);
479
485 void set_session_logger(SessionLogger* logger);
486
497 std::vector<Message> run_turn(const std::string& input);
498
513 std::vector<Message> run_turn_as(const std::string& tier,
514 const std::string& input);
515
536 std::vector<Message> run_turn(std::vector<Message> new_messages);
537
549 void seed_system_prompt(const std::vector<Message>& new_messages);
550
565 std::vector<Message> run_drain_loop(std::string pending,
566 const std::string& tier_override);
567
579 void seed_system_prompt_for_tier(const std::string& tier);
580
592 bool prepare_next_turn(std::vector<Message>& pending);
593
610 int run_streaming(const std::string& input,
611 TokenCallback on_token,
612 void* user_data,
613 int* cancel_flag,
614 const std::string& tier = "");
615
631 int run_streaming(std::vector<Message> new_messages,
632 TokenCallback on_token,
633 void* user_data,
634 int* cancel_flag);
635
640 void clear_conversation();
641
653 size_t message_count() const;
654
665 const std::vector<Message>& get_messages() const;
666
667 // ── Mid-generation user-message queue (gh#40, v2.1.10) ──
668
681 bool queue_user_message(const std::string& message);
682
688 size_t user_message_queue_depth() const;
689
696
710
722 bool is_running() const { return running_flag_.load(); }
723
753 bool try_begin_turn(const std::string& key);
754
768
777 void end_turn(const std::string& key);
778
789 void end_turn();
790
797 std::size_t active_run_count() const;
798
818
825 bool concurrent_sessions() const;
826
844 bool interrupt_session(const std::string& key);
845
853 bool session_interrupted(const std::string& key) const;
854
869 std::atomic<bool>& run_cancel_flag();
870
894 void set_active_session(const std::string& key);
895
910 std::string active_session_key() const;
911
926 std::vector<Message> messages_for(const std::string& key) const;
927
948 bool set_session_messages(const std::string& key,
949 std::vector<Message> messages);
950
958 std::size_t message_count_for(const std::string& key) const;
959
966 void clear_conversation_for(const std::string& key);
967
979 bool drop_session(const std::string& key);
980
987 std::vector<std::string> session_keys() const;
988
1004 void set_queue_observer(
1005 void (*observer)(const char*, size_t, void*),
1006 void* user_data);
1007
1027 void set_state_observer(
1028 void (*observer)(int state, void* user_data),
1029 void* user_data);
1030
1031 // ── Directive hooks (v2.0.2) ────────────────────────────
1032
1043
1044 // ── Per-workspace prompts (gh#179, v2.14.0) ─────────────
1045
1057 void set_workspace_prompts(const std::string& workspace,
1058 WorkspacePrompts prompts);
1059
1066 void clear_workspace_prompts(const std::string& workspace);
1067
1074 void bind_session_workspace(const std::string& session,
1075 const std::string& workspace);
1076
1085 std::string session_system_prompt(const std::string& session) const;
1086
1087 // ── Tier info (v2.0.2) ──────────────────────────────────
1088
1099 void set_tier_info(const std::string& name,
1100 const ChildContextInfo& info);
1101
1112 bool has_tier(const std::string& name) const;
1113
1126 std::vector<std::string> get_tier_allowed_tools(
1127 const std::string& name) const;
1128
1139 const std::string& tier_system_prompt(const std::string& name) const;
1140
1152 void set_relay_single_delegate(const std::string& name);
1153
1159 void set_handoff_rules(
1160 const std::unordered_map<std::string,
1161 std::vector<std::string>>& rules);
1162
1174 const std::string& tier) const;
1175
1188 const LoopContext& ctx, const std::string& target) const;
1189
1206 const LoopContext& ctx, const std::string& target) const;
1207
1222
1250 LoopContext& ctx, const Message& tool_result_msg) const;
1251
1275
1289 CompactionManager& compaction_manager() { return compaction_manager_; }
1290
1291private:
1303 void init_session_conversation(LoopContext& ctx);
1304
1316 void accumulate_run_metrics(LoopContext& ctx);
1317
1330 void accumulate_per_tier(const LoopContext& ctx);
1331
1341 void clear_pause_for_fresh_turn();
1342
1346 mutable std::mutex metrics_mutex_;
1347
1353 void loop(LoopContext& ctx);
1354
1379 void force_iteration_cap_completion(LoopContext& ctx);
1380
1411 void finish_with_carried_output(LoopContext& ctx,
1412 const std::string& reason,
1413 const std::string& stop_noun,
1414 const std::string& terminal_reason);
1415
1421 void execute_iteration(LoopContext& ctx);
1422
1430 void evaluate_no_tool_decision(LoopContext& ctx,
1431 const std::string& content,
1432 const std::string& finish_reason);
1433
1442 bool handle_terminal_finish_reasons(
1443 LoopContext& ctx, const std::string& finish_reason);
1444
1454 bool record_explicit_completion_failure(
1455 LoopContext& ctx, const std::string& finish_reason);
1456
1469 void finalize_delegation_result(
1470 LoopContext& ctx, const struct DelegationResult& result);
1471
1479 void relay_partial_result(LoopContext& ctx, const std::string& summary);
1480
1488 void log_relay_status(LoopContext& ctx,
1489 const std::string& terminal_reason = {});
1490
1497 bool should_stop(const LoopContext& ctx) const;
1498
1513 static bool is_terminal_state(const LoopContext& ctx);
1514
1521 void set_state(LoopContext& ctx, AgentState state);
1522
1528 void reinject_context_anchors(LoopContext& ctx);
1529
1534 void register_directive_handlers();
1535
1536 // ── Directive handlers ───────────────────────────────
1537 void dir_stop(LoopContext&, const Directive&, DirectiveResult&);
1538 void dir_tier_change(LoopContext&, const Directive&, DirectiveResult&);
1539 void dir_delegate(LoopContext&, const Directive&, DirectiveResult&);
1540 void dir_pipeline(LoopContext&, const Directive&, DirectiveResult&);
1541 void dir_complete(LoopContext&, const Directive&, DirectiveResult&);
1542 void dir_clear_todos(LoopContext&, const Directive&, DirectiveResult&);
1543 void dir_inject(LoopContext&, const Directive&, DirectiveResult&);
1544 void dir_prune(LoopContext&, const Directive&, DirectiveResult&);
1545 void dir_anchor(LoopContext&, const Directive&, DirectiveResult&);
1546 void dir_phase(LoopContext&, const Directive&, DirectiveResult&);
1547 void dir_notify(LoopContext&, const Directive&, DirectiveResult&);
1548
1555 std::pair<std::string, std::vector<ToolCall>> parse_tool_calls(
1556 const std::string& raw_content);
1557
1568 bool process_tool_results(LoopContext& ctx,
1569 const std::vector<ToolCall>& tool_calls);
1570
1571 // ── Delegation (v1.8.6) ──────────────────────────────
1572
1578 void execute_pending_delegation(LoopContext& ctx);
1579
1593 bool reject_delegation_if_guarded(LoopContext& ctx,
1594 const PendingDelegation& pending);
1595
1609 bool reject_pipeline_if_guarded(LoopContext& ctx,
1610 const PendingPipeline& pending);
1611
1617 void execute_pending_pipeline(LoopContext& ctx);
1618
1627 bool should_auto_chain(const LoopContext& ctx,
1628 const std::string& finish_reason,
1629 const std::string& content);
1630
1639 bool try_auto_chain(LoopContext& ctx,
1640 const std::string& finish_reason,
1641 const std::string& content);
1642
1650 bool fire_pre_hook(entropic_hook_point_t point, int iteration);
1651
1665 void fire_post_generate_hook(GenerateResult& result,
1666 const std::string& tier,
1667 const std::vector<Message>& messages);
1668
1682 void capture_validation_feedback(LoopContext& ctx);
1683
1704 void dispatch_post_generate(LoopContext& ctx,
1705 GenerateResult& result);
1706
1720 void process_generation_result(LoopContext& ctx,
1721 GenerateResult& result);
1722
1734 void dispatch_pending_or_halt(LoopContext& ctx);
1735
1754 void charge_thinking_budget(LoopContext& ctx, size_t content_len,
1755 bool made_tool_call);
1756
1765 int budget_units_consumed(LoopContext& ctx, size_t content_len);
1766
1773 void nudge_budget_completion(LoopContext& ctx);
1774
1791 void hard_cut_budget(LoopContext& ctx);
1792
1805 bool fire_complete_hook(const std::string& summary,
1806 const LoopContext& ctx);
1807
1815 bool fire_delegate_pre_hook(const PendingDelegation& pending,
1816 int depth);
1817
1829 void fire_delegate_complete_hook(const std::string& target,
1830 bool success,
1831 const std::string& summary = "");
1832
1852 std::filesystem::path get_repo_dir();
1853
1860 std::filesystem::path get_repo_dir_locked();
1861
1868 std::string system_prompt_copy() const;
1869
1906 SandboxManager* ensure_sandbox_manager(
1907 const std::filesystem::path& root);
1908
1915 std::pair<ScopedSandbox::SwapDirFn, void*> dir_swap_snapshot() const;
1916
1942 bool resolve_latest_for_target(LoopContext& ctx,
1943 PendingDelegation& pending);
1944
1945 bool resolve_resume_delegation(
1946 LoopContext& ctx,
1947 PendingDelegation& pending,
1948 std::vector<Message>& out_history);
1949
1964 bool fetch_resume_payload(
1965 LoopContext& ctx,
1966 const std::string& id,
1967 nlohmann::json& parsed);
1968
1985 DelegationResult run_pending_delegation(
1986 LoopContext& ctx,
1987 const PendingDelegation& pending,
1988 std::vector<Message> resume_history);
1989
1997 void fire_delegation_start(const LoopContext& ctx,
1998 const std::string& tier,
1999 const std::string& task);
2000
2008 void fire_delegation_complete(const LoopContext& ctx,
2009 const std::string& tier,
2010 const struct DelegationResult& result);
2011
2012 // ── Members ──────────────────────────────────────────
2013 LoopMetrics last_metrics_;
2014 std::unordered_map<std::string, LoopMetrics>
2015 per_tier_metrics_;
2016 InferenceInterface inference_;
2017 LoopConfig loop_config_;
2018 EngineCallbacks callbacks_;
2019 std::atomic<bool> interrupt_flag_{false};
2030 std::atomic<bool> pause_flag_{false};
2031 void (*external_interrupt_cb_)(void*) = nullptr;
2032 void* external_interrupt_data_ = nullptr;
2033 void (*external_reset_cb_)(void*) = nullptr;
2034 void* external_reset_data_ = nullptr;
2035 // ── Delegation callbacks (gh#29, v2.1.5) ────────────────
2040 DelegationCallbacks delegation_cb_;
2041 mutable std::mutex delegation_cb_mutex_;
2042 char* (*validation_provider_)(void*) = nullptr;
2043 void* validation_provider_data_ = nullptr;
2044 std::unordered_map<std::string, std::string> context_anchors_;
2048 mutable std::mutex anchors_mutex_;
2049 ToolExecutionInterface tool_exec_;
2050 TierResolutionInterface tier_res_;
2051 StorageInterface storage_;
2052 DirectiveProcessor directive_processor_;
2053 TokenCounter token_counter_;
2054 CompactionManager compaction_manager_;
2055 ContextManager context_manager_;
2056 ResponseGenerator response_generator_;
2057 HookInterface hooks_;
2058 std::optional<std::filesystem::path> cached_repo_dir_;
2059 bool repo_dir_checked_ = false;
2060 std::filesystem::path project_dir_override_;
2063 std::map<std::filesystem::path, SandboxManager> sandbox_mgrs_;
2064 SessionRootInterface session_root_;
2065 ScopedSandbox::SwapDirFn swap_dir_fn_ = nullptr;
2066 void* swap_dir_data_ = nullptr;
2071 mutable std::mutex sandbox_mutex_;
2072
2073 // ── Mid-generation user-message queue (gh#40, v2.1.10) ──
2074 mutable std::mutex queue_mutex_;
2075 std::deque<std::string> user_message_queue_;
2076 std::atomic<bool> running_flag_{false};
2079 std::atomic<int64_t> last_activity_epoch_s_{0};
2080 void (*queue_observer_)(const char*, size_t, void*) = nullptr;
2081 void* queue_observer_data_ = nullptr;
2084 void (*state_observer_)(int, void*) = nullptr;
2085 void* state_observer_data_ = nullptr;
2096 std::optional<std::string> pop_queued_user_message();
2097
2105 void fire_queue_consumed(const std::string& consumed, size_t remaining);
2106
2107 // ── Conversation state (v2.0.2) ─────────────────────────
2113 ConversationState& active_conversation();
2114
2126 std::unordered_map<std::string, ConversationState> conversations_;
2127
2140 mutable std::mutex conversations_mutex_;
2141
2155 struct RunState {
2156 std::atomic<bool> interrupt{false};
2157 std::string key;
2158 };
2159
2165 mutable std::mutex runs_mutex_;
2166
2168 std::unordered_map<std::string, std::shared_ptr<RunState>> active_runs_;
2169
2172 bool concurrent_sessions_ = true;
2173
2180 std::shared_ptr<RunState> this_thread_run() const;
2181
2188 bool run_interrupted() const;
2189
2196 std::string active_session_key_;
2202 mutable std::mutex session_key_mutex_;
2203 std::string system_prompt_;
2207 mutable std::mutex prompt_mutex_;
2209 std::unordered_map<std::string, WorkspacePrompts> workspace_prompts_;
2211 std::unordered_map<std::string, std::string> session_workspace_;
2212
2221 std::optional<std::string> workspace_prompt_for(const std::string& session,
2222 const std::string& tier) const;
2223 SessionLogger* session_logger_ = nullptr;
2224
2225 // ── Pre-resolved tier data (v2.0.2) ─────────────────────
2226 std::unordered_map<std::string, ChildContextInfo> tier_info_;
2227 std::unordered_map<std::string, std::vector<std::string>> handoff_rules_;
2229 std::unordered_set<std::string> relay_single_delegate_tiers_;
2230
2236 void wire_internal_tier_resolution();
2237
2249 void apply_identity_overrides(LoopContext& ctx);
2250
2265 void begin_loop_preamble(LoopContext& ctx);
2266
2274 int resolve_max_iterations(const LoopContext& ctx) const;
2275
2283 int resolve_max_tool_calls(const LoopContext& ctx) const;
2284
2285 /* ── TierResolutionInterface trampolines (static — accept void* ud) ── */
2294 static ChildContextInfo tri_resolve_tier(
2295 const std::string& name, void* ud);
2304 static bool tri_tier_exists(
2305 const std::string& name, void* ud);
2314 static std::vector<std::string> tri_get_handoff_targets(
2315 const std::string& name, void* ud);
2325 static std::string tri_get_tier_param(
2326 const std::string& name, const std::string& param, void* ud);
2327};
2328
2329} // namespace entropic
Core agent execution engine.
Definition engine.h:65
std::vector< std::string > isolation_unsafe_tools(const LoopContext &ctx, const std::string &target_tier)
Child-visible external tools that break the isolation claim.
Definition engine.cpp:3459
void cancel_pause()
Cancel pause and interrupt completely.
Definition engine.cpp:1406
bool queue_user_message(const std::string &message)
Append a user message to the mid-gen queue.
Definition engine.cpp:4388
void set_external_reset(void(*cb)(void *user_data), void *user_data)
Register the external transport interrupt-release callback.
Definition engine.cpp:1362
CompactionManager & compaction_manager()
Borrowed reference to the engine's built-in CompactionManager.
Definition engine.h:1289
void set_validation_provider(char *(*provider)(void *), void *user_data)
Register a JSON provider for the validation block in ON_COMPLETE hook context.
Definition engine.cpp:270
bool is_delegation_cycle(const LoopContext &ctx, const std::string &target) const
Check whether pending delegation would close a cycle.
Definition engine.cpp:1145
bool try_begin_turn()
Claim a turn for the session bound to THIS thread (gh#158).
Definition engine.h:767
size_t user_message_queue_depth() const
Snapshot of the queue depth.
Definition engine.cpp:4407
std::string session_system_prompt(const std::string &session) const
The untiered system prompt a fresh conversation in session would be seeded with (gh#179).
Definition engine.cpp:3911
std::vector< Message > run(std::vector< Message > messages, const std::string &tier_override="")
Run the engine on a set of messages.
Definition engine.cpp:471
bool interrupt_session(const std::string &key)
Interrupt exactly one session's run (gh#158).
Definition engine.cpp:3728
bool set_session_messages(const std::string &key, std::vector< Message > messages)
Replace one session's conversation wholesale (gh#165, v2.13.0).
Definition engine.cpp:4341
void seed_system_prompt_for_tier(const std::string &tier)
Seed a tier's system prompt on an empty conversation (gh#99).
Definition engine.cpp:3930
void clear_user_message_queue()
Drop all queued user messages.
Definition engine.cpp:4417
const std::vector< Message > & get_messages() const
Get conversation messages (read-only).
Definition engine.cpp:4365
bool prepare_next_turn(std::vector< Message > &pending)
Pull the next queued user message into pending (gh#40).
Definition engine.cpp:4024
void set_callbacks(const EngineCallbacks &callbacks)
Set callback functions for loop events.
Definition engine.cpp:167
std::size_t active_run_count() const
Number of runs currently in flight on this handle (gh#158).
Definition engine.cpp:3679
void seed_system_prompt(const std::vector< Message > &new_messages)
Prepend the configured system prompt if this turn needs it.
Definition engine.cpp:4000
std::vector< Message > run_turn(const std::string &input)
Run a single conversation turn (stateful).
Definition engine.cpp:3782
DelegationCallbacks delegation_callbacks_snapshot() const
Atomically snapshot the registered delegation callbacks.
Definition engine.cpp:258
void set_stream_observer(TokenCallback observer, void *user_data)
Set the global stream observer.
Definition engine.cpp:228
bool session_interrupted(const std::string &key) const
Whether a named session's in-flight run carries an interrupt.
Definition engine.cpp:3751
LoopMetrics last_loop_metrics() const
Get metrics from the most recent completed run.
Definition engine.cpp:581
const LoopConfig & loop_config() const
Get loop configuration.
Definition engine.h:421
std::vector< std::string > session_keys() const
Keys of every session the engine currently holds.
Definition engine.cpp:4318
void set_session_root_interface(const SessionRootInterface &iface)
Inject the session-root / tool-reach seam (gh#160, v2.13.0).
Definition engine.cpp:3376
void set_project_dir(const std::filesystem::path &project_dir)
Set the configured project directory (gh#31, v2.1.6).
Definition engine.cpp:3136
bool is_running() const
Whether a top-level run_turn is currently in progress.
Definition engine.h:722
DirectiveProcessor & directive_processor()
Get directive processor for external hook wiring.
Definition engine.h:429
std::vector< Message > run_drain_loop(std::string pending, const std::string &tier_override)
Shared drain loop for run_turn / run_turn_as (gh#99).
Definition engine.cpp:3954
int run_streaming(const std::string &input, TokenCallback on_token, void *user_data, int *cancel_flag, const std::string &tier="")
Run a streaming conversation turn (stateful).
Definition engine.cpp:4119
void interrupt()
Interrupt the running loop (thread-safe).
Definition engine.cpp:1292
bool concurrent_sessions() const
Whether per-session concurrency is enabled (gh#158).
Definition engine.cpp:3703
void pause()
Pause generation (thread-safe).
Definition engine.cpp:1396
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?...
Definition engine.cpp:1161
void bind_session_workspace(const std::string &session, const std::string &workspace)
Record that session belongs to workspace.
Definition engine.cpp:3873
void clear_conversation_for(const std::string &key)
Clear one session's history, keeping the session itself.
Definition engine.cpp:4290
SandboxManager * sandbox_for_session(const std::string &session_key)
Sandbox manager for a session, or nullptr when isolation is off (gh#160).
Definition engine.cpp:3443
void set_hooks(const HookInterface &hooks)
Set the hook dispatch interface.
Definition engine.cpp:210
void set_tier_resolution(const TierResolutionInterface &tier_res)
Set the tier resolution interface for delegation.
Definition engine.cpp:188
void run_loop(LoopContext &ctx, bool inherit_interrupt=false)
Run the engine loop on a pre-built context.
Definition engine.cpp:408
void set_session_logger(SessionLogger *logger)
Set session logger for model transcript logging.
Definition engine.cpp:3516
const TierResolutionInterface & tier_resolution() const
Get the tier resolution interface.
Definition engine.cpp:282
std::string active_session_key() const
Session whose turn is currently running.
Definition engine.cpp:3575
void set_storage(const StorageInterface &storage)
Set the storage interface for persistence.
Definition engine.cpp:199
std::unordered_map< std::string, LoopMetrics > per_tier_metrics() const
Per-tier aggregated metrics since engine start.
Definition engine.cpp:593
void set_concurrent_sessions(bool enabled)
Allow runs on DIFFERENT session keys to proceed together.
Definition engine.cpp:3690
std::vector< std::string > get_tier_allowed_tools(const std::string &name) const
Return the allowed tool names registered for a tier (gh#121 regression).
Definition engine.cpp:4552
std::size_t message_count_for(const std::string &key) const
Message count for a named session.
Definition engine.cpp:4278
bool drop_session(const std::string &key)
Forget a session entirely.
Definition engine.cpp:4303
void clear_conversation()
Clear conversation history.
Definition engine.cpp:4228
std::vector< Message > run_turn_as(const std::string &tier, const std::string &input)
Run a single turn under a named tier's grammar/identity (gh#99).
Definition engine.cpp:3826
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.
Definition engine.cpp:4470
std::pair< int, int > context_usage(const std::vector< Message > &messages) const
Get context usage for a message list.
Definition engine.cpp:1419
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...
Definition engine.cpp:1176
void set_system_prompt(const std::string &prompt)
Set the system prompt for conversation state.
Definition engine.cpp:3491
void set_relay_single_delegate(const std::string &name)
Mark a tier as relay-on-single-delegate.
Definition engine.cpp:4579
void set_state_observer(void(*observer)(int state, void *user_data), void *user_data)
Register a persistent state-transition observer.
Definition engine.cpp:4488
void set_active_session(const std::string &key)
Bind this turn to a caller-scoped session (gh#144, v2.12.0).
Definition engine.cpp:3596
size_t message_count() const
Get conversation message count.
Definition engine.cpp:4248
static constexpr int MAX_DELEGATION_DEPTH
Max delegation nesting depth (0=root, 1=child, 2=max).
Definition engine.h:69
std::vector< Message > messages_for(const std::string &key) const
Messages held by a named session.
Definition engine.cpp:4264
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).
Definition engine.cpp:241
void end_turn()
Release the turn this thread claimed (gh#158).
Definition engine.cpp:3666
ToolExecutorHooks build_directive_hooks()
Build ToolExecutorHooks wired to this engine's DirectiveProcessor.
Definition engine.cpp:4504
void set_workspace_prompts(const std::string &workspace, WorkspacePrompts prompts)
Register (or replace) one workspace's assembled prompts.
Definition engine.cpp:3844
void set_dir_swap(ScopedSandbox::SwapDirFn swap_fn, void *user_data)
Install the directory-swap callback used by sandboxing.
Definition engine.cpp:3389
void defang_meta_action_envelope(Message &msg) const
gh#88: reshape a meta-tool {"action":...} result so the model is not primed to parrot the call-shaped...
Definition engine.cpp:1813
void set_handoff_rules(const std::unordered_map< std::string, std::vector< std::string > > &rules)
Store handoff rules for tier delegation.
Definition engine.cpp:4590
void set_tier_info(const std::string &name, const ChildContextInfo &info)
Store pre-resolved tier context info.
Definition engine.cpp:4526
void set_message_queue_capacity(int cap)
Set the runtime capacity of the mid-gen queue.
Definition engine.cpp:4431
const std::string & tier_system_prompt(const std::string &name) const
A tier's resolved system prompt (gh#98).
Definition engine.cpp:4566
std::filesystem::path resolve_session_root(const std::string &session_key)
Resolve the root a session's tools operate in (gh#160).
Definition engine.cpp:3422
EngineCallbacks & callbacks()
Get mutable reference to engine callbacks.
Definition engine.h:413
void clear_workspace_prompts(const std::string &workspace)
Forget a workspace's prompts; its sessions fall back to the handle's.
Definition engine.cpp:3859
void reset_interrupt()
Reset interrupt flag for next run.
Definition engine.cpp:1373
bool has_tier(const std::string &name) const
Whether a tier name is known (gh#99).
Definition engine.cpp:4540
void set_external_interrupt(void(*cb)(void *user_data), void *user_data)
Register a callback invoked alongside interrupt().
Definition engine.cpp:1344
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 ...
Definition engine.cpp:1124
int64_t seconds_since_last_activity() const
gh#35: seconds since the engine last serviced a run().
Definition engine.cpp:1196
std::atomic< bool > & run_cancel_flag()
The cancel flag of the run executing on THIS thread (gh#158).
Definition engine.cpp:3764
void set_tool_executor(const ToolExecutionInterface &tool_exec)
Set the tool execution interface.
Definition engine.cpp:177
Manages automatic context compaction.
Definition compaction.h:135
Processes tool directives via registry-based dispatch.
Definition directives.h:340
Create, finalize, and discard per-delegation filesystem sandboxes.
Definition sandbox.h:116
void(*)(const std::string &session_key, const std::filesystem::path &path, bool entering, void *user_data) SwapDirFn
Callback type for directory swapping.
Definition sandbox.h:361
Manages session_model.log for raw streaming content.
Auto-compaction for context management.
Context management subsystem for the agentic loop.
gh#144: one caller's conversation, as a value.
Directive processing for tool-to-engine communication.
Types for the agentic loop engine.
Public C API for the Entropic inference engine.
ent_decision_t
Consumer decision returned from delegation callbacks.
Definition entropic.h:1614
entropic_hook_point_t
Hook points in the engine lifecycle.
Definition hooks.h:39
Hook dispatch interface injected into engine subsystems.
Function pointer types for core-to-inference communication.
std::size_t remaining
Unexamined count.
Activate model on GPU (WARM → ACTIVE).
@ enabled
Named in enabled_mcpjson_servers, or enable-all is set.
@ optional
optional: every escape asks the host's path approver
@ tier
The TIER's identity frontmatter grammar: stem (gh#154).
void(*)(const char *, size_t, void *) TokenCallback
Token callback type matching the C API signature.
AgentState
C++ enum class for agent execution states.
Response generation subsystem for the agentic loop.
Filesystem-based sandbox isolation for delegations.
Session model log — raw streaming transcript.
Streaming filter that strips a model family's reasoning blocks.
Request describing a delegation that is about to run.
Definition entropic.h:1628
Result of a finalized delegation, delivered to the consumer.
Definition entropic.h:1651
Grouped consumer-registered delegation callbacks (gh#29).
Definition engine.h:92
Resolved tier information for building child delegation contexts.
Auto-compaction configuration.
Definition config.h:1059
Result returned from a child delegation loop.
Definition delegation.h:33
Callback function pointer types for engine events.
Configuration for the agentic loop.
Mutable state carried through the agentic loop.
Metrics collected during loop execution.
A message in a conversation.
Definition message.h:36
Where a session's tools live, and what it can reach (gh#160).
Storage interface for conversation persistence.
Tier resolution callbacks for delegation and auto-chain.
Tool execution interface for the engine.
Engine-level hooks called during tool processing.
One workspace's assembled system prompts (gh#179, v2.14.0).