Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
engine_handle.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
18#pragma once
19
37
38#include <atomic>
39#include <memory>
40#include <mutex>
41#include <string>
42
43// Forward declarations for Phase 1+ subsystems.
44// Headers included as each phase wires them.
45namespace entropic {
46class ModelOrchestrator;
47class ServerManager;
48class ToolExecutor;
49class IdentityManager;
50class MCPAuthorizationManager;
51class AgentEngine;
52class SqliteStorageBackend;
53class AuditLogger;
54class ConstitutionalValidator;
55class CompactorRegistry;
56struct ParsedConfig;
57class BundledModels;
58struct InterfaceContext; // gh#58 follow-up (v2.2.6): per-handle iface ctx
59} // namespace entropic
60
74 // ── Phase 0: Lifecycle ──────────────────────────────────
76 std::mutex api_mutex;
77 std::string last_error;
78 std::atomic<bool> configured{false};
79 std::atomic<bool> running{false};
84 int log_id = 0;
85
86 // ── Phase 1: Configuration ────────────────────────────────
89
90 // ── Phase 2: Inference ─────────────────────────────────────
91 std::unique_ptr<entropic::ModelOrchestrator> orchestrator;
92 entropic::InferenceInterface inference_iface;
96
97 // ── Phase 3: MCP + Identity + Authorization ──────────────
98 std::unique_ptr<entropic::ServerManager> server_manager;
99 std::unique_ptr<entropic::ToolExecutor> tool_executor;
100 std::unique_ptr<entropic::IdentityManager> identity_manager;
101 std::unique_ptr<entropic::MCPAuthorizationManager> mcp_auth;
102
103 // ── Phase 4: Engine Loop + Storage + Audit ─────────────────
104 std::unique_ptr<entropic::AgentEngine> engine;
105 std::unique_ptr<entropic::SqliteStorageBackend> storage;
106 std::unique_ptr<entropic::AuditLogger> audit_logger;
107 std::unique_ptr<entropic::SessionLogger> session_logger;
108
109 // ── Phase 5: Constitutional + Compaction ────────────────────
110 std::unique_ptr<entropic::ConstitutionalValidator> validator;
111 std::unique_ptr<entropic::CompactorRegistry> compactor_registry;
112
113 // ── Phase 6: Tier metadata (v2.0.4) ───────────────────────
115 std::unordered_map<std::string, std::vector<std::string>> tier_allowed_tools;
117 std::unordered_map<std::string, std::vector<std::string>> tier_validation_rules;
118
119 // ── Phase 7: External MCP bridge (v2.0.8) ──────────────────
120 std::unique_ptr<entropic::ExternalBridge> external_bridge;
121
122 // ── Stream observer (v2.0.10) ────────────────────────────
124 void (*stream_observer)(const char*, size_t, void*) = nullptr;
125 void* stream_observer_data = nullptr;
126
127 // ── State-change observer (P1-5 follow-up, 2.0.6-rc16.2) ─
131 void (*state_observer)(int, void*) = nullptr;
132 void* state_observer_data = nullptr;
133
134 // ── Mid-gen queue observer (gh#40, v2.1.10) ───────────────
138 void (*queue_observer)(const char*, size_t, void*) = nullptr;
139 void* queue_observer_data = nullptr;
140
141 // ── Critique start/end callbacks (gh#50, v2.1.12) ─────────
147 void (*critique_start_cb)(void*) = nullptr;
149 void (*critique_end_cb)(void*) = nullptr;
151 void* critique_cb_data = nullptr;
152};
153
154namespace entropic {
155
173public:
176 : lock_(h->api_mutex), log_scope_(h->log_id) {}
177 HandleApiLock(const HandleApiLock&) = delete;
178 HandleApiLock& operator=(const HandleApiLock&) = delete;
179private:
180 // Order matters: api_mutex acquired first, log_scope second.
181 // Destruction reverses (scope first, mutex second) — fine.
182 std::lock_guard<std::mutex> lock_;
184};
185
186} // namespace entropic
JSONL audit logger for MCP tool calls.
Bundled model registry — resolves keys to filesystem paths.
gh#59 (v2.3.1): RAII guard combining api_mutex + log scope.
HandleApiLock(entropic_handle_t h)
Lock handle mutex + enter log scope.
Thread-safe hook registration and dispatch.
Bundled model registry loaded from bundled_models.yaml.
gh#59 (v2.3.1): RAII guard — sets thread's current handle_id.
Definition logging.h:154
Per-identity compactor registration and dispatch.
Configuration structs with defaults.
Post-generation constitutional compliance validator.
Core agent execution engine.
Error types for cross-.so error reporting.
Unix socket MCP bridge — exposes a running engine to external clients.
Thread-safe hook registration and dispatch.
IdentityManager – lifecycle management for static and dynamic identities.
spdlog initialization and logger access.
Per-identity MCP authorization with runtime grant/revoke.
Activate model on GPU (WARM → ACTIVE).
ModelOrchestrator — multi-model lifecycle and routing.
MCP server lifecycle management and tool routing.
Session model log — raw streaming transcript.
SqliteStorageBackend — conversation persistence via SQLite.
Holds orchestrator + tier for C callback user_data.
Full parsed configuration.
Definition config.h:714
Engine handle struct — owns all subsystems.
std::unique_ptr< entropic::ConstitutionalValidator > validator
Constitutional validation.
std::unique_ptr< entropic::ToolExecutor > tool_executor
Tool dispatch.
void(* critique_end_cb)(void *)
Fires after the critique generate returns.
int log_id
gh#59 (v2.3.1): unique handle id for per-handle log routing via entropic::log::HandleAwareSink.
std::atomic< bool > running
True during run()
std::unordered_map< std::string, std::vector< std::string > > tier_validation_rules
Per-tier validation_rules from identity frontmatter (v2.0.6).
std::unique_ptr< entropic::SqliteStorageBackend > storage
SQLite persistence.
entropic::InferenceInterface inference_iface
Stable copy for validator lifetime.
std::unique_ptr< entropic::AuditLogger > audit_logger
Audit log.
std::unique_ptr< entropic::SessionLogger > session_logger
Model transcript log.
std::unordered_map< std::string, std::vector< std::string > > tier_allowed_tools
Per-tier allowed_tools from identity frontmatter.
std::unique_ptr< entropic::CompactorRegistry > compactor_registry
Compaction strategies.
std::atomic< bool > configured
True after configure()
std::unique_ptr< entropic::ExternalBridge > external_bridge
Unix socket MCP bridge.
void(* state_observer)(int, void *)
Observer for engine state transitions.
entropic::config::BundledModels bundled_models
Model registry.
void * stream_observer_data
Observer user_data.
std::unique_ptr< entropic::IdentityManager > identity_manager
Identity lifecycle.
std::string last_error
Per-handle error message.
std::unique_ptr< entropic::AgentEngine > engine
Agentic loop (owns conversation state)
void * critique_cb_data
Forwarded to both callbacks.
std::unique_ptr< entropic::MCPAuthorizationManager > mcp_auth
Per-identity tool auth.
std::unique_ptr< entropic::ModelOrchestrator > orchestrator
Model pool + routing.
entropic::ParsedConfig config
Parsed config.
void(* stream_observer)(const char *, size_t, void *)
Global stream observer — fires for all streaming output.
void(* queue_observer)(const char *, size_t, void *)
Observer fired when a queued mid-gen user message is consumed and seeded as the next turn.
std::unique_ptr< entropic::ServerManager > server_manager
MCP server lifecycle.
entropic::InterfaceContext * inference_iface_ctx
Per-handle owned context backing inference_iface.user_data.
std::mutex api_mutex
Serializes API calls.
void(* critique_start_cb)(void *)
Fires before the constitutional validator's critique generate begins.
entropic::HookRegistry hook_registry
Hook dispatch.
Processes tool calls from model output.