Entropic 2.3.8
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
168 ent_decision_t (*on_start)(const ent_delegation_request_t*, void*),
169 ent_decision_t (*on_complete)(const ent_delegation_result_t*, void*),
170 void* user_data);
171
182 LoopContext& parent_ctx,
183 const std::string& target_tier,
184 const std::string& task,
185 std::optional<int> max_turns = std::nullopt);
186
207 LoopContext& parent_ctx,
208 const std::string& target_tier,
209 const std::string& task,
210 std::vector<Message> seed_history,
211 std::optional<int> max_turns = std::nullopt);
212
222 LoopContext& parent_ctx,
223 const std::vector<std::string>& stages,
224 const std::string& task);
225
226private:
235 LoopContext build_child_context(
236 const LoopContext& parent_ctx,
237 const ChildContextInfo& info,
238 const std::string& task);
239
255 LoopContext build_resumed_child_context(
256 const LoopContext& parent_ctx,
257 const ChildContextInfo& info,
258 const std::string& target_tier,
259 const std::string& task,
260 std::vector<Message> seed_history);
261
268 std::string extract_summary(const LoopContext& child_ctx) const;
269
288 std::optional<DelegationResult> check_delegation_preconditions(
289 const ChildContextInfo& info,
290 const std::string& target_tier,
291 const std::string& task,
292 const std::string& del_id,
293 int depth,
294 std::optional<SandboxInfo>& sb_info_out);
295
305 DelegationResult run_child(
306 LoopContext& child_ctx,
307 const std::string& target_tier,
308 const std::string& task,
309 std::optional<int> max_turns);
310
320 DelegationResult build_child_result(
321 const std::string& target_tier,
322 const std::string& task,
323 LoopContext& child_ctx);
324
331 void log_child_result(const DelegationResult& result);
332
346 void finalize_sandbox_for(
347 const std::optional<SandboxInfo>& sb_info,
348 const DelegationResult& result);
349
359 std::string create_storage_record(
360 LoopContext& child_ctx, const std::string& target_tier,
361 const std::string& task, std::optional<int> max_turns);
362
369 void complete_storage_record(
370 const std::string& delegation_id,
371 const DelegationResult& result);
372
373 RunChildLoopFn run_child_fn_;
374 void* run_child_data_;
375 TierResolutionInterface tier_res_;
376 TodoCallbacks todo_callbacks_;
377 ScopedSandbox::SwapDirFn swap_dir_fn_ = nullptr;
378 void* swap_dir_data_ = nullptr;
379 SandboxManager* sandbox_mgr_ = nullptr;
380 std::filesystem::path repo_dir_;
381 const struct StorageInterface* storage_ = nullptr;
382
383 // ── Delegation callbacks (gh#29, v2.1.5) ───────────────
384 ent_decision_t (*delegation_start_cb_)(
385 const ent_delegation_request_t*, void*) = nullptr;
386 ent_decision_t (*delegation_complete_cb_)(
387 const ent_delegation_result_t*, void*) = nullptr;
388 void* delegation_cb_data_ = nullptr;
389
406 ent_decision_t fire_start_cb(
407 const std::string& delegation_id,
408 const std::string& target_tier,
409 const std::string& task,
410 int depth,
411 bool is_pipeline);
412
427 void deliver_sandbox_result(
428 const SandboxInfo& sb_info,
429 const SandboxResult& sandbox_result,
430 const DelegationResult& result);
431
444 ent_decision_t invoke_complete_cb(const ent_delegation_result_t& res,
445 const std::string& delegation_id);
446
460 void persist_pending_patch(
461 const SandboxInfo& sb_info,
462 const SandboxResult& sandbox_result,
463 const char* reason);
464
485 bool run_pipeline_stage(
486 LoopContext& parent_ctx,
487 const std::vector<std::string>& stages,
488 size_t stage_idx,
489 const std::string& task,
490 const std::optional<SandboxInfo>& shared_sb,
491 DelegationResult& last_result);
492};
493
494} // namespace entropic
Orchestrates child loop creation and execution.
Definition delegation.h:105
DelegationResult execute_delegation(LoopContext &parent_ctx, const std::string &target_tier, const std::string &task, std::optional< int > max_turns=std::nullopt)
Run a child inference loop for the target tier.
void set_todo_callbacks(const TodoCallbacks &callbacks)
Set todo list save/restore callbacks.
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)
Resume a prior delegation with pre-loaded conversation history.
void set_dir_swap(ScopedSandbox::SwapDirFn swap_fn, void *user_data)
Set directory swap callback for ScopedSandbox.
DelegationResult execute_pipeline(LoopContext &parent_ctx, const std::vector< std::string > &stages, const std::string &task)
Run a multi-stage delegation pipeline sequentially.
void set_storage(const struct StorageInterface *storage)
Set storage interface for delegation record persistence.
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).
Create, finalize, and discard per-delegation filesystem sandboxes.
Definition sandbox.h:99
void(*)(const std::filesystem::path &path, void *user_data) SwapDirFn
Callback type for directory swapping.
Definition sandbox.h:298
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:870
Message struct for conversation history.
Activate model on GPU (WARM → ACTIVE).
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:884
Result of a finalized delegation, delivered to the consumer.
Definition entropic.h:907
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:49
Final artifact emitted by a finalized sandbox.
Definition sandbox.h:66
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