Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
engine_types.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
13#pragma once
14
19
20#include <atomic>
21#include <filesystem>
22#include <optional>
23#include <string>
24#include <unordered_map>
25#include <vector>
26
27namespace entropic {
28
48
53enum class InterruptMode {
54 CANCEL,
55 PAUSE,
56 INJECT,
57};
58
63enum class ToolApproval {
64 DENY,
65 ALLOW,
68};
69
81enum class BudgetMode {
82 off,
83 tokens,
85};
86
166
172 int iterations = 0;
173 int tool_calls = 0;
174 int tokens_used = 0;
175 int errors = 0;
176 double start_time = 0.0;
177 double end_time = 0.0;
178
184 int duration_ms() const;
185};
186
198 std::string target;
199 std::string task;
200 int max_turns = -1;
202};
203
209 std::vector<std::string> stages;
210 std::string task;
211};
212
218 std::string system_prompt;
219 std::vector<std::string> tools;
220 std::vector<std::string> allowed_tools;
221 bool explicit_completion = false;
223 bool valid = false;
227};
228
240 const std::string& tier_name, void* user_data) = nullptr;
241
244 std::string (*get_tier_param)(
245 const std::string& tier_name,
246 const std::string& param_name,
247 void* user_data) = nullptr;
248
250 std::vector<std::string> (*get_handoff_targets)(
251 const std::string& tier_name, void* user_data) = nullptr;
252
254 bool (*tier_exists)(
255 const std::string& tier_name, void* user_data) = nullptr;
256
257 void* user_data = nullptr;
258};
259
269 std::vector<Message> messages;
270 std::vector<ToolCall> pending_tool_calls;
271 AgentState state = AgentState::IDLE;
277 std::string locked_tier;
278 std::string task_id;
279 std::string conversation_id;
280 std::string source = "human";
281 std::vector<std::string> all_tools;
282 std::string base_system;
283 std::unordered_map<std::string, std::string> metadata;
285 std::vector<std::string> delegation_ancestor_tiers;
287 std::vector<std::string> child_conversation_ids;
288 std::string active_phase = "default";
289 std::unordered_map<std::string, std::string> recent_tool_calls;
290 std::optional<PendingDelegation> pending_delegation;
291 std::optional<PendingPipeline> pending_pipeline;
300
309
314 std::string last_tool_name;
315
321
326
333
340
345
353};
354
365 void (*on_state_change)(int state, void* ud) = nullptr;
366 void (*on_stream_chunk)(const char* chunk, size_t len,
367 void* ud) = nullptr;
368 void (*on_tier_selected)(const char* tier, void* ud) = nullptr;
369 void (*on_routing_complete)(const char* json, void* ud) = nullptr;
370 void (*on_tool_call)(const char* json, void* ud) = nullptr;
371 void (*on_tool_start)(const char* json, void* ud) = nullptr;
372 void (*on_tool_complete)(const char* json, const char* result,
373 double ms, void* ud) = nullptr;
374 void (*on_presenter_notify)(const char* key, const char* json,
375 void* ud) = nullptr;
376 void (*on_compaction)(const char* json, void* ud) = nullptr;
377 void (*on_pause_prompt)(const char* partial, char** injection,
378 void* ud) = nullptr;
379 void (*on_tool_record)(const char* tier, const char* json,
380 const char* result, const char* error,
381 double ms, void* ud) = nullptr;
382 void (*on_delegation_start)(const char* child_id, const char* tier,
383 const char* task, void* ud) = nullptr;
384 void (*on_delegation_complete)(const char* child_id, const char* tier,
385 const char* summary, int success,
386 void* ud) = nullptr;
387 const char* (*error_sanitizer)(const char* raw, void* ud) = nullptr;
388 void* user_data = nullptr;
389};
390
403using ToolExecutionFn = std::vector<Message> (*)(
404 LoopContext& ctx,
405 const std::vector<ToolCall>& tool_calls,
406 void* user_data);
407
418 void* user_data = nullptr;
419
428 char* (*history_json)(size_t count, void* user_data) = nullptr;
429
431 void (*free_fn)(char*) = nullptr;
432};
433
445 void (*after_tool)(LoopContext& ctx, void* user_data) = nullptr;
446
450 LoopContext& ctx,
451 const std::vector<const Directive*>& directives,
452 void* user_data) = nullptr;
453
454 void* user_data = nullptr;
455};
456
482 const char* title,
483 std::string& conversation_id,
484 void* user_data) = nullptr;
485
492 const char* conversation_id,
493 const char* messages_json,
494 void* user_data) = nullptr;
495
507 const char* parent_id,
508 const char* delegating_tier,
509 const char* target_tier,
510 const char* task,
511 int max_turns,
512 std::string& delegation_id,
513 std::string& child_conversation_id,
514 void* user_data) = nullptr;
515
523 const char* delegation_id,
524 const char* status,
525 const char* summary,
526 void* user_data) = nullptr;
527
534 const char* conversation_id,
535 const char* messages_json,
536 void* user_data) = nullptr;
537
551 const char* delegation_id,
552 std::string& result_json,
553 void* user_data) = nullptr;
554
555 void* user_data = nullptr;
556};
557
569using PermissionPersistFn = void (*)(
570 const char* pattern, bool allow, void* user_data);
571
580
589 std::atomic<bool>* interrupt = nullptr;
590 std::atomic<bool>* pause = nullptr;
591};
592
603
611const char* agent_state_name(AgentState state);
612
613} // namespace entropic
Directive processing for tool-to-engine communication.
Shared enumerations used across .so boundaries.
@ ENTROPIC_AGENT_STATE_COMPLETE
Turn finished.
Definition enums.h:47
@ ENTROPIC_AGENT_STATE_DELEGATING
Child delegation running.
Definition enums.h:46
@ ENTROPIC_AGENT_STATE_VERIFYING
Post-generation verification.
Definition enums.h:45
@ ENTROPIC_AGENT_STATE_PAUSED
Awaiting user input.
Definition enums.h:50
@ ENTROPIC_AGENT_STATE_EXECUTING
Generating response.
Definition enums.h:43
@ ENTROPIC_AGENT_STATE_WAITING_TOOL
Tool call in progress.
Definition enums.h:44
@ ENTROPIC_AGENT_STATE_IDLE
No active generation.
Definition enums.h:41
@ ENTROPIC_AGENT_STATE_PLANNING
Assembling context and tools.
Definition enums.h:42
@ ENTROPIC_AGENT_STATE_ERROR
Unrecoverable error.
Definition enums.h:48
@ ENTROPIC_AGENT_STATE_INTERRUPTED
Cancelled by consumer.
Definition enums.h:49
Message struct for conversation history.
Activate model on GPU (WARM → ACTIVE).
BudgetMode
Thinking-budget gating mode.
@ tokens
Gate on generated tokens since the last tool call.
@ off
Disabled (default) — no thinking-budget gating.
@ wall_clock
Gate on wall-clock seconds since the last tool call.
@ error
Tool server returned an error payload.
@ count
Sentinel — MUST remain last.
const char * agent_state_name(AgentState state)
Get the string name for an AgentState value.
std::vector< Message >(*)(LoopContext &ctx, const std::vector< ToolCall > &tool_calls, void *user_data) ToolExecutionFn
Tool execution callback type.
ToolApproval
Tool approval responses from user.
@ DENY
Deny this once.
@ ALLOW
Allow this once.
@ ALWAYS_DENY
Deny and save to config.
@ ALWAYS_ALLOW
Allow and save to config.
InterruptMode
How to handle generation interrupt.
@ CANCEL
Discard partial response, stop.
@ PAUSE
Keep partial response, await input.
@ INJECT
Keep partial, inject context, continue.
AgentState
C++ enum class for agent execution states.
void(*)(const char *pattern, bool allow, void *user_data) PermissionPersistFn
Permission persistence callback type.
Resolved tier information for building child delegation contexts.
std::string completion_instructions
Instructions for explicit completion.
std::vector< std::string > tools
Tool JSON definitions for tier.
int max_iterations_override
Per-tier max_iterations (-1 = global, P3-18)
std::vector< std::string > allowed_tools
Allowed tool names (gh#121)
std::string system_prompt
Built for target tier.
int max_tool_calls_per_turn_override
Per-tier tool cap (-1 = global, P3-18)
bool valid
False if tier not found.
bool explicit_completion
Requires entropic.complete?
int max_consecutive_empty_turns_override
Per-tier empty-turn allowance (-1 = global default, gh#123)
Aggregate result of processing a batch of directives.
Definition directives.h:281
Callback function pointer types for engine events.
void(* on_tier_selected)(const char *tier, void *ud)
Tier routing result.
void(* on_routing_complete)(const char *json, void *ud)
Full routing JSON.
void(* on_tool_call)(const char *json, void *ud)
Tool call request.
void(* on_compaction)(const char *json, void *ud)
Compaction result.
void(* on_presenter_notify)(const char *key, const char *json, void *ud)
UI notification.
void(* on_delegation_complete)(const char *child_id, const char *tier, const char *summary, int success, void *ud)
Delegation returned.
void(* on_tool_complete)(const char *json, const char *result, double ms, void *ud)
Tool execution done.
void * user_data
Opaque pointer passed to all callbacks.
void(* on_tool_start)(const char *json, void *ud)
Tool execution start.
void(* on_delegation_start)(const char *child_id, const char *tier, const char *task, void *ud)
Delegation spawned.
void(* on_pause_prompt)(const char *partial, char **injection, void *ud)
Pause: get injection.
void(* on_state_change)(int state, void *ud)
AgentState as int.
void(* on_stream_chunk)(const char *chunk, size_t len, void *ud)
Per-token streaming.
void(* on_tool_record)(const char *tier, const char *json, const char *result, const char *error, double ms, void *ud)
Tool audit record.
Atomic flags for interrupt/pause signaling.
std::atomic< bool > * interrupt
Hard interrupt flag.
std::atomic< bool > * pause
Pause flag.
Context for interrupted/paused generation.
InterruptMode mode
Interrupt handling mode.
std::vector< ToolCall > partial_tool_calls
Parsed tool calls (if any)
std::string partial_content
Content generated before interrupt.
std::string injection
User injection content.
Configuration for the agentic loop.
int max_consecutive_same_tool
Anti-spiral SOFT threshold: after N consecutive calls of the SAME tool (regardless of arg similarity,...
int budget_limit
Budget ceiling for the active budget_mode: generated tokens (mode tokens) or wall-clock seconds (mode...
int context_length
Context budget for compaction (v2.0.4)
int max_iterations
Max loop iterations before forced stop.
bool stream_output
Stream vs batch generation.
int max_consecutive_same_tool_hard_block
Anti-spiral HARD threshold: when consecutive same-tool calls exceed this, the engine blocks the call ...
bool require_plan_for_complex
Planning gate (reserved)
bool auto_approve_tools
Skip tool approval (v1.8.5)
int max_consecutive_failed_delegations
gh#64: cap on N consecutive failed delegations targeting the same tier.
int max_tool_result_bytes
Maximum byte length for a single tool's result content before the engine truncates with a "[....
int max_consecutive_errors
Errors before ERROR state.
bool speculative_enabled
gh#110 (v2.9.6): mirrors inference.speculative.enabled from config, plumbed through since core....
int max_tool_calls_per_turn
Tool calls per iteration (v1.8.5)
BudgetMode budget_mode
Thinking-budget gating mode (gh#80, v2.5.0).
int idle_timeout_seconds
Idle timeout (reserved)
int message_queue_capacity
Capacity of the mid-generation user-message queue surfaced by entropic_queue_user_message.
Mutable state carried through the agentic loop.
std::string task_id
External task ID (MCP integration)
bool budget_completion_nudged
gh#80 (v2.5.0): true once the engine has emitted the "emit completion now" nudge for the current budg...
std::vector< std::string > delegation_ancestor_tiers
Tier stack from root to this loop (P1-9, 2.0.6-rc16)
std::unordered_map< std::string, std::string > recent_tool_calls
Duplicate detection cache (v1.8.5)
std::optional< PendingDelegation > pending_delegation
Stored by dir_delegate (v1.8.6)
std::optional< PendingPipeline > pending_pipeline
Stored by dir_pipeline (v1.8.6)
std::string last_failed_delegation_target
gh#64: target tier of the most recent FAILED delegation (DelegationResult.success == false).
int budget_tokens_since_tool
gh#80 (v2.5.0): tokens generated since the last tool call (mode tokens).
LoopMetrics metrics
Timing and counts.
std::vector< ToolCall > pending_tool_calls
Pending tool calls (v1.8.5)
int effective_max_iterations
Per-identity override (-1 = LoopConfig, P3-18)
double budget_window_start_s
gh#80 (v2.5.0): wall-clock epoch-seconds marking the start of the current tool-call-free window (mode...
std::string source
Message source.
std::string pending_anti_spiral_warning
One-shot anti-spiral reminder for the next per-turn system prompt.
int consecutive_duplicate_attempts
Stuck-model detector.
int consecutive_failed_delegations
gh#64: count of consecutive failed delegations against last_failed_delegation_target.
int consecutive_same_tool_calls
Count of CONSECUTIVE successful calls to the same tool (last_tool_name).
std::string active_phase
Active inference phase.
std::string conversation_id
Conversation ID for storage (v1.8.8)
int effective_tool_calls
Non-blocked calls this iteration.
int consecutive_errors
Error streak counter.
bool has_pending_tool_results
Tool results awaiting presentation.
std::unordered_map< std::string, std::string > metadata
Runtime metadata.
int effective_max_tool_calls_per_turn
Per-identity override (-1 = LoopConfig, P3-18)
std::string base_system
Base system prompt (pre-tier formatting)
int delegation_depth
0 = root, 1+ = child
std::vector< std::string > child_conversation_ids
Spawned child IDs.
AgentState state
Current state.
std::vector< Message > messages
Conversation history.
std::string pending_validation_feedback
One-shot reminder text consumed by the next per-turn system prompt assembly.
std::string locked_tier
Tier locked for this loop ("" = none)
std::string parent_conversation_id
Parent conv ID (delegation)
std::vector< std::string > all_tools
Full tool list as raw JSON strings.
std::string last_tool_name
Name of the most recently dispatched tool.
Metrics collected during loop execution.
double start_time
Loop start (seconds since epoch)
int tokens_used
Total tokens consumed.
int errors
Total errors encountered.
int duration_ms() const
Get loop duration in milliseconds.
int tool_calls
Total tool calls executed.
double end_time
Loop end (seconds since epoch)
int iterations
Total iterations completed.
Pending single delegation (stored by dir_delegate handler).
std::string task
Task description.
std::string target
Target tier name.
std::string resume_from_delegation_id
gh#32 (v2.1.6): empty = cold start
int max_turns
Max turns for child (-1 = default)
Pending multi-stage pipeline (stored by dir_pipeline handler).
std::vector< std::string > stages
Tier names in order.
std::string task
Task description.
Permission persistence interface.
PermissionPersistFn persist
Persist callback.
Storage interface for conversation persistence.
bool(* save_snapshot)(const char *conversation_id, const char *messages_json, void *user_data)
Save a compaction snapshot (full history before compaction).
bool(* create_delegation)(const char *parent_id, const char *delegating_tier, const char *target_tier, const char *task, int max_turns, std::string &delegation_id, std::string &child_conversation_id, void *user_data)
Create a delegation record with child conversation.
bool(* save_conversation)(const char *conversation_id, const char *messages_json, void *user_data)
Save messages to a conversation.
bool(* complete_delegation)(const char *delegation_id, const char *status, const char *summary, void *user_data)
Complete a delegation record.
void * user_data
Opaque pointer (storage backend)
bool(* load_delegation_with_messages)(const char *delegation_id, std::string &result_json, void *user_data)
Load a delegation's full child conversation (gh#32, v2.1.6).
bool(* create_conversation)(const char *title, std::string &conversation_id, void *user_data)
Create a root conversation row.
Tier resolution callbacks for delegation and auto-chain.
void * user_data
Opaque pointer (facade context)
bool(* tier_exists)(const std::string &tier_name, void *user_data)
Check if a tier exists in the configuration.
std::vector< std::string >(* get_handoff_targets)(const std::string &tier_name, void *user_data)
Get valid handoff targets from a tier.
std::string(* get_tier_param)(const std::string &tier_name, const std::string &param_name, void *user_data)
Get a string parameter from tier identity frontmatter.
ChildContextInfo(* resolve_tier)(const std::string &tier_name, void *user_data)
Build context info for a child delegation to the given tier.
Tool execution interface for the engine.
void(* free_fn)(char *)
Free function for strings returned by history_json.
ToolExecutionFn process_tool_calls
Dispatches tool calls.
void * user_data
Opaque pointer (ToolExecutor*)
Engine-level hooks called during tool processing.
void(* after_tool)(LoopContext &ctx, void *user_data)
Called after each tool execution.
DirectiveResult(* process_directives)(LoopContext &ctx, const std::vector< const Directive * > &directives, void *user_data)
Process directives from tool results.
void * user_data
Opaque pointer for hooks.
Tool call and tool result types.