24#include <unordered_map>
195 const std::string& tier_name,
void*
user_data) =
nullptr;
200 const std::string& tier_name,
201 const std::string& param_name,
206 const std::string& tier_name,
void*
user_data) =
nullptr;
210 const std::string& tier_name,
void*
user_data) =
nullptr;
238 std::unordered_map<std::string, std::string>
metadata;
309 double ms,
void* ud) =
nullptr;
316 const char* result,
const char*
error,
317 double ms,
void* ud) =
nullptr;
319 const char* task,
void* ud) =
nullptr;
321 const char* summary,
int success,
323 const char* (*error_sanitizer)(
const char* raw,
void* ud) =
nullptr;
341 const std::vector<ToolCall>& tool_calls,
364 char* (*history_json)(
size_t count,
void*
user_data) =
nullptr;
387 const std::vector<const Directive*>& directives,
419 std::string& conversation_id,
428 const char* conversation_id,
429 const char* messages_json,
443 const char* parent_id,
444 const char* delegating_tier,
445 const char* target_tier,
448 std::string& delegation_id,
449 std::string& child_conversation_id,
459 const char* delegation_id,
470 const char* conversation_id,
471 const char* messages_json,
487 const char* delegation_id,
488 std::string& result_json,
506 const char* pattern,
bool allow,
void* user_data);
Directive processing for tool-to-engine communication.
Shared enumerations used across .so boundaries.
@ ENTROPIC_AGENT_STATE_COMPLETE
Turn finished.
@ ENTROPIC_AGENT_STATE_DELEGATING
Child delegation running.
@ ENTROPIC_AGENT_STATE_VERIFYING
Post-generation verification.
@ ENTROPIC_AGENT_STATE_PAUSED
Awaiting user input.
@ ENTROPIC_AGENT_STATE_EXECUTING
Generating response.
@ ENTROPIC_AGENT_STATE_WAITING_TOOL
Tool call in progress.
@ ENTROPIC_AGENT_STATE_IDLE
No active generation.
@ ENTROPIC_AGENT_STATE_PLANNING
Assembling context and tools.
@ ENTROPIC_AGENT_STATE_ERROR
Unrecoverable error.
@ ENTROPIC_AGENT_STATE_INTERRUPTED
Cancelled by consumer.
Message struct for conversation history.
Activate model on GPU (WARM → ACTIVE).
@ error
Tool server returned an error payload.
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.
@ 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::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?
Aggregate result of processing a batch of directives.
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 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.
int max_tool_calls_per_turn
Tool calls per iteration (v1.8.5)
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)
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).
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)
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.
void * user_data
Opaque pointer.
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 ¶m_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.