Entropic 2.11.1
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
169 ent_decision_t (*on_start)(const ent_delegation_request_t*, void*),
170 ent_decision_t (*on_complete)(const ent_delegation_result_t*, void*),
171 void* user_data);
172
184 LoopContext& parent_ctx,
185 const std::string& target_tier,
186 const std::string& task,
187 std::optional<int> max_turns = std::nullopt);
188
210 LoopContext& parent_ctx,
211 const std::string& target_tier,
212 const std::string& task,
213 std::vector<Message> seed_history,
214 std::optional<int> max_turns = std::nullopt);
215
227 LoopContext& parent_ctx,
228 const std::vector<std::string>& stages,
229 const std::string& task,
230 std::vector<DelegationResult>& stage_log);
231
232private:
242 LoopContext build_child_context(
243 const LoopContext& parent_ctx,
244 const ChildContextInfo& info,
245 const std::string& task);
246
262 LoopContext build_resumed_child_context(
263 const LoopContext& parent_ctx,
264 const ChildContextInfo& info,
265 const std::string& target_tier,
266 const std::string& task,
267 std::vector<Message> seed_history);
268
276 std::string extract_summary(const LoopContext& child_ctx) const;
277
297 std::optional<DelegationResult> check_delegation_preconditions(
298 const ChildContextInfo& info,
299 const std::string& target_tier,
300 const std::string& task,
301 const std::string& del_id,
302 int depth,
303 std::optional<SandboxInfo>& sb_info_out);
304
315 DelegationResult run_child(
316 LoopContext& child_ctx,
317 const std::string& target_tier,
318 const std::string& task,
319 std::optional<int> max_turns);
320
331 DelegationResult build_child_result(
332 const std::string& target_tier,
333 const std::string& task,
334 LoopContext& child_ctx);
335
342 void log_child_result(const DelegationResult& result);
343
357 void finalize_sandbox_for(
358 const std::optional<SandboxInfo>& sb_info,
359 const DelegationResult& result);
360
371 std::string create_storage_record(
372 LoopContext& child_ctx, const std::string& target_tier,
373 const std::string& task, std::optional<int> max_turns);
374
382 void complete_storage_record(
383 const std::string& delegation_id,
384 const DelegationResult& result);
385
386 RunChildLoopFn run_child_fn_;
387 void* run_child_data_;
388 TierResolutionInterface tier_res_;
389 TodoCallbacks todo_callbacks_;
390 ScopedSandbox::SwapDirFn swap_dir_fn_ = nullptr;
391 void* swap_dir_data_ = nullptr;
392 SandboxManager* sandbox_mgr_ = nullptr;
393 std::filesystem::path repo_dir_;
394 const struct StorageInterface* storage_ = nullptr;
395
396 // ── Delegation callbacks (gh#29, v2.1.5) ───────────────
397 ent_decision_t (*delegation_start_cb_)(
398 const ent_delegation_request_t*, void*) = nullptr;
399 ent_decision_t (*delegation_complete_cb_)(
400 const ent_delegation_result_t*, void*) = nullptr;
401 void* delegation_cb_data_ = nullptr;
402
420 ent_decision_t fire_start_cb(
421 const std::string& delegation_id,
422 const std::string& target_tier,
423 const std::string& task,
424 int depth,
425 bool is_pipeline);
426
441 void deliver_sandbox_result(
442 const SandboxInfo& sb_info,
443 const SandboxResult& sandbox_result,
444 const DelegationResult& result);
445
458 ent_decision_t invoke_complete_cb(const ent_delegation_result_t& res,
459 const std::string& delegation_id);
460
474 void persist_pending_patch(
475 const SandboxInfo& sb_info,
476 const SandboxResult& sandbox_result,
477 const char* reason);
478
500 bool run_pipeline_stage(
501 LoopContext& parent_ctx,
502 const std::vector<std::string>& stages,
503 size_t stage_idx,
504 const std::string& task,
505 const std::optional<SandboxInfo>& shared_sb,
506 std::vector<DelegationResult>& stage_log,
507 DelegationResult& last_result);
508};
509
510} // 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.
DelegationResult execute_pipeline(LoopContext &parent_ctx, const std::vector< std::string > &stages, const std::string &task, std::vector< DelegationResult > &stage_log)
Run a multi-stage delegation pipeline sequentially.
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.
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:1091
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:1105
Result of a finalized delegation, delivered to the consumer.
Definition entropic.h:1128
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