Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
directives.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
10
11#include <cstdlib>
12#include <string>
13
14static auto logger = entropic::log::get("core.directives");
15
16namespace entropic {
17
27 DirectiveHandler handler) {
28 handlers_[static_cast<int>(dtype)] = std::move(handler);
29}
30
40 LoopContext& ctx,
41 const std::vector<const Directive*>& directives) {
42 logger->info("Processing {} directive(s)", directives.size());
43 DirectiveResult result;
44 int processed = 0;
45 for (const auto* directive : directives) {
46 if (directive == nullptr) {
47 continue;
48 }
49
50 auto it = handlers_.find(static_cast<int>(directive->type));
51 bool has_handler = it != handlers_.end();
52
53 // Hook: ON_DIRECTIVE or ON_CUSTOM_DIRECTIVE (v1.9.1)
54 if (!fire_directive_hook(directive, has_handler)) {
55 continue; // suppressed by hook
56 }
57
58 if (has_handler) {
59 logger->info("Directive type={}, handler invoked",
60 static_cast<int>(directive->type));
61 it->second(ctx, *directive, result);
62 ++processed;
63 if (result.stop_processing) {
64 break;
65 }
66 }
67 }
68 logger->info("Directives: {}/{} processed", processed,
69 directives.size());
70 return result;
71}
72
81bool DirectiveProcessor::fire_directive_hook(
82 const Directive* directive, bool has_handler) {
83 if (hooks_.fire_pre == nullptr) {
84 return true;
85 }
86
87 auto point = has_handler
90 std::string json = "{\"type\":"
91 + std::to_string(static_cast<int>(directive->type)) + "}";
92 char* mod = nullptr;
93 int rc = hooks_.fire_pre(hooks_.registry,
94 point, json.c_str(), &mod);
95 free(mod);
96 return rc == 0;
97}
98
99} // namespace entropic
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.
Directive processing for tool-to-engine communication.
entropic_directive_type_t
Directive types emitted by MCP tool results.
Definition enums.h:53
@ ENTROPIC_HOOK_ON_CUSTOM_DIRECTIVE
19: Unrecognized directive type
Definition hooks.h:57
@ ENTROPIC_HOOK_ON_DIRECTIVE
18: Before processing a directive
Definition hooks.h:56
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
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
Aggregate result of processing a batch of directives.
Definition directives.h:281
bool stop_processing
Halt further processing.
Definition directives.h:282
Base directive — all directives carry a type tag.
Definition directives.h:36
entropic_directive_type_t type
Discriminant for dispatch.
Definition directives.h:37
Mutable state carried through the agentic loop.