Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
directives.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
15#pragma once
16
20
21#include <functional>
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26namespace entropic {
27
28struct LoopContext; // forward declaration
29
30// ── Directive structs ────────────────────────────────────
31
39
53
59 std::string tier;
60 std::string reason;
61
68 TierChangeDirective(std::string t = "", std::string r = "")
69 : tier(std::move(t)), reason(std::move(r)) {
71 }
72};
73
85 std::string target;
86 std::string task;
87 int max_turns = -1;
89
98 DelegateDirective(std::string tgt = "",
99 std::string tsk = "",
100 int mt = -1,
101 std::string resume_id = "")
102 : target(std::move(tgt)),
103 task(std::move(tsk)),
104 max_turns(mt),
105 resume_from_delegation_id(std::move(resume_id)) {
107 }
108};
109
115 std::vector<std::string> stages;
116 std::string task;
117
124 PipelineDirective(std::vector<std::string> s = {},
125 std::string t = "")
126 : stages(std::move(s)), task(std::move(t)) {
128 }
129};
130
146 std::string summary;
147 bool coverage_gap = false;
148 std::string gap_description;
149 std::vector<std::string> suggested_files;
150
156 explicit CompleteDirective(std::string s = "")
157 : summary(std::move(s)) {
159 }
160};
161
175
181 std::string content;
182 std::string role = "user";
183
190 InjectContextDirective(std::string c = "",
191 std::string r = "user")
192 : content(std::move(c)), role(std::move(r)) {
194 }
195};
196
214
220 std::string key;
221 std::string content;
222
229 ContextAnchorDirective(std::string k = "",
230 std::string c = "")
231 : key(std::move(k)), content(std::move(c)) {
233 }
234};
235
241 std::string phase;
242
248 explicit PhaseChangeDirective(std::string p = "")
249 : phase(std::move(p)) {
251 }
252};
253
259 std::string key;
260 std::string data_json;
261
268 NotifyPresenterDirective(std::string k = "",
269 std::string d = "")
270 : key(std::move(k)), data_json(std::move(d)) {
272 }
273};
274
275// ── DirectiveResult ──────────────────────────────────────
276
282 bool stop_processing = false;
283 bool tier_changed = false;
284 std::vector<Message> injected_messages;
285};
286
287// ── DirectiveHandler type ────────────────────────────────
288
297using DirectiveHandler = std::function<void(
298 LoopContext& ctx,
299 const Directive& directive,
300 DirectiveResult& result)>;
301
302// ── DirectiveProcessor ───────────────────────────────────
303
313public:
321 DirectiveHandler handler);
322
331 LoopContext& ctx,
332 const std::vector<const Directive*>& directives);
333
340 void set_hooks(const HookInterface& hooks) { hooks_ = hooks; }
341
342private:
350 bool fire_directive_hook(const Directive* directive,
351 bool has_handler);
352
353 std::unordered_map<int, DirectiveHandler> handlers_;
354 HookInterface hooks_;
355};
356
357} // namespace entropic
Processes tool directives via registry-based dispatch.
Definition directives.h:312
void register_handler(entropic_directive_type_t dtype, DirectiveHandler handler)
Register a handler for a directive type.
DirectiveResult process(LoopContext &ctx, const std::vector< const Directive * > &directives)
Process a list of directives.
void set_hooks(const HookInterface &hooks)
Set the hook dispatch interface.
Definition directives.h:340
Shared enumerations used across .so boundaries.
entropic_directive_type_t
Directive types emitted by MCP tool results.
Definition enums.h:53
@ ENTROPIC_DIRECTIVE_TIER_CHANGE
Switch active tier.
Definition enums.h:55
@ ENTROPIC_DIRECTIVE_STOP_PROCESSING
Halt directive processing.
Definition enums.h:54
@ ENTROPIC_DIRECTIVE_PRUNE_MESSAGES
Prune old tool results.
Definition enums.h:61
@ ENTROPIC_DIRECTIVE_INJECT_CONTEXT
Inject message into context.
Definition enums.h:60
@ ENTROPIC_DIRECTIVE_COMPLETE
Mark task complete.
Definition enums.h:58
@ ENTROPIC_DIRECTIVE_NOTIFY_PRESENTER
Generic UI notification passthrough.
Definition enums.h:64
@ ENTROPIC_DIRECTIVE_CLEAR_SELF_TODOS
Clear self-directed todos (engine no-op)
Definition enums.h:59
@ ENTROPIC_DIRECTIVE_PHASE_CHANGE
Switch active inference phase.
Definition enums.h:63
@ ENTROPIC_DIRECTIVE_PIPELINE
Multi-stage sequential execution.
Definition enums.h:57
@ ENTROPIC_DIRECTIVE_CONTEXT_ANCHOR
Replace context anchor.
Definition enums.h:62
@ ENTROPIC_DIRECTIVE_DELEGATE
Route to another identity.
Definition enums.h:56
Hook dispatch interface injected into engine subsystems.
Message struct for conversation history.
Activate model on GPU (WARM → ACTIVE).
std::function< void(LoopContext &ctx, const Directive &directive, DirectiveResult &result)> DirectiveHandler
Directive handler function type.
Definition directives.h:300
Clear self-directed todos (engine no-op).
Definition directives.h:166
ClearSelfTodosDirective()
Construct a ClearSelfTodos directive.
Definition directives.h:171
Signal explicit completion.
Definition directives.h:145
std::string summary
Completion summary.
Definition directives.h:146
bool coverage_gap
Suppresses auto-relay (#10, v2.1.4)
Definition directives.h:147
std::string gap_description
What the gap IS (#10, v2.1.4)
Definition directives.h:148
CompleteDirective(std::string s="")
Construct a Complete directive.
Definition directives.h:156
std::vector< std::string > suggested_files
Files for lead to inspect (#10, v2.1.4)
Definition directives.h:149
Update a keyed persistent context anchor.
Definition directives.h:219
std::string content
Anchor content (empty = remove)
Definition directives.h:221
ContextAnchorDirective(std::string k="", std::string c="")
Construct a ContextAnchor directive.
Definition directives.h:229
std::string key
Anchor key (unique, update-in-place)
Definition directives.h:220
Delegate a task to a child inference loop.
Definition directives.h:84
int max_turns
Max turns (-1 = default)
Definition directives.h:87
std::string target
Target tier for delegation.
Definition directives.h:85
std::string task
Task description.
Definition directives.h:86
std::string resume_from_delegation_id
gh#32 (v2.1.6): empty = fresh delegate
Definition directives.h:88
DelegateDirective(std::string tgt="", std::string tsk="", int mt=-1, std::string resume_id="")
Construct a Delegate directive.
Definition directives.h:98
Aggregate result of processing a batch of directives.
Definition directives.h:281
std::vector< Message > injected_messages
Messages to inject.
Definition directives.h:284
bool stop_processing
Halt further processing.
Definition directives.h:282
bool tier_changed
Tier was switched.
Definition directives.h:283
Base directive — all directives carry a type tag.
Definition directives.h:36
entropic_directive_type_t type
Discriminant for dispatch.
Definition directives.h:37
Inject a message into the conversation context.
Definition directives.h:180
std::string content
Content to inject.
Definition directives.h:181
std::string role
Message role.
Definition directives.h:182
InjectContextDirective(std::string c="", std::string r="user")
Construct an InjectContext directive.
Definition directives.h:190
Mutable state carried through the agentic loop.
Generic UI notification passthrough.
Definition directives.h:258
std::string key
Notification key.
Definition directives.h:259
NotifyPresenterDirective(std::string k="", std::string d="")
Construct a NotifyPresenter directive.
Definition directives.h:268
std::string data_json
Arbitrary JSON payload.
Definition directives.h:260
Switch the active inference phase.
Definition directives.h:240
std::string phase
Target phase name.
Definition directives.h:241
PhaseChangeDirective(std::string p="")
Construct a PhaseChange directive.
Definition directives.h:248
Execute a multi-stage delegation pipeline.
Definition directives.h:114
std::string task
Task description.
Definition directives.h:116
std::vector< std::string > stages
Tier names in order.
Definition directives.h:115
PipelineDirective(std::vector< std::string > s={}, std::string t="")
Construct a Pipeline directive.
Definition directives.h:124
Prune old tool results from context.
Definition directives.h:201
PruneMessagesDirective(int k=2)
Construct a PruneMessages directive.
Definition directives.h:209
int keep_recent
How many recent results to keep.
Definition directives.h:202
Stop processing remaining tool calls.
Definition directives.h:44
StopProcessingDirective()
Construct a StopProcessing directive.
Definition directives.h:49
Request a tier change.
Definition directives.h:58
std::string reason
Why the change was requested.
Definition directives.h:60
std::string tier
Target tier name.
Definition directives.h:59
TierChangeDirective(std::string t="", std::string r="")
Construct a TierChange directive.
Definition directives.h:68