Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
delegation.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
13#pragma once
14
15#include <entropic/entropic.h> // ent_decision_t + ent_delegation_* (gh#29, v2.1.5)
19
20#include <functional>
21#include <optional>
22#include <string>
23#include <vector>
24
25namespace entropic {
26
27class AgentEngine; // forward declaration
28
34 std::string summary;
35 bool success = false;
36 std::string target_tier;
37 std::string task;
38 int turns_used = 0;
39 std::vector<Message> child_messages;
45 std::string terminal_reason;
50 bool coverage_gap = false;
54 std::string gap_description;
57 std::vector<std::string> suggested_files;
58};
59
70using RunChildLoopFn = void (*)(LoopContext& ctx, void* user_data);
71
81 std::string (*save)(void* user_data) = nullptr;
83 void (*install_fresh)(void* user_data) = nullptr;
85 void (*restore)(const std::string& saved, void* user_data) = nullptr;
86 void* user_data = nullptr;
87};
88
106public:
125 void* run_child_data,
126 const TierResolutionInterface& tier_resolution,
127 const std::filesystem::path& repo_dir = {},
128 SandboxManager* sandbox_mgr = nullptr);
129
135 void set_todo_callbacks(const TodoCallbacks& callbacks);
136
143 void set_dir_swap(ScopedSandbox::SwapDirFn swap_fn, void* user_data);
144
150 void set_storage(const struct StorageInterface* storage);
151
171 void* user_data);
172
185 const std::string& target_tier,
186 const std::string& task,
187 std::optional<int> max_turns = std::nullopt,
188 const std::vector<ContextRef>& context = {});
189
212 const std::string& target_tier,
213 const std::string& task,
214 std::vector<Message> seed_history,
215 std::optional<int> max_turns = std::nullopt,
216 const std::vector<ContextRef>& context = {});
217
230 const std::vector<std::string>& stages,
231 const std::string& task,
232 std::vector<DelegationResult>& stage_log,
233 const std::vector<ContextRef>& context = {});
234
235private:
243 std::string mint_delegation_id(const std::string& prefix);
244
252 std::filesystem::path restore_root_for(
253 const LoopContext& parent_ctx) const;
254
267 static std::string format_context_block(
268 const std::vector<ContextRef>& context);
269
279 LoopContext build_child_context(
280 const LoopContext& parent_ctx,
281 const ChildContextInfo& info,
282 const std::string& task,
283 const std::vector<ContextRef>& context = {});
284
300 LoopContext build_resumed_child_context(
301 const LoopContext& parent_ctx,
302 const ChildContextInfo& info,
303 const std::string& target_tier,
304 const std::string& task,
305 std::vector<Message> seed_history);
306
314 std::string extract_summary(const LoopContext& child_ctx) const;
315
335 std::optional<DelegationResult> check_delegation_preconditions(
336 const ChildContextInfo& info,
337 const std::string& target_tier,
338 const std::string& task,
339 const std::string& del_id,
340 int depth,
341 std::optional<SandboxInfo>& sb_info_out);
342
355 DelegationResult run_child(
357 const std::string& target_tier,
358 const std::string& task,
359 std::optional<int> max_turns);
360
371 DelegationResult build_child_result(
372 const std::string& target_tier,
373 const std::string& task,
375
382 void log_child_result(const DelegationResult& result);
383
397 void finalize_sandbox_for(
398 const std::optional<SandboxInfo>& sb_info,
399 const DelegationResult& result);
400
411 std::string create_storage_record(
412 LoopContext& child_ctx, const std::string& target_tier,
413 const std::string& task, std::optional<int> max_turns);
414
422 void complete_storage_record(
423 const std::string& delegation_id,
424 const DelegationResult& result);
425
426 RunChildLoopFn run_child_fn_;
427 void* run_child_data_;
428 TierResolutionInterface tier_res_;
429 TodoCallbacks todo_callbacks_;
430 ScopedSandbox::SwapDirFn swap_dir_fn_ = nullptr;
431 void* swap_dir_data_ = nullptr;
432 SandboxManager* sandbox_mgr_ = nullptr;
433 std::filesystem::path repo_dir_;
434 const struct StorageInterface* storage_ = nullptr;
435
436 // ── Delegation callbacks (gh#29, v2.1.5) ───────────────
437 ent_decision_t (*delegation_start_cb_)(
438 const ent_delegation_request_t*, void*) = nullptr;
439 ent_decision_t (*delegation_complete_cb_)(
440 const ent_delegation_result_t*, void*) = nullptr;
441 void* delegation_cb_data_ = nullptr;
442
460 ent_decision_t fire_start_cb(
461 const std::string& delegation_id,
462 const std::string& target_tier,
463 const std::string& task,
464 int depth,
465 bool is_pipeline);
466
481 void deliver_sandbox_result(
482 const SandboxInfo& sb_info,
484 const DelegationResult& result);
485
498 ent_decision_t invoke_complete_cb(const ent_delegation_result_t& res,
499 const std::string& delegation_id);
500
514 void persist_pending_patch(
515 const SandboxInfo& sb_info,
517 const char* reason);
518
540 bool run_pipeline_stage(
542 const std::vector<std::string>& stages,
543 size_t stage_idx,
544 const std::string& task,
545 const std::optional<SandboxInfo>& shared_sb,
546 std::vector<DelegationResult>& stage_log,
547 DelegationResult& last_result);
548};
549
550} // namespace entropic
Orchestrates child loop creation and execution.
Definition delegation.h:105
void set_todo_callbacks(const TodoCallbacks &callbacks)
Set todo list save/restore callbacks.
void set_dir_swap(ScopedSandbox::SwapDirFn swap_fn, void *user_data)
Set directory swap callback for ScopedSandbox.
void set_storage(const struct StorageInterface *storage)
Set storage interface for delegation record persistence.
DelegationResult execute_resume_delegation(LoopContext &parent_ctx, const std::string &target_tier, const std::string &task, std::vector< Message > seed_history, std::optional< int > max_turns=std::nullopt, const std::vector< ContextRef > &context={})
Resume a prior delegation with pre-loaded conversation history.
DelegationResult execute_pipeline(LoopContext &parent_ctx, const std::vector< std::string > &stages, const std::string &task, std::vector< DelegationResult > &stage_log, const std::vector< ContextRef > &context={})
Run a multi-stage delegation pipeline sequentially.
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)
Set delegation start/complete callbacks (gh#29, v2.1.5).
DelegationResult execute_delegation(LoopContext &parent_ctx, const std::string &target_tier, const std::string &task, std::optional< int > max_turns=std::nullopt, const std::vector< ContextRef > &context={})
Run a child inference loop for the target tier.
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
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
Message struct for conversation history.
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
void(*)(LoopContext &ctx, void *user_data) RunChildLoopFn
Callback type for running a child engine loop.
Definition delegation.h:70
Filesystem-based sandbox isolation for delegations.
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
Resolved tier information for building child delegation contexts.
Result returned from a child delegation loop.
Definition delegation.h:33
std::vector< Message > child_messages
Full child message history.
Definition delegation.h:39
std::string terminal_reason
Non-empty when the child terminated synthetically rather than via a real entropic....
Definition delegation.h:45
bool coverage_gap
Issue #10 (v2.1.4): coverage_gap signal from the child's entropic.complete call.
Definition delegation.h:50
bool success
Whether child reached COMPLETE via real entropic.complete.
Definition delegation.h:35
std::string summary
Final summary from child.
Definition delegation.h:34
std::string task
Original task text.
Definition delegation.h:37
std::vector< std::string > suggested_files
Issue #10 (v2.1.4): file paths the lead should inspect to fill the coverage gap.
Definition delegation.h:57
std::string target_tier
Tier that executed.
Definition delegation.h:36
std::string gap_description
Issue #10 (v2.1.4): concrete description of what the child's answer DOES NOT cover.
Definition delegation.h:54
int turns_used
Iterations consumed.
Definition delegation.h:38
Mutable state carried through the agentic loop.
Identifies one delegation's sandbox directory.
Definition sandbox.h:66
Final artifact emitted by a finalized sandbox.
Definition sandbox.h:83
Storage interface for conversation persistence.
Tier resolution callbacks for delegation and auto-chain.
Callback type for saving/restoring todo list state.
Definition delegation.h:79
std::string(* save)(void *user_data)
Save current todo list state. Returns opaque state string.
Definition delegation.h:81
void(* restore)(const std::string &saved, void *user_data)
Restore a previously saved todo list state.
Definition delegation.h:85
void(* install_fresh)(void *user_data)
Install a fresh empty todo list for child.
Definition delegation.h:83
void * user_data
Opaque pointer (facade context)
Definition delegation.h:86