Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic Namespace Reference

Activate model on GPU (WARM → ACTIVE). More...

Namespaces

namespace  tool_suffix
 The bare tool suffixes this bridge exposes, in advertised order.
 

Classes

struct  AdapterInfo
 Metadata for a loaded LoRA adapter. More...
 
class  AdapterManager
 LoRA adapter lifecycle manager. More...
 
class  AgentEngine
 Core agent execution engine. More...
 
struct  AsyncFinalState
 Handle entropic.context_clear. More...
 
struct  AuditEntry
 A single audit log entry for one MCP tool call. More...
 
struct  AuditHookContext
 Context passed to AuditLogger hook via user_data pointer. More...
 
struct  AuditLogConfig
 Audit log configuration within StorageConfig. More...
 
class  AuditLogger
 JSONL audit logger for MCP tool calls. More...
 
struct  AutoPlacement
 A placement decision, with the reason it was reached. More...
 
struct  BackendInfo
 Backend metadata for introspection. More...
 
struct  BashConfig
 Bash MCP server configuration (v2.13.0). More...
 
class  BashServer
 Bash MCP server for shell command execution. More...
 
struct  BatchKvPlan
 Which sequences a batch will write, and what it may clear. More...
 
struct  CacheEntry
 Single cached KV state snapshot. More...
 
struct  CacheKey
 64-bit hash used as cache lookup key. More...
 
struct  CacheKeyHash
 Hash function for CacheKey in unordered containers. More...
 
struct  CacheStats
 Cumulative cache performance counters. More...
 
class  ChatAdapter
 Concrete base class for chat format adapters (80% logic). More...
 
class  CheckErrorsTool
 Stub tool for LSP error checking. More...
 
struct  ChildContextInfo
 Resolved tier information for building child delegation contexts. More...
 
struct  ClearSelfTodosDirective
 Clear self-directed todos (engine no-op). More...
 
struct  CompactionConfig
 Auto-compaction configuration. More...
 
class  CompactionManager
 Manages automatic context compaction. More...
 
struct  CompactionResult
 Result of a compaction operation. More...
 
struct  CompactorEntry
 A registered compactor entry. More...
 
class  CompactorRegistry
 Per-identity compactor registry and dispatch. More...
 
struct  CompleteDirective
 Signal explicit completion. More...
 
class  CompleteTool
 Tool for signaling task completion. More...
 
struct  ConstitutionalValidationConfig
 Constitutional validation pipeline configuration. More...
 
class  ConstitutionalValidator
 Post-generation constitutional compliance validator. More...
 
struct  ContentPart
 A single content part within a multimodal message. More...
 
struct  ContextAnchorDirective
 Update a keyed persistent context anchor. More...
 
struct  ContextFit
 One turn's irreducible prompt, measured against the tier budget. More...
 
class  ContextInspectTool
 Tool for inspecting the current context window contents. More...
 
class  ContextManager
 Handles context management for the agentic loop. More...
 
struct  ContextManagerHooks
 Engine-level hooks called during context management. More...
 
struct  ContextRef
 One file the lead already paid to find (gh#162, v2.13.0). More...
 
struct  ConversationRecord
 Database record for a conversation. More...
 
struct  ConversationState
 One caller-scoped conversation and its KV bookkeeping. More...
 
struct  CritiqueResult
 Structured result from a single critique generation pass. More...
 
struct  DelegateDirective
 Delegate a task to a child inference loop. More...
 
class  DelegateTool
 Tool for delegating tasks to child inference loops. More...
 
struct  DelegationConfig
 Delegation behaviour knobs (gh#160, v2.13.0). More...
 
class  DelegationManager
 Orchestrates child loop creation and execution. More...
 
struct  DelegationRecord
 Database record for a delegation. More...
 
struct  DelegationResult
 Result returned from a child delegation loop. More...
 
class  DiagnoseTool
 Tool for full engine state snapshots. More...
 
class  DiagnosticsServer
 Diagnostics MCP server with LSP client. More...
 
class  DiagnosticsTool
 Stub tool for LSP diagnostics retrieval. More...
 
struct  Directive
 Base directive — all directives carry a type tag. More...
 
class  DirectiveProcessor
 Processes tool directives via registry-based dispatch. More...
 
struct  DirectiveResult
 Aggregate result of processing a batch of directives. More...
 
class  EditFileTool
 Tool for in-place file editing (string replace or insert). More...
 
struct  EngineCallbacks
 Callback function pointer types for engine events. More...
 
class  EntropicServer
 gh#32 (v2.1.6) resume More...
 
class  ExecuteTool
 Tool for executing shell commands. More...
 
class  ExpertOffloadOverrides
 Owning, null-terminated tensor-buffer override list for expert offload. More...
 
class  ExternalBridge
 Unix socket MCP bridge for external client access. More...
 
class  ExternalMCPClient
 Client for an external MCP server (stdio or SSE). More...
 
struct  ExternalMCPConfig
 External MCP server configuration (Entropic-as-server). More...
 
struct  ExternalServerConfig
 Parsed server entry from .mcp.json. More...
 
struct  ExternalServerEntry
 Configuration for a single external MCP server entry. More...
 
class  FileAccessTracker
 Tracks file read state for read-before-write enforcement. More...
 
struct  FilesystemConfig
 Filesystem MCP server configuration. More...
 
class  FilesystemServer
 Filesystem MCP server with read-before-write enforcement. More...
 
class  FollowupTool
 Recall prior delegation results via storage-backed search. More...
 
struct  FootprintEstimate
 An estimate, or an explicit admission that there isn't one. More...
 
struct  FootprintInputs
 Everything the estimate needs, with no orchestrator or filesystem. More...
 
class  Gemma4Adapter
 Fallback adapter for Gemma-4 tiers; owns the <|channel> markers. More...
 
struct  GenerateResult
 Result of a generate_response call. More...
 
struct  GenerationConfig
 Generation parameters configuration (top-level defaults). More...
 
struct  GenerationEvents
 Atomic flags for interrupt/pause signaling. More...
 
struct  GenerationParams
 Generation parameters for a single inference call. More...
 
struct  GenerationRecord
 One generation's metrics, without its text (gh#154). More...
 
struct  GenerationResult
 Result of a single generation call. More...
 
struct  GenerationSummary
 The numbers a finished generation reports, whatever produced it. More...
 
class  GenericAdapter
 Generic adapter using <tool_call>JSON</tool_call> format. More...
 
struct  GgufShape
 A GGUF's shape, as far as its metadata states it. More...
 
class  GitAddTool
 Tool: git add files (space-separated). More...
 
class  GitBranchTool
 Tool: git branch -a, or git checkout -b name. More...
 
class  GitCheckoutTool
 Tool: git checkout target. More...
 
class  GitCommitTool
 Tool: git commit -m "message", optionally git add -A first. More...
 
class  GitDiffTool
 Tool: git diff [–staged] [file]. More...
 
class  GitLogTool
 Tool: git log -N [–oneline]. More...
 
class  GitResetTool
 Tool: git reset HEAD [files]. More...
 
class  GitServer
 Git MCP server for version control operations. More...
 
class  GitStatusTool
 Tool: git status –short. More...
 
class  GlobTool
 Tool for recursive file pattern matching. More...
 
struct  GPUResourceProfile
 Named GPU resource profile for controlling inference hardware knobs. More...
 
struct  GrammarEntry
 Metadata for a registered grammar. More...
 
struct  GrammarProvenance
 What constrained one decode, and what asked for it (gh#154). More...
 
class  GrammarRegistry
 Centralized grammar registry for named GBNF grammars. More...
 
struct  GrammarValidationInterface
 Grammar validation callbacks injected by the facade. More...
 
class  GrepTool
 Tool for regex content search across files. More...
 
class  HandleApiLock
 gh#59 (v2.3.1): RAII guard combining api_mutex + log scope. More...
 
class  HandleTurnGuard
 gh#144 (v2.12.0): RAII turn claim + log scope, for the RUN paths. More...
 
struct  HealthEvent
 Status change event posted by the monitor thread. More...
 
class  HealthMonitor
 Monitors external server connections and handles reconnection. More...
 
struct  HookEntry
 A single registered hook entry. More...
 
class  HookRegistry
 Thread-safe hook registration and dispatch. More...
 
struct  IdentityConfig
 Full identity configuration. More...
 
class  IdentityManager
 Manages the lifecycle of all identities in the engine. More...
 
struct  IdentityManagerConfig
 Configuration for the identity manager. More...
 
class  IgnoreMatcher
 gitignore-style path matcher (#15, v2.1.4). More...
 
struct  ImagePreprocessConfig
 Image preprocessing configuration. More...
 
class  ImagePreprocessor
 Image preprocessor — validates, resizes, and normalizes images. More...
 
class  InferenceBackend
 Concrete base class for inference backends (80% logic). More...
 
struct  InferenceConfig
 Inference-side configuration knobs (v2.1.11). More...
 
struct  InjectContextDirective
 Inject a message into the conversation context. More...
 
class  InspectTool
 Tool for targeted engine state queries. More...
 
struct  InterfaceContext
 Holds orchestrator + tier for C callback user_data. More...
 
struct  InterruptContext
 Context for interrupted/paused generation. More...
 
struct  JsonCursor
 Lightweight cursor into a JSON string. More...
 
class  ListDirectoryTool
 Tool for listing directory contents. More...
 
class  LlamaCppBackend
 LlamaCppBackend — common llama.cpp patterns (15% layer). More...
 
class  LlamaCppSampler
 Sampler adapter that wraps a llama_sampler* chain. More...
 
class  LlamaCppSamplerFactory
 Factory that builds entropic's canonical llama_sampler chain. More...
 
class  LlamaCppTokenizer
 Tokenizer adapter that forwards to llama.cpp's vocab API. More...
 
struct  LogprobResult
 Per-token log-probability evaluation result. More...
 
struct  LoopConfig
 Configuration for the agentic loop. More...
 
struct  LoopContext
 Mutable state carried through the agentic loop. More...
 
struct  LoopMetrics
 Metrics collected during loop execution. More...
 
struct  LSPConfig
 LSP integration configuration. More...
 
struct  LSPServerConfig
 Configuration for a single LSP server. More...
 
class  MCPAuthorizationManager
 Per-identity MCP authorization with runtime grant/revoke. More...
 
struct  MCPConfig
 MCP server configuration. More...
 
class  MCPJsonDiscovery
 Discovers external MCP servers from .mcp.json files. More...
 
struct  MCPKey
 A single authorized MCP key with access level. More...
 
struct  MCPKeyInterface
 MCP key management callbacks injected by the facade. More...
 
class  MCPKeySet
 Per-identity set of authorized MCP tool keys. More...
 
class  MCPServerBase
 Concrete base class for MCP servers (80% logic). More...
 
struct  Message
 A message in a conversation. More...
 
struct  MessageRecord
 Database record for a message. More...
 
struct  Migration
 A single named migration. More...
 
struct  ModelConfig
 Model configuration for a single tier. More...
 
class  ModelOrchestrator
 Multi-model lifecycle and routing orchestrator. More...
 
struct  ModelsConfig
 Configuration for all models (tiers + router). More...
 
class  Nemotron3Adapter
 Nemotron 3 chat adapter (hybrid Mamba-Transformer family). More...
 
struct  NotifyPresenterDirective
 Generic UI notification passthrough. More...
 
struct  OutsideRootRequest
 One outside-root access awaiting the host's decision (v2.13.0). More...
 
struct  ParsedConfig
 Full parsed configuration. More...
 
struct  ParsedModelResponse
 Content and tool calls extracted from one raw emission. More...
 
struct  ParseResult
 Parsed tool call result: cleaned content + extracted calls. More...
 
struct  PendingDelegation
 Pending single delegation (stored by dir_delegate handler). More...
 
struct  PendingPipeline
 Pending multi-stage pipeline (stored by dir_pipeline handler). More...
 
class  PermissionManager
 Permission manager for MCP tool access control. More...
 
class  PermissionPersister
 Read-modify-write permission patterns in YAML config. More...
 
struct  PermissionPersistInterface
 Permission persistence interface. More...
 
struct  PermissionsConfig
 Tool permission configuration. More...
 
struct  PhaseChangeDirective
 Switch the active inference phase. More...
 
class  PhaseChangeTool
 Tool for switching inference phase. More...
 
struct  PhaseConfig
 Inference parameters for a single identity phase. More...
 
struct  PipelineDirective
 Execute a multi-stage delegation pipeline. More...
 
class  PipelineTool
 Tool for multi-stage delegation pipelines. More...
 
class  PluginServer
 A loaded MCP server plugin and its C-ABI entry points. More...
 
struct  PoolGeometry
 Context geometry derived from a tier's session-pool request. More...
 
struct  PreconditionCheck
 Outcome of precondition checks for a single tool call. More...
 
struct  PreprocessedImage
 Preprocessed image ready for vision encoder. More...
 
class  ProfileRegistry
 Centralized registry for named GPU resource profiles. More...
 
class  PromptCache
 Host-memory KV cache with LRU eviction. More...
 
struct  PromptCacheConfig
 Prompt caching configuration. More...
 
class  PromptLogDedup
 Remembers which message bodies a session's log has already shown. More...
 
class  PruneContextTool
 Tool for pruning old messages from context. More...
 
struct  PruneMessagesDirective
 Prune old tool results from context. More...
 
class  Qwen35Adapter
 Qwen 3.5 MoE chat adapter (20% override layer). More...
 
class  Qwen36Adapter
 Qwen 3.6 MoE chat adapter. More...
 
class  ReadFileTool
 Tool for reading file contents with line numbering. More...
 
struct  ReconnectConfig
 Reconnection policy configuration for external MCP servers. More...
 
class  ReconnectPolicy
 Exponential backoff with jitter for reconnection attempts. More...
 
class  ResponseGenerator
 Handles model response generation, tier routing, pause/injection. More...
 
class  ResumeDelegationTool
 Resume a prior delegation with its conversation seeded. More...
 
struct  RoutingConfig
 Configuration for model routing. More...
 
struct  RoutingResult
 Result metadata from a routing decision. More...
 
class  RunCancelScope
 RAII publication of one run's cancel token to its own thread. More...
 
class  RunSessionScope
 RAII publication of one run's session key to its own thread. More...
 
class  RunStreamScope
 RAII: publish a streaming run's sink to its own thread (gh#208). More...
 
class  Sampler
 Pure-virtual per-generation sampler used by the decode loop. More...
 
class  SamplerFactory
 Factory that materializes a Sampler from GenerationParams. More...
 
struct  SandboxInfo
 Identifies one delegation's sandbox directory. More...
 
class  SandboxManager
 Create, finalize, and discard per-delegation filesystem sandboxes. More...
 
struct  SandboxResult
 Final artifact emitted by a finalized sandbox. More...
 
class  ScopedSandbox
 RAII directory swapper for sandbox-scoped tool execution. More...
 
class  SecondaryModelLoader
 Role-keyed lifecycle manager for non-primary models. More...
 
struct  ServerInfo
 Runtime state of a connected MCP server. More...
 
class  ServerManager
 Manages MCP server instances and routes tool calls. More...
 
struct  ServerResponse
 Structured result from tool execution. More...
 
class  SessionLogger
 Manages session_model.log for raw streaming content. More...
 
class  SessionResidency
 Per-session llama sequence slots and their resident tokens. More...
 
struct  SessionRootInterface
 Where a session's tools live, and what it can reach (gh#160). More...
 
class  SessionScoped
 One T per session key, under one leaf mutex (gh#158). More...
 
class  SessionStateOwner
 A server that keeps state per session and can release it (gh#158). More...
 
struct  SpeculativeConfig
 Speculative-decoding configuration (inference.speculative. More...
 
struct  SpeculativeRunState
 Bundles per-kernel-run mutable state to keep the loop body focused on its responsibility (knots: cognitive ≤ 15, ≤ 3 returns). More...
 
class  SqliteDatabase
 Thread-safe SQLite database wrapper. More...
 
class  SqliteStorageBackend
 SQLite-based storage backend. More...
 
class  SSETransport
 SSE transport: HTTP GET for event stream, POST for requests. More...
 
class  StdioTransport
 Stdio transport: fork/exec child, pipe stdin/stdout. More...
 
struct  StopProcessingDirective
 Stop processing remaining tool calls. More...
 
struct  StorageConfig
 Storage backend configuration. More...
 
struct  StorageInterface
 Storage interface for conversation persistence. More...
 
struct  StreamAccumulator
 Context passed to the streaming token callback. More...
 
class  StreamThinkFilter
 Streaming filter that removes <think> blocks from output. More...
 
struct  ThinkMarkers
 The reasoning-block delimiters a model family emits (gh#108). More...
 
class  ThroughputTracker
 EWMA-based throughput tracker for generation budgeting. More...
 
struct  TierChangeDirective
 Request a tier change. More...
 
struct  TierConfig
 Tier-specific model configuration. More...
 
struct  TierResolutionInterface
 Tier resolution callbacks for delegation and auto-chain. More...
 
struct  TierSamplerOverrides
 Per-tier sampler overrides parsed from identity frontmatter. More...
 
struct  TodoCallbacks
 Callback type for saving/restoring todo list state. More...
 
struct  TodoItem
 Single todo entry. More...
 
class  TodoTool
 Tool for managing a persistent todo list. More...
 
class  TokenCounter
 Track token usage across conversation. More...
 
class  Tokenizer
 Pure-virtual tokenizer surface used by the inference backend. More...
 
class  ToolBase
 Abstract base class for individual MCP tools. More...
 
struct  ToolCall
 A tool call request parsed from model output. More...
 
class  ToolCallHistory
 Fixed-size ring buffer of recent tool calls. More...
 
struct  ToolCallRecord
 Lightweight record of a recent tool call for introspection. More...
 
struct  ToolDefinition
 Parsed tool definition from JSON schema file. More...
 
struct  ToolExecutionInterface
 Tool execution interface for the engine. More...
 
class  ToolExecutor
 Processes tool calls from model output. More...
 
struct  ToolExecutorHooks
 Engine-level hooks called during tool processing. More...
 
class  ToolRegistry
 Manages a collection of ToolBase instances. More...
 
struct  ToolResult
 Result of a tool execution. More...
 
class  ToolRootLock
 Shared/exclusive lock whose exclusive side is re-entrant for its owner, and whose owner passes through the shared side. More...
 
class  ToolRootShared
 RAII shared hold on a ToolRootLock (owner pass-through aware). More...
 
class  Transport
 Abstract transport for external MCP communication. More...
 
struct  ValidationContext
 Context passed through hook user_data. More...
 
struct  ValidationResult
 
struct  Violation
 A single constitutional violation found during critique. More...
 
class  WebFetchTool
 Tool for fetching web page content by URL. More...
 
class  WebSearchTool
 Tool for web search queries. More...
 
class  WebServer
 Web MCP server for web fetch and search. More...
 
struct  WorkspacePrompts
 One workspace's assembled system prompts (gh#179, v2.14.0). More...
 
class  WriteFileTool
 Tool for writing file contents with read-before-write. More...
 

Typedefs

using CompactorFn = std::function< CompactionResult(const std::vector< Message > &messages, const CompactionConfig &config, const std::string &identity)>
 Internal C++ compactor function type.
 
using RunChildLoopFn = void(*)(LoopContext &ctx, void *user_data)
 Callback type for running a child engine loop.
 
using DirectiveHandler = std::function< void(LoopContext &ctx, const Directive &directive, DirectiveResult &result)>
 Directive handler function type.
 
using ToolExecutionFn = std::vector< Message >(*)(LoopContext &ctx, const std::vector< ToolCall > &tool_calls, void *user_data)
 Tool execution callback type.
 
using PermissionPersistFn = void(*)(const char *pattern, bool allow, void *user_data)
 Permission persistence callback type.
 
using TokenCallback = void(*)(const char *, size_t, void *)
 Token callback type matching the C API signature.
 
using OutsideRootApprover = OutsideRootVerdict(*)(const OutsideRootRequest &request, void *user_data)
 Approver the server consults under allow_outside_root: optional.
 
using RunStreamFn = void(*)(const char *chunk, size_t len, void *user_data)
 Signature of a run's stream-chunk sink (gh#208, v2.14.2).
 
using ToolHandler = json(*)(entropic_handle_t, ExternalBridge *, const json &)
 A non-ask tool's handler (v2.14.3).
 

Enumerations

enum class  IdentityOrigin : uint8_t { STATIC = 0 , DYNAMIC = 1 }
 Origin of an identity – how it was created. More...
 
enum class  AgentState : int {
  IDLE = ENTROPIC_AGENT_STATE_IDLE , PLANNING = ENTROPIC_AGENT_STATE_PLANNING , EXECUTING = ENTROPIC_AGENT_STATE_EXECUTING , WAITING_TOOL = ENTROPIC_AGENT_STATE_WAITING_TOOL ,
  VERIFYING = ENTROPIC_AGENT_STATE_VERIFYING , DELEGATING = ENTROPIC_AGENT_STATE_DELEGATING , COMPLETE = ENTROPIC_AGENT_STATE_COMPLETE , ERROR = ENTROPIC_AGENT_STATE_ERROR ,
  INTERRUPTED = ENTROPIC_AGENT_STATE_INTERRUPTED , PAUSED = ENTROPIC_AGENT_STATE_PAUSED
}
 C++ enum class for agent execution states. More...
 
enum class  InterruptMode { CANCEL , PAUSE , INJECT }
 How to handle generation interrupt. More...
 
enum class  ToolApproval { DENY , ALLOW , ALWAYS_DENY , ALWAYS_ALLOW }
 Tool approval responses from user. More...
 
enum class  BudgetMode { off , tokens , wall_clock }
 Thinking-budget gating mode. More...
 
enum class  PathAccess { read , write }
 What a filesystem tool is about to do with a path (v2.13.0). More...
 
enum class  OutsideRootVerdict { approved , rejected , no_approver }
 The host's answer to an OutsideRootRequest (v2.13.0). More...
 
enum class  BackendCapability : int {
  KV_CACHE = 0 , HIDDEN_STATE = 1 , STREAMING = 2 , RAW_COMPLETION = 3 ,
  GRAMMAR = 4 , LORA_ADAPTERS = 5 , MULTI_SEQUENCE = 6 , TOKENIZER = 7 ,
  LOG_PROBS = 8 , VISION = 9 , SPECULATIVE_DECODING = 10 , PROMPT_CACHING = 11 ,
  AUDIO = 12 , _COUNT
}
 Capabilities that an inference backend may or may not support. More...
 
enum class  MCPAccessLevel : uint8_t { NONE = 0 , READ = 1 , WRITE = 2 }
 MCP tool access level for per-identity authorization. More...
 
enum class  ModelState : int { COLD = ENTROPIC_MODEL_STATE_COLD , WARM = ENTROPIC_MODEL_STATE_WARM , ACTIVE = ENTROPIC_MODEL_STATE_ACTIVE }
 C++ enum class for model VRAM lifecycle states. More...
 
enum class  AdapterState : int { COLD = 0 , WARM = 1 , HOT = 2 }
 LoRA adapter lifecycle state. More...
 
enum class  OutsideRootAccess { refuse , allow , optional }
 What the filesystem server does with a path outside its root. More...
 
enum class  DelegationIsolation { none , sandbox }
 How a delegation's filesystem writes are contained (gh#160). More...
 
enum class  ContentPartType { TEXT , IMAGE }
 Content part type discriminant. More...
 
enum class  ToolResultKind {
  ok = 0 , error , rejected_duplicate , rejected_schema ,
  rejected_precondition , ok_empty , delegation_failed , rejected_anti_spiral ,
  rejected_unauthorized
}
 Categorical outcome of a single tool invocation. More...
 
enum class  ValidationVerdict {
  passed = 0 , revised , rejected_reverted_length , rejected_max_revisions ,
  skipped , paused_pending_consumer , passed_consumer_override
}
 Result of the full validation pipeline (critique + optional revision). More...
 
enum class  EmptyContentCause {
  not_empty , tool_call_only , budget_truncated , model_stopped ,
  unknown
}
 Why a turn produced tokens but delivered no content. More...
 
enum class  GrammarSource {
  none , request , tier , tool_call ,
  count
}
 Which source, if any, constrains the decode. More...
 
enum class  Offload { none , full , partial_unknown }
 Where a tier's weights land, as far as the estimate can tell. More...
 
enum class  McpJsonConfigVerdict { disabled , enabled , ask }
 What configuration alone says about a discovered server. More...
 

Functions

const char * agent_state_name (AgentState state)
 Get the string name for an AgentState value.
 
std::vector< ToolCall > recover_action_envelope_calls (const std::string &raw)
 gh#88: recover tool calls a gemma model parroted as bare-JSON.
 
void apply_action_envelope_recovery (std::vector< ToolCall > &calls, const std::string &raw)
 gh#88: substitute recovered bare-JSON calls when a reliable (PEG_GEMMA4 / gemma) parse produced none; logs the recovery.
 
void coerce_string_typed_args (std::vector< ToolCall > &calls, const std::string &tools_json)
 gh#90: coerce numeric scalars back to strings for string-typed tool parameters.
 
InferenceInterface build_orchestrator_interface (ModelOrchestrator *orchestrator, const std::string &default_tier, InterfaceContext **out_context)
 Build an InferenceInterface wired to an orchestrator.
 
void destroy_orchestrator_interface (InterfaceContext *context)
 Free a context returned by build_orchestrator_interface().
 
ENTROPIC_EXPORT void apply_tier_sampler_overrides (GenerationParams &params, const TierSamplerOverrides &ov)
 Apply per-tier sampler overrides to params.
 
std::filesystem::path compute_socket_path (const std::filesystem::path &project_dir)
 Compute project-unique Unix socket path for self-detection.
 
bool is_blocked_env_var (const std::string &key)
 Environment variable blocklist for .mcp.json env field.
 
ToolDefinition load_tool_definition (const std::string &tool_name, const std::string &server_prefix, const std::string &data_dir)
 Load a tool definition from a JSON file.
 
std::string render_response_format (const std::string &output_schema_json)
 Render an outputSchema as the compact "Response format" text a model reads (gh#203).
 
std::string tool_error_json (const std::string &code, const std::string &message)
 A declared tool error: {"error": code, "message": message}.
 
std::string summarize_params (const std::string &args_json)
 Extract top-level JSON keys as a comma-separated summary.
 
std::string truncate_result (const std::string &text, size_t max_len)
 Truncate a string to max_len characters with "..." suffix.
 
nlohmann::json audit_entry_to_json (const AuditEntry &entry)
 Serialize AuditEntry fields to a JSON object.
 
bool audit_entry_from_json (const nlohmann::json &j, AuditEntry &entry)
 Deserialize AuditEntry fields from a JSON object.
 
void populate_from_hook_context (AuditEntry &entry, const AuditHookContext &ctx)
 Populate AuditEntry fields from AuditHookContext state.
 
std::string generate_uuid ()
 Generate a UUID v4 string.
 
std::string utc_timestamp ()
 Get current UTC time as ISO 8601 string.
 
ConversationRecord make_conversation (const std::string &title="New Conversation", const std::optional< std::string > &project_path=std::nullopt, const std::optional< std::string > &model_id=std::nullopt)
 Create a new ConversationRecord with generated UUID and timestamps.
 
DelegationRecord make_delegation (const std::string &parent_conversation_id, const std::string &child_conversation_id, const std::string &delegating_tier, const std::string &target_tier, const std::string &task)
 Create a new DelegationRecord with generated UUID and timestamp.
 
const char * mcp_access_level_name (MCPAccessLevel level)
 Convert MCPAccessLevel to string representation.
 
bool parse_mcp_access_level (const std::string &name, MCPAccessLevel &out)
 Parse MCPAccessLevel from string.
 
ModelConfig make_default_draft_model_config ()
 Speculative decoding configuration (v2.1.11, gh#36).
 
std::string extract_text (const std::vector< ContentPart > &parts)
 Extract concatenated text from content parts.
 
bool has_images (const std::vector< ContentPart > &parts)
 Check if content parts contain any image parts.
 
GenerationRecord make_generation_record (const GenerationResult &r)
 Project a result down to the record kept for metrics.
 
std::vector< Message > parse_messages_json (const char *json_str)
 Parse a JSON array of messages into a vector of Message.
 
bool any_message_has_images (const std::vector< Message > &messages)
 Convenience: true if any message carries image content_parts.
 
ENTROPIC_EXPORT const std::atomic< bool > * current_run_cancel ()
 The cancel token of the run executing on this thread, if any.
 
ENTROPIC_EXPORT bool current_run_cancelled ()
 Whether THIS thread's run has been cancelled.
 
ENTROPIC_EXPORT bool cancel_current_run ()
 Cancel the run executing on this thread (gh#158).
 
ENTROPIC_EXPORT std::string current_run_session ()
 The session key of the run executing on this thread (gh#166).
 
ENTROPIC_EXPORT bool emit_to_current_run_stream (const char *chunk, size_t len)
 Deliver a chunk to the stream sink published on THIS thread.
 
const char * result_kind_to_string (ToolResultKind kind)
 Serialize a ToolResultKind to its wire-stable string form.
 
static void partition_messages (const std::vector< Message > &messages, size_t start, std::vector< const Message * > &user_msgs, std::vector< const Message * > &assistant_msgs, int &stripped_count)
 Partition messages (from start) into user/assistant/stripped.
 
static std::vector< Message > assemble_compacted (const Message *system_msg, Message summary_msg, const std::vector< const Message * > &user_msgs, const std::vector< const Message * > &assistant_msgs)
 Assemble the compacted list: system, summary, users, last asst.
 
static bool is_tool_result (const Message &msg)
 Extract original user task from messages.
 
static std::string find_tagged (const std::vector< Message > &messages, const std::string &source)
 Find the first message matching a source tag.
 
static std::string find_first_user_task (const std::vector< Message > &messages)
 Find the first user-role message that isn't a tool result.
 
static std::string json_escape (const std::string &input)
 Save pre-compaction snapshot via storage interface.
 
static std::string serialize_messages_json (const std::vector< Message > &messages)
 Serialize messages to minimal JSON array.
 
static const char * json_escape_char (char c)
 Map a character to its JSON escape sequence.
 
static std::string json_escape (const std::string &input)
 Escape a string for JSON embedding.
 
static std::string serialize_messages (const std::vector< Message > &messages)
 Serialize messages to minimal JSON array.
 
static std::string serialize_config (const CompactionConfig &config, const std::string &identity, int token_count)
 Serialize compaction config + identity to JSON.
 
static void json_skip_ws (JsonCursor &c)
 Skip whitespace in a JSON cursor.
 
static char json_unescape_char (char ch)
 Decode one JSON escape sequence character.
 
static bool json_read_string (JsonCursor &c, std::string &out)
 Read a JSON quoted string from cursor.
 
static void json_skip_composite (JsonCursor &c)
 Skip a JSON array or object in cursor (nested-aware).
 
static void json_skip_value (JsonCursor &c)
 Skip one JSON value (string, primitive, array, or object).
 
static bool json_read_content_part_field (JsonCursor &c, std::string &type_val, std::string &text_val)
 Read one field of a content part object into type/text.
 
static bool json_parse_content_part (JsonCursor &c, std::string &type_val, std::string &text_val)
 Parse one content part object, extract type and text.
 
static void append_text_part (const std::string &type_val, const std::string &text_val, std::string &text)
 Append text from a content part if type == "text".
 
static char json_skip_to_element (JsonCursor &c)
 Read one content part object from an array cursor.
 
static bool json_read_one_content_part (JsonCursor &c, std::string &text)
 Parse one content part object and append text if applicable.
 
static bool json_extract_text_from_array (JsonCursor &c, std::string &text)
 Extract concatenated text from a JSON content array.
 
static bool json_read_field (JsonCursor &c, Message &msg)
 Read one key:value pair and apply to message fields.
 
static bool json_parse_message (JsonCursor &c, Message &msg)
 Parse one JSON object into a Message (role + content).
 
static bool json_parse_array (JsonCursor &c, std::vector< Message > &messages)
 Parse message objects from a JSON array cursor.
 
static bool parse_messages (const char *json, std::vector< Message > &messages)
 Parse a JSON array of message objects.
 
static bool is_pure_tool_call (const std::string &content)
 Check if content is a pure tool call with no prose.
 
static std::string strip_reasoning (const std::string &content, const std::string &open, const std::string &close)
 Strip reasoning blocks from content before critique (gh#108).
 
static std::string json_escape (const std::string &s)
 Escape a string for JSON embedding.
 
static ent_delegation_result_t build_delegation_result_struct (const SandboxInfo &sb_info, const SandboxResult &sandbox_result, const DelegationResult &result, const std::vector< const char * > &files_c, size_t files_len)
 Deliver a finalized patch to consumer or pending/.
 
static std::string pipeline_context (size_t stage_idx, size_t total, const std::vector< std::string > &stages, const std::string &prior_output)
 Build pipeline context prefix for a stage.
 
static void fire_hook_info (const HookInterface &hooks, entropic_hook_point_t point, const char *json)
 Fire an informational hook if the interface is wired.
 
static void fire_loop_start_hook (const HookInterface &hooks, const LoopContext &ctx)
 Build + fire the ON_LOOP_START info hook.
 
static void fire_loop_end_hook (const HookInterface &hooks, const LoopContext &ctx)
 Build + fire the ON_LOOP_END info hook.
 
static void fire_loop_iteration_hook (const HookInterface &hooks, const LoopContext &ctx)
 Build + fire the ON_LOOP_ITERATION info hook.
 
static void fire_context_assemble_hook (const HookInterface &hooks, const LoopContext &ctx)
 Build + fire the ON_CONTEXT_ASSEMBLE info hook.
 
static void remove_anchor_messages (LoopContext &ctx, const std::string &key)
 Remove messages with a specific anchor key.
 
static double now_seconds ()
 Get current time as seconds since epoch.
 
static std::string last_substantive_assistant (const LoopContext &ctx)
 The last assistant message with something in it (gh#169).
 
static std::string annotate_hard_stop (const std::string &carried, const std::string &reason, const std::string &stop_noun)
 Build an engine-forced stop's final assistant content.
 
static ToolCall build_tool_call_from_json (const nlohmann::json &obj, const std::string &tc_str)
 Parse tool calls from raw model output.
 
static std::vector< ToolCall > decode_tool_calls_json (const std::string &tc_str)
 Decode a JSON tool-calls array string into ToolCall vector.
 
static const std::array< const char *, 256 > & json_escape_table ()
 256-entry table mapping bytes to JSON escape sequences.
 
static std::string json_escape_engine (const std::string &s)
 JSON-escape a string (no surrounding quotes).
 
static std::string build_tool_manifest (const std::vector< Message > &messages)
 Build tool call manifest from conversation messages.
 
static std::string format_tool_evidence_entry (const Message &msg, size_t chars_per_result)
 Format one tool-result message for the evidence block.
 
static std::string build_tool_evidence (const std::vector< Message > &messages, size_t max_results, size_t chars_per_result)
 Build un-pruned tool-result evidence for the validator.
 
static std::string enrich_manifest_with_history (const std::string &base, const ToolExecutionInterface &tool_exec)
 Append executor history (if any) to the tool manifest.
 
static std::string extract_system_prompt (const std::vector< Message > &messages)
 Extract the first system message content from messages.
 
static std::string build_tool_results_json (const std::vector< Message > &messages)
 Build a JSON array of tool results from context messages.
 
static void run_child_loop_trampoline (LoopContext &ctx, void *user_data)
 Trampoline for DelegationManager to call engine loop.
 
static void push_delegation_rejected (LoopContext &ctx)
 Append a delegation rejection message to the loop context.
 
static void push_delegation_cycle_rejected (LoopContext &ctx, const std::string &target)
 Append a structured cycle-rejection message to the loop context so the model can recover.
 
static void push_delegation_result (LoopContext &ctx, const std::string &target, const DelegationResult &result)
 Append a delegation result message to the loop context.
 
static void push_delegation_repeat_blocked (LoopContext &ctx, const std::string &target, int n)
 Append a "stop retrying same target" reject message (gh#64).
 
static void push_delegation_isolation_unsafe (LoopContext &ctx, const std::string &target, const std::vector< std::string > &tools)
 Append the "isolation cannot be honoured" reject message (gh#160).
 
static std::string build_coverage_gap_message (const std::string &tier, const DelegationResult &result)
 Build the [COVERAGE GAP] message body that goes back to lead when a relay-tier child returns coverage_gap=true (#10, v2.1.4).
 
static void fold_delegation_summary (LoopContext &ctx, const std::string &summary)
 gh#119 (v2.9.17): fold child summary into the lead's empty delegate turn.
 
static void push_resume_failure (LoopContext &ctx, const std::string &reason, const std::string &delegation_id)
 Lazy session-scoped SandboxManager accessor (gh#33, v2.1.6).
 
static std::string concat_user_echo (const std::vector< Message > &messages)
 Concatenate user-role message text for session-log echo.
 
static std::string join_csv (const std::vector< std::string > &v)
 Join a vector of strings with comma separators.
 
static const std::regex s_name_regex ("^[a-z][a-z0-9_-]{0,63}$")
 Compiled regex for identity name validation.
 
static std::string validate_phases (const std::unordered_map< std::string, PhaseConfig > &phases)
 Validate all phases in an identity config.
 
static std::string validate_fields (const IdentityConfig &config)
 Validate phases and adapter_path fields.
 
static entropic_error_t check_create_preconditions (const IdentityConfig &config, const IdentityManagerConfig &mgr_config, const std::unordered_map< std::string, IdentityConfig > &identities)
 Check create preconditions before validation.
 
static entropic_error_t check_mutable (const std::string &name, const std::unordered_map< std::string, IdentityConfig > &identities, std::unordered_map< std::string, IdentityConfig >::const_iterator &out_it)
 Check that a mutable identity exists and is dynamic.
 
bool prompt_log_unabridged ()
 Whether the operator has demanded unabridged prompt logs.
 
std::string prompt_log_reference (size_t index, const std::string &role, size_t size_chars, size_t content_hash)
 The one-line stand-in for a body already shown earlier in the log.
 
static bool generation_cancelled (const GenerationEvents &events)
 Whether the generation in progress must stop (gh#158).
 
static void log_system_message (size_t i, const Message &msg, const std::string &tier)
 Log the system message, in full only when it has changed.
 
static void log_other_message (size_t i, const Message &msg, entropic::PromptLogDedup &dedup)
 Log one non-system message, in full the first time only.
 
static void log_prompt (const std::vector< Message > &messages, const std::string &tier)
 Log the assembled prompt, each distinct body in full exactly once.
 
static void stream_token_callback (const char *token, size_t len, void *user_data)
 Token callback for streaming generation.
 
static std::string resolve_stream_finish_reason (int rc, size_t content_size)
 Resolve a stream's finish_reason from rc + content size.
 
static bool flag_raised (const std::atomic< bool > *flag)
 Whether a nullable stop flag is set (gh#158).
 
static bool apply_terminal_batch_rc (int rc, const char *result_json, GenerateResult &result)
 Map a TERMINAL batch return code onto the result, if it is one.
 
static void json_escape_into (const std::string &s, std::string &out)
 Serialize messages to JSON for inference interface.
 
static void serialize_content_parts (const std::vector< ContentPart > &parts, std::string &out)
 Serialize a single multimodal content_parts array (gh#37, v2.1.8).
 
static bool snapshot_git_project (const std::filesystem::path &source, const std::filesystem::path &target)
 Copy git-tracked + untracked-not-ignored files from a project.
 
static bool snapshot_plain_copy (const std::filesystem::path &source, const std::filesystem::path &target)
 Recursive copy for non-git sources (or sandbox-to-sandbox chains).
 
static bool capture_diff (const std::filesystem::path &base, const std::filesystem::path &head, std::string &patch)
 Run git diff --no-index between base and head, capture patch.
 
static void trim_path_prefix (std::string &line, std::string p)
 Strip a directory prefix p from the front of line.
 
static std::vector< std::filesystem::path > diff_files (const std::filesystem::path &base, const std::filesystem::path &head)
 List files differing between base and head via diff -rq-style logic.
 
static int utf8_char_len (unsigned char byte)
 Count expected bytes in a UTF-8 sequence from lead byte.
 
EntropicWorkspace * workspace_for (entropic_handle_t h, const std::string &key)
 The workspace a session is bound to, or nullptr for the default.
 
entropic::ServerManager * workspace_servers (entropic_handle_t h, const std::string &key)
 The MCP servers a session's tools must run against (gh#166).
 
void wire_outside_root_approver (entropic_handle_t h)
 Point the DEFAULT server set's filesystem server at the handle's path-approval slot (v2.13.0).
 
std::filesystem::path expected_bridge_socket (entropic_handle_t h)
 The socket this handle's external bridge binds, or empty when the handle runs no bridge (v2.14.0, gh#200).
 
std::filesystem::path bridge_project_dir (entropic_handle_t h)
 The project dir the external bridge derives its socket from.
 
void wire_external_server_policy (entropic_handle_t h, ServerManager &servers, bool with_declared)
 Give a server set the handle's external-server policy (v2.14.0).
 
void apply_workspace_app_context (entropic_handle_t h, const std::string &workspace, const std::optional< std::string > &app_context)
 Give a workspace's sessions prompts built on its own app_context (gh#179), or return them to the handle's.
 
ENTROPIC_EXPORT void swap_session_tool_dir (const std::string &session_key, const std::filesystem::path &path, bool entering, void *ud)
 The facade's gh#160 ScopedSandbox swap callback.
 
std::size_t release_session_tool_state (entropic_handle_t h, const std::string &key)
 Release a session's per-session tool state on every server set (gh#158).
 
static std::string rpc_ok (const json &id, const json &result)
 Build a JSON-RPC success response.
 
static std::string rpc_err (const json &id, int code, const std::string &msg)
 Build a JSON-RPC error response.
 
static json tool_text (const std::string &text)
 Wrap text in MCP tool result shape.
 
static std::string describe (const ExternalMCPConfig &cfg, const char *suffix, const char *fallback)
 Resolve a tool's description, honouring any consumer override.
 
static json no_args_tool (const ExternalMCPConfig &cfg, const char *suffix, const char *fallback)
 Definition for a tool that takes no arguments.
 
static json session_scoped_tool (const ExternalMCPConfig &cfg, const char *suffix, const char *fallback)
 Definition for a tool scoped to an optional session (gh#144).
 
static json ask_tool (const ExternalMCPConfig &cfg)
 Definition for the ask tool (prompt + optional async).
 
static json ask_status_tool (const ExternalMCPConfig &cfg)
 Definition for the ask_status tool (task_id lookup).
 
static json tool_definitions (const ExternalMCPConfig &cfg)
 MCP tool definitions exposed by the bridge.
 
static void write_json_line (int fd, const json &msg)
 Write a JSON-RPC line to a socket fd.
 
static void send_progress (int fd, const std::string &token_text, const json &progress_token, uint64_t seq)
 Send an MCP progress notification with a text token.
 
static json final_answer_from_context (entropic_handle_t handle, const std::string &session_key)
 Read the live conversation and render the operator-visible answer.
 
static entropic_error_t run_plain_turn (entropic_handle_t handle, const std::string &session_key, const std::string &tier, const std::string &prompt, char **result_json)
 Run one non-streaming turn, under tier when one is given (gh#205).
 
static entropic_error_t run_stream_turn (entropic_handle_t handle, const std::string &session_key, const std::string &tier, const std::string &prompt, void(*on_token)(const char *, size_t, void *), void *ud)
 Run one streaming turn, under tier when one is given (gh#205).
 
static json handle_ask_plain (entropic_handle_t handle, const json &args, const std::string &session_key)
 Handle entropic.ask — non-streaming path (gh#115, v2.9.12).
 
static json handle_ask (entropic_handle_t handle, const json &args, const std::string &session_key, int client_fd, const json &progress_token)
 Handle entropic.ask — stream tokens then return final text.
 
static json handle_status (entropic_handle_t handle, const ExternalBridge *bridge)
 Handle the status tool.
 
static AsyncFinalState derive_async_final_state (entropic_handle_t handle, entropic_error_t err, char *result_json)
 Translate entropic_run's return code into a final task state.
 
static bool mark_tasks_cancelling (ExternalBridge *bridge, const std::string &session_key)
 Mark one session's queued/running tasks as cancelling.
 
static bool any_cancelling_left (ExternalBridge *bridge, const std::string &session_key)
 True while one session's task is still phase=cancelling.
 
static void cancel_inflight_async_tasks (entropic_handle_t handle, ExternalBridge *bridge, const std::string &session_key)
 Cancel any async tasks currently running on the bridge.
 
static json handle_clear (entropic_handle_t handle, ExternalBridge *bridge, const std::string &session_key)
 entropic.context_clear MCP tool handler.
 
static json handle_count (entropic_handle_t handle, const std::string &session_key)
 Handle entropic.context_count.
 
static std::string generate_task_id ()
 Generate a simple UUID-like task ID.
 
static std::string bound_workspace (entropic_handle_t handle, const std::string &session_key)
 The session's current workspace binding, or "" (gh#205).
 
static std::string resolve_workspace (entropic_handle_t handle, const std::string &workspace, std::string &err)
 Resolve workspace to a workspace name, creating one for a path.
 
static std::string bind_session_workspace (entropic_handle_t handle, const std::string &session_key, const std::string &workspace)
 Bind a session to the requested workspace, idempotently (gh#205).
 
static json ask_in_turn (entropic_handle_t handle, ExternalBridge *bridge, const json &args, const std::string &session_key, int client_fd, const json &progress_token)
 Run a sync ask once this session's turn comes up (gh#144, gh#205).
 
static json dispatch_ask (entropic_handle_t handle, ExternalBridge *bridge, const json &args, int client_fd, const json &progress_token)
 Route entropic.ask — sync (streaming) or async.
 
static std::string resident_tiers (entropic_handle_t handle)
 Names of the models resident right now, from the snapshot.
 
static json handle_release (entropic_handle_t handle)
 release: unload every resident model, keep everything else.
 
static const std::unordered_map< std::string, ToolHandler > & tool_handlers ()
 Non-ask tools by suffix (v2.14.3).
 
static json dispatch_tool (entropic_handle_t handle, ExternalBridge *bridge, const json &params, int client_fd, const std::string &call_id)
 Dispatch a tools/call to the appropriate handler.
 
static void prepare_socket_dir (const std::filesystem::path &parent)
 Prepare the socket containing directory with 0700 perms.
 
static bool socket_path_safe (const std::filesystem::path &path)
 Reject a pre-existing path that is a symlink or non-socket.
 
static bool bind_and_listen (int fd, const std::filesystem::path &path)
 Bind+listen on an AF_UNIX socket, applying 0600 perms.
 
static int create_listen_socket (const std::filesystem::path &path)
 Create, bind, and listen on a unix domain socket.
 
static bool peer_uid_matches (int client_fd)
 Validate that the connecting peer shares the engine's UID.
 
static std::string read_line (int fd)
 Read one newline-delimited line from a socket fd.
 
static json initialize_result (const ExternalMCPConfig &cfg)
 Build the MCP initialize response payload.
 
static void phase_observer_cb (int state, void *ud)
 State observer that projects VERIFYING onto task phase.
 
static json task_complete_notification (const std::string &task_id, const std::string &status)
 The completion notification for an async task (Issue #4, v2.1.2).
 
static bool send_nonblocking (int fd, const std::string &payload)
 One non-blocking write of a whole payload to one fd.
 
static const char * sentinel_suffix_for_status (const std::string &status)
 Map a terminal status string to a sentinel filename suffix.
 
static std::optional< ToolCall > action_envelope_to_call (const nlohmann::json &j)
 Map one parsed JSON object to a recovered ToolCall.
 
static std::unordered_set< std::string > tool_string_props (const nlohmann::json &tools, const std::string &name)
 String-typed property names for a tool in the staged MCP defs.
 
static void coerce_call_string_args (ToolCall &tc, const nlohmann::json &tools)
 Coerce one call's numeric args to strings per the tool schema.
 
static std::optional< ToolCall > parse_recovered_tool_call (const std::string &fixed)
 Parse a brace/quote-fixed JSON string into a ToolCall.
 
static std::optional< ToolCall > regex_recovered_tool_call (const std::string &json_str)
 Last-ditch recovery: pull a tool name out via regex.
 
logger info ("JSON recovery attempt: {} chars", json_str.size())
 
std::unique_ptr< ChatAdapter > create_adapter (const std::string &name, const std::string &tier_name, const std::string &identity_prompt)
 Create adapter by name (gh#87 Phase D hybrid).
 
static nlohmann::json build_tool_defs (const std::vector< std::string > &tool_jsons)
 Build the OpenAI-function <tools> JSON array for injection.
 
uint64_t compute_allowance_bytes (const FootprintInputs &base, int n_ubatch)
 VRAM to hold back for graph/activation scratch.
 
bool placement_fits (const FootprintInputs &base, const GgufShape &shape, int gpu_layers, int cpu_moe_layers, uint64_t budget_bytes, uint64_t *used)
 Does a candidate placement fit the budget?
 
bool try_fully_resident (const GgufShape &shape, const FootprintInputs &base, uint64_t budget, AutoPlacement *out)
 Try the best case: every layer and every expert on the card.
 
bool try_expert_offload (const GgufShape &shape, const FootprintInputs &base, uint64_t budget, AutoPlacement *out)
 Try keeping every layer resident by moving experts host-side.
 
bool try_fewer_layers (const GgufShape &shape, const FootprintInputs &base, uint64_t budget, AutoPlacement *out)
 Last resort: take the largest layer count that fits.
 
bool try_smaller_ubatch (const GgufShape &shape, const FootprintInputs &base, uint64_t free_vram_bytes, int configured, AutoPlacement *out)
 Try full residency at each ubatch below the configured one.
 
AutoPlacement derive_auto_placement (const GgufShape &shape, const FootprintInputs &base, uint64_t free_vram_bytes, int n_ubatch=0)
 Choose the placement that uses the card best without overcommitting.
 
BatchKvPlan plan_batch_kv (std::size_t n, int session_slots, const std::vector< int > &temp_ids)
 Plan the sequence ids a same-prefix batch may use.
 
bool plan_disturbs_sessions (const BatchKvPlan &plan, int session_slots)
 Whether a plan can disturb any session's resident KV.
 
template<typename Tok >
std::size_t batch_shared_prefix_len (const std::vector< std::vector< Tok > > &seqs)
 Longest shared token prefix across N request sequences (gh#98).
 
bool batch_is_viable (std::size_t n, int n_parallel, std::size_t shared, bool hybrid, std::size_t total_suffix, int n_batch)
 Decide whether the same-prefix batch fast-path is safe + worthwhile.
 
bool context_fit_overflows (const ContextFit &f)
 Whether this turn's prompt cannot fit the tier's context at all.
 
int context_fit_history_tokens (const ContextFit &f)
 Tokens left over once system prompt and tool block are accounted.
 
std::string context_fit_largest_contributor (const ContextFit &f)
 Name the single largest contributor to the overflow.
 
std::string context_fit_breakdown (const ContextFit &f)
 Per-contributor token breakdown, as one clause.
 
std::string context_overflow_message (const ContextFit &f)
 The refusal an operator reads, carrying every number they need.
 
uint64_t query_device_free_vram_bytes ()
 Free VRAM on the first GPU device ggml reports, in bytes.
 
uint64_t host_memlock_limit_bytes ()
 This process's RLIMIT_MEMLOCK soft limit (gh#148).
 
uint64_t device_memory_query_count ()
 How many device free-VRAM queries this process has made (gh#198).
 
EmptyContentCause diagnose_empty_content (bool content_empty, bool produced_tokens, const std::string &finish_reason, bool has_tool_calls)
 Classify an empty-content turn from what the decode reported.
 
std::string explain_empty_content (EmptyContentCause cause)
 Operator-facing explanation for an empty-content turn.
 
std::string expert_block_pattern (int layer)
 The override pattern for ONE layer's expert tensors.
 
std::vector< std::string > expert_offload_patterns (int cpu_moe_layers)
 Patterns for the FIRST cpu_moe_layers layers, in layer order.
 
std::string expert_offload_conflict_reason (const ModelConfig &cfg)
 Configuration-time refusal for a combination that cannot mean what it says.
 
std::string expert_offload_load_refusal (int cpu_moe_layers, int n_layer, int n_expert)
 Post-load refusal, against the numbers only the loaded model knows.
 
std::string format_generation_summary (const GenerationSummary &s)
 Format the one-line generation summary.
 
GgufShape read_gguf_shape (const std::string &path)
 Read a GGUF's shape from its metadata, without loading tensor data.
 
static std::optional< GrammarEntry > build_grammar_entry (const std::filesystem::path &path)
 Load all bundled grammars from a directory.
 
constexpr int grammar_source_count ()
 Number of declared grammar sources, sentinel excluded.
 
GrammarSource resolve_grammar_source (const std::string &request_grammar, const std::string &tool_grammar, bool request_from_tier=false)
 Resolve which grammar wins.
 
bool is_request_grammar (GrammarSource source)
 Whether a source is applied as a request-side grammar.
 
bool tier_grammar_unresolved (const GenerationParams &params)
 A TIER named a grammar and nothing resolved it (gh#154).
 
const char * grammar_source_name (GrammarSource source)
 Stable wire name for a grammar source.
 
bool grammar_sources_collide (const std::string &request_grammar, const std::string &tool_grammar)
 Whether both sources are active — a config error worth reporting.
 
GrammarProvenance describe_grammar (const GenerationParams &params, const std::string &tool_grammar)
 Describe what constrained one decode, for the result record (gh#154).
 
static std::vector< uint8_t > read_image_bytes (const std::filesystem::path &path, size_t max_file_size)
 Validate + read an image file fully into a byte buffer.
 
static std::vector< Message > parse_msgs (const char *json_str)
 Parse JSON message array into Message vector.
 
template<typename T >
static void assign_if_present (const nlohmann::json &j, const char *key, T &dst)
 Conditionally assign a typed JSON field into a destination.
 
static void parse_logit_bias_into (const nlohmann::json &j, std::unordered_map< int32_t, float > &dst)
 Populate logit_bias map from a JSON object of token→bias.
 
static GenerationParams parse_params (const char *json_str)
 Parse generation params from JSON string.
 
static std::string extract_tier (const char *json_str, const std::string &default_tier)
 Extract tier name from params JSON, falling back to default.
 
static char * dup (const std::string &s)
 Heap-allocate a C string copy.
 
static int iface_generate (const char *msgs_json, const char *params_json, char **result_json, void *user_data)
 Generate via orchestrator.
 
static int iface_generate_stream (const char *msgs_json, const char *params_json, void(*on_token)(const char *, size_t, void *), void *token_ud, int *cancel, void *user_data)
 Streaming generate via orchestrator.
 
static int iface_generate_with_cancel (const char *msgs_json, const char *params_json, char **result_json, int *cancel, void *user_data)
 Batch generate with cancel via orchestrator (gh#81, v2.4.2).
 
static int iface_route (const char *msgs_json, char **result_json, void *user_data)
 Route messages to tier via orchestrator.
 
static int iface_complete (const char *prompt, const char *params_json, char **result_json, void *user_data)
 Raw text completion via orchestrator.
 
static std::vector< ToolCall > tc_from_json_obj (const nlohmann::json &j)
 Build a ToolCall from a parsed JSON object with name/tool + arguments/parameters.
 
static std::vector< ToolCall > try_fenced_json_call (const std::string &raw)
 Extract a tool call from a single fenced json block in raw model output (gh#122).
 
static std::string find_unique_args_match (const nlohmann::json &obj, const nlohmann::json &tools)
 Find the unique tool whose required params are all present in obj.
 
static std::optional< nlohmann::json > extract_args_only_fence (const std::string &raw)
 Extract and validate the fenced JSON block for args-only inference.
 
static std::vector< ToolCall > try_fenced_args_object_call (const std::string &raw, const std::string &tools_json)
 Try to synthesise a tool call from a fenced args-only JSON object (gh#127).
 
static void apply_fenced_fallbacks (const std::string &raw, LlamaCppBackend *llama, std::vector< ToolCall > &calls)
 Apply fenced-json and fenced-args-only fallback parsers (gh#122, gh#127).
 
static void parse_via_adapter (ModelOrchestrator *orch, const std::string &raw, const std::string &tier, std::string &out_cleaned, std::vector< ToolCall > &out_calls)
 Parse tool calls via the adapter for the given tier (gh#89).
 
static int iface_parse_tool_calls (const char *raw, char **cleaned, char **tool_calls_json, void *user_data)
 Parse tool calls from raw model output (gh#87 3b).
 
static int iface_is_complete (const char *, const char *tool_calls_json, void *)
 Check if response is complete (no pending tool calls).
 
static void fill_batch_cell (llama_batch &b, int k, llama_token tok, llama_pos pos, llama_seq_id seq, bool want_logits)
 Fill one cell of a multi-seq llama_batch (defined below).
 
static int effective_n_draft (int n_max)
 Draft-window size setup_mtp_draft will actually use (gh#106).
 
static std::vector< llama_chat_message > to_llama_chat (const std::vector< Message > &messages)
 Convert engine messages to llama_chat_message views.
 
static std::vector< common_chat_msg > to_common_chat (const std::vector< Message > &messages)
 Convert engine messages to common_chat_msg (gh#86, v2.6.1).
 
static std::vector< common_chat_tool > mcp_tools_to_common_chat (const std::string &tools_json)
 Convert entropic MCP tool JSON to common_chat_tool defs (gh#87).
 
static ToolCall to_entropic_tool_call (const common_chat_tool_call &cc)
 Map a common_chat_tool_call to entropic's ToolCall (gh#87).
 
static std::optional< common_chat_params > render_common_chat (llama_model *model, const std::vector< Message > &messages, const GenerationParams &params, const std::vector< common_chat_tool > &tools, bool require_tool_call)
 Shared common_chat render core for both template paths (gh#87).
 
static std::string concat_messages_fallback (const std::vector< Message > &messages)
 Plain "role: content" join used when templating fails.
 
void strip_thinking_channels (std::string &content, std::string *reasoning_out)
 Strip Gemma 4 QAT reasoning channels (<|channel>…<channel|>) from content, accumulating the stripped text into reasoning.
 
static GenerationResult batch_error_result (const std::string &msg)
 Build a single error GenerationResult (gh#98 batch failures).
 
static int staged_tool_count (const std::string &tools_json)
 Number of definitions in a staged MCP tool-list JSON array.
 
static void spec_cleanup (SpeculativeRunState &state)
 Free everything allocated by the kernel.
 
static void spec_build_batch (SpeculativeRunState &state)
 Build the target batch [id_last, draft0, ..., draftN-1].
 
static bool spec_decode_both (SpeculativeRunState &state)
 Decode the speculative batch on both contexts.
 
static int spec_run_draft (SpeculativeRunState &state)
 Trigger draft generation via common_speculative_draft.
 
static std::string spec_emit_token (SpeculativeRunState &state, llama_token id, const llama_vocab *vocab, int max_tokens, std::function< void(std::string_view)> &on_token, std::atomic< bool > &cancel)
 Emit on_token for one accepted id, updating state and returning a stop signal when terminating conditions apply.
 
static void spec_ckpt_save_dft (SpeculativeRunState &state)
 Drive one accept round: draft → decode → sample-and-accept → emit tokens.
 
static void spec_ckpt_save_tgt (SpeculativeRunState &state)
 Snapshot target state right before the target decode of the speculative batch (when use_ckpt_tgt + non-empty draft).
 
static void spec_ckpt_restore_dft (SpeculativeRunState &state)
 Restore the draft's pre-draft state so the upcoming target-batch decode on the draft re-fills cleanly.
 
static void spec_rollback_partial (SpeculativeRunState &state, common_sampler *smpl_save, std::vector< llama_token > &ids)
 Partial-acceptance rollback: restore both contexts and the sampler to their pre-draft state, then arrange for the outer loop to re-decode with the partial accept as the new draft.
 
static void spec_trim_rejected_drafts (SpeculativeRunState &state)
 Clear any stale KV positions left by rejected draft tokens.
 
static bool spec_commit_accepted (SpeculativeRunState &state, const std::vector< llama_token > &ids, const llama_vocab *vocab, int max_tokens, std::function< void(std::string_view)> &on_token, std::atomic< bool > &cancel)
 Walk accepted ids, emit tokens via callback, update state.
 
static int spec_prepare_draft (SpeculativeRunState &state)
 Drive one accept round: optional draft generation, decode on both contexts, sample-and-accept, emit tokens (or roll back via checkpoint on partial acceptance).
 
static bool spec_accept_round (SpeculativeRunState &state, const llama_vocab *vocab, int max_tokens, std::function< void(std::string_view)> &on_token, std::atomic< bool > &cancel)
 Run one speculative accept round; return false to stop.
 
static std::string spec_check_preconditions (bool target_active, bool draft_active, llama_context *ctx_tgt, llama_context *ctx_dft)
 Validate speculative preconditions and reject NO-seq_rm.
 
static std::string spec_init_sampler_and_decoder (SpeculativeRunState &state, llama_model *model_tgt, const GenerationParams &params, int n_draft_max, const std::string &draft_path, const std::string &tool_grammar, bool tool_grammar_lazy, const std::string &generation_prompt)
 Initialize the kernel state: clear KV, prefill, sampler, speculative context, batch, and detect FULL-seq_rm checkpoint-mode for target/draft.
 
static std::string spec_init_run (SpeculativeRunState &state, llama_model *model_tgt, const std::vector< llama_token > &tokens, const GenerationParams &params, int n_draft_max, const std::string &draft_path, const std::string &tool_grammar, bool tool_grammar_lazy, const std::string &generation_prompt)
 Initialize speculative run state (prefill + sampler + decoder).
 
static void spec_run_loop (SpeculativeRunState &state, const llama_vocab *vocab, int max_tokens, std::function< void(std::string_view)> &on_token, std::atomic< bool > &cancel)
 Run the accept-round loop until completion / EOS / cancel.
 
static GenerationResult spec_finalize (SpeculativeRunState &state, std::chrono::steady_clock::time_point t0)
 Speculative kernel against an explicit draft backend.
 
static GenerationResult spec_run_from_tokens (llama_context *ctx_tgt, llama_context *ctx_dft, llama_model *model_tgt, const std::vector< llama_token > &tokens, const GenerationParams &params, std::function< void(std::string_view)> &on_token, std::atomic< bool > &cancel, int n_draft_max, const std::string &draft_path, std::chrono::steady_clock::time_point t0, const std::string &tool_grammar, bool tool_grammar_lazy, const std::string &generation_prompt)
 Public entry point for the speculative-decoding kernel.
 
std::string mtp_unsupported_reason (float temperature, bool has_grammar, bool streaming)
 Reason MTP cannot run for a request, or "" when the envelope is safe.
 
bool looks_like_mtp_head (int n_layer)
 True when the model's layer count is consistent with an MTP head GGUF.
 
std::string mtp_head_classical_path_error (int n_layer)
 Actionable error message for gh#107: MTP head on classical path.
 
static bool mtp_head_guard_fires (LlamaCppBackend *draft, GenerationResult &result)
 gh#107: return true (and populate result) when draft looks like an MTP head GGUF routed to the classical separate-draft path.
 
static void stage_active_tools (InferenceBackend *model, const GenerationParams &params, bool require_tool_call)
 Stage the turn's tool defs on the backend for common_chat (gh#87).
 
static void apply_adapter_parse (InferenceBackend *model, ChatAdapter *adapter, GenerationResult &result)
 Split tool calls out of a result (gh#87: common_chat or adapter).
 
static void warn_if_content_vanished (const GenerationResult &result)
 Explain a turn that produced tokens but delivered no content (gh#137).
 
static void warn_if_budget_starved_required_turn (const GenerationResult &result, const std::string &tier_name, const std::unordered_map< std::string, TierConfig > &tiers)
 Diagnose a mandatory-tool turn that ran out of budget (gh#134).
 
static void warn_turn_diagnostics (const GenerationResult &result, const std::string &tier_name, const std::unordered_map< std::string, TierConfig > &tiers)
 Report every post-turn diagnostic from one call site (gh#137).
 
static void log_orchestration (const GenerationResult &result, const std::string &selected, const std::string &adapter_name, const GenerationParams &params, double routing_ms, double swap_ms)
 Log the per-orchestration tier/adapter/timing summary.
 
static void stream_token_trampoline (const char *data, std::size_t len, void *ud)
 Trampoline: bridges TokenCallback C signature to std::function.
 
static FootprintInputs footprint_inputs_for (const TierConfig &tier_cfg, uint64_t weights_bytes, int vram_reserve_mb)
 Gather a tier's footprint inputs for the pure estimator.
 
static llama_model * resolve_target_model (const std::shared_ptr< InferenceBackend > &tier_backend)
 Resolve the active main-tier llama_model* for compat lookup.
 
static std::string normalize_grammar_key (const std::string &grammar_value)
 Normalize a frontmatter grammar value to a registry key.
 
static nlohmann::json make_residency_entry (const std::string &name, const std::filesystem::path &path, int context_length, size_t footprint, int vram_reserve_mb, long long last_ms)
 JSON serialization of the current residency set.
 
int partial_gpu_layers_for (uint64_t file_bytes, uint64_t free_vram_bytes, int n_layers=30)
 Layers to place on the GPU for an oversized model.
 
bool host_can_hold_warm_load (uint64_t file_bytes, uint64_t available_bytes, uint64_t headroom_bytes=1024ull *1024 *1024)
 Whether the host can hold a model's WARM load.
 
bool large_model_tests_waived (uint64_t file_bytes)
 Whether an operator has explicitly waived one LARGE model's test.
 
bool mlock_refused (bool use_mlock, uint64_t file_bytes, int gpu_layers, uint64_t memlock_limit_bytes, uint64_t host_expert_bytes=0)
 Whether an explicit use_mlock would be fatal for this model.
 
bool gpu_offload_refused (uint64_t file_bytes, int gpu_layers, uint64_t free_vram_bytes)
 Whether a requested GPU offload provably cannot fit free VRAM.
 
static std::vector< std::string > required_params (const std::string &tools_json, const std::string &name, bool &found)
 Required parameter names declared by a tool's inputSchema.
 
static bool has_all_required (const nlohmann::json &args, const std::vector< std::string > &required, const std::string &call_name)
 Verify every required key is present, warning on the first absent one.
 
static bool one_call_satisfies_schema (const ToolCall &call, const std::string &tools_json)
 Check one call's declared required parameters are all present.
 
bool calls_satisfy_schema (const std::vector< ToolCall > &calls, const std::string &tools_json)
 Check that every call's declared required parameters are present.
 
static bool try_template_parse (LlamaCppBackend *llama, const std::string &raw, ParsedModelResponse &out)
 Tool calls from the template parser, when trustworthy.
 
ParsedModelResponse parse_model_response (LlamaCppBackend *llama, ChatAdapter *adapter, const std::string &raw)
 Parse a raw emission: template first, adapter second.
 
PoolGeometry derive_pool_geometry (const ModelConfig &cfg)
 Derive the context geometry a tier's config implies.
 
std::string session_pool_conflict_reason (const ModelConfig &cfg)
 Why this tier's session-pool request cannot be honoured.
 
std::string close_marker_for_format (common_chat_format fmt)
 Map a resolved common_chat format to its single-tool-call close marker.
 
void append_sequential_stop (GenerationParams &params, const std::string &marker)
 Append a tool-call close marker to params.stop for sequential mode.
 
std::string serialize_tool_calls (const std::vector< ToolCall > &calls)
 Serialize parsed tool calls to the C-ABI JSON array form.
 
double kv_scale_for_cache_type (const std::string &type)
 Cost of a KV cache type relative to f16.
 
Offload classify_offload (int gpu_layers)
 Classify a tier's offload request into a priceable placement.
 
double kv_bytes_per_token (const FootprintInputs &in)
 Per-token KV cost in bytes for this tier's cache configuration.
 
FootprintEstimate estimate_vram_footprint (const FootprintInputs &in)
 Estimate the VRAM a tier will occupy, or report that it cannot.
 
int recommend_context_length (const FootprintInputs &in, uint64_t available_bytes)
 Largest context length that fits, for the "won't fit" recommendation.
 
template<typename Tok >
std::size_t common_prefix_len (const std::vector< Tok > &a, const std::vector< Tok > &b)
 Length of the longest common token prefix of two sequences.
 
template<typename Tok >
std::size_t warm_keep_cut (const std::vector< Tok > &resident, const std::vector< Tok > &incoming, long kv_pos_max)
 Decide how many resident-KV tokens warm-keep may reuse this turn.
 
McpJsonConfigVerdict mcpjson_config_verdict (const std::string &name, const MCPConfig &cfg)
 Config's verdict on one discovered server.
 
std::string arg_after (const std::vector< std::string > &args, const std::string &flag)
 The value following flag in args, or "".
 
bool is_entropic_bridge (const ExternalServerConfig &cfg)
 Whether a stdio entry runs entropic mcp-bridge.
 
bool launches_own_bridge (const ExternalServerConfig &cfg, const std::filesystem::path &own_socket, const std::filesystem::path &spawn_root)
 Whether launching cfg would connect this handle to itself.
 
std::string discovered_server_json (const ExternalServerConfig &cfg, const std::filesystem::path &root)
 The pre-connect hook's context JSON for one discovered server.
 
static std::vector< std::string > names_diff (const std::set< std::string > &a, const std::set< std::string > &b)
 Names in a not in b (sorted set difference).
 
static bool has_blocked_prefix (const std::string &key)
 Check if key matches a blocked prefix pattern.
 
static const char * directive_type_name (entropic_directive_type_t type)
 Map directive type enum to wire-format string.
 
static void append_prefixed_tools (const std::string &tools_json, const std::string &prefix, nlohmann::json &all)
 Append a server's tools to an array, prefixing each name.
 
static bool tool_is_read_only (const nlohmann::json &tool)
 Whether one tool descriptor asserts readOnlyHint: true (gh#160).
 
static std::string expand_workspace_root (std::string s, const std::string &root)
 Replace every ${ENTROPIC_WORKSPACE_ROOT} with root (v2.14.1).
 
static bool is_safe_cwd (const std::string &cwd)
 Reject working_dir values that would smuggle shell syntax.
 
static size_t carry_context (const nlohmann::json &args, nlohmann::json &result)
 Copy a context argument into the result, dropping junk (gh#162).
 
static std::string pipeline_rejection (const std::vector< std::string > &stages, const std::vector< std::string > &tier_names, const std::vector< std::string > &require_context_tiers, size_t refs)
 Parse pipeline args, validate stages, emit directives.
 
static ToolDefinition phase_change_definition ()
 The inline phase_change definition, contract included.
 
static std::string call_provider (char *(*fn)(void *), void *ud)
 Call a state provider callback and wrap result.
 
static std::string call_history_provider (char *(*fn)(int, void *), int max_entries, void *ud)
 Call history callback with max_entries param.
 
static std::string call_docs_provider (char *(*fn)(const char *, void *), const char *section, void *ud)
 Call docs callback with section param.
 
static nlohmann::json build_snapshot (const entropic_state_provider_t &p, bool include_docs, int history_limit)
 Build the diagnose snapshot JSON.
 
static std::vector< std::string > collect_object_keys (const nlohmann::json &j)
 Collect keys from a JSON object into a vector.
 
static std::vector< std::string > collect_array_names (const nlohmann::json &j)
 Collect "name" fields from a JSON array of objects.
 
static std::string list_available_keys (const nlohmann::json &j)
 List available keys from a JSON value for error messages.
 
static std::string filter_json_by_key (const std::string &json_str, const std::string &key, const std::string &label, nlohmann::json &data)
 Select one entry of a provider's JSON by key (object key or array element name).
 
static std::string inspect_filterable (char *(*fn)(void *), void *ud, const std::string &key, const std::string &label, nlohmann::json &data)
 Inspect a filterable target (config/identity/tool).
 
static bool dispatch_simple_target (const entropic_state_provider_t &p, const std::string &target, const std::string &key, nlohmann::json &data)
 Dispatch inspect for simple (non-filterable) targets.
 
static std::string dispatch_inspect (const entropic_state_provider_t &p, const std::string &target, const std::string &key, nlohmann::json &data)
 Dispatch an inspect query to the appropriate provider.
 
static std::string followup_results (const char *raw)
 Wrap the provider's records in the declared {"results": [...]}.
 
std::string check_read_gates (FilesystemServer &server, const fs::path &resolved, const std::string &display)
 Execute read_file: resolve, size-check, read, hash, track.
 
std::string read_window (const json &args, long budget, ReadWindow &w)
 The window a read_file call asks for, validated.
 
json read_and_track (FilesystemServer &server, const fs::path &resolved, const std::string &display, const json &args, std::string &err)
 Read the requested window and record the read for the session.
 
std::regex compile_grep_or_error (const std::string &pattern, std::string &err)
 Compile a regex or return a structured tool error.
 
static void grep_search (const fs::path &root, const fs::path &start, const std::vector< std::string > &file_patterns, const std::regex &re, const IgnoreMatcher &ignore, WalkBudget &budget, PagedResult &page)
 Execute grep: brace-expand the file glob, compile the content regex (error-safe), iterate the tree applying the same classify_glob_entry filter glob uses.
 
static void grep_target (FilesystemServer &server, const fs::path &start, const json &args, const std::regex &re, WalkBudget &budget, PagedResult &page)
 Search start — one file, or a tree under the glob filter.
 
static std::string grep_preflight (const json &args, const fs::path &start, const fs::path &root, Page &requested, std::regex &re)
 Validate a grep call: paging, regex, and that path exists.
 
static void list_page (const fs::path &dir, const json &args, Page requested, int max_walk, json &result)
 Collect one page of a directory listing into result.
 
static int compute_max_read_bytes (const FilesystemConfig &config, int model_context_bytes)
 Compute max read bytes from config and model context.
 
static std::pair< std::string, int > run_git (const std::string &repo_dir, const std::string &git_args)
 Run a git command in a given directory via popen.
 
static ServerResponse make_git_response (const std::string &output, int exit_code)
 Format a git result as JSON ServerResponse.
 
static nlohmann::json record_to_json (const ToolCallRecord &rec)
 Serialize a single ToolCallRecord to JSON.
 
static std::string check_required_fields (const nlohmann::json &schema, const nlohmann::json &args)
 Check required fields are present.
 
static std::string check_enum (const std::string &key, const nlohmann::json &allowed, const nlohmann::json &val)
 Check one property's enum and type constraints.
 
static std::string check_type (const std::string &key, const std::string &type, const nlohmann::json &val)
 Check a single value against a type constraint.
 
static std::string check_range (const std::string &key, const nlohmann::json &prop, const nlohmann::json &val)
 Check a numeric value against minimum / maximum (v2.14.0).
 
static std::string check_property_constraints (const std::string &key, const nlohmann::json &prop, const nlohmann::json &val)
 Check one property's enum, type and range constraints.
 
static std::string validate_tool_args (const std::string &schema_json, const nlohmann::json &args)
 Validate tool arguments against the tool's JSON Schema.
 
static std::string parse_tool_result_text (const std::string &result_json)
 Extract the "result" text from an MCP result JSON envelope.
 
static ToolResultKind classify_tool_result (const std::string &content)
 Classify a tool result by its content (error/empty/ok).
 
static bool pre_mod_renames_tool (const nlohmann::json &parsed, const std::string &tool_name)
 Does a PRE_TOOL_CALL payload try to change the call's identity?
 
static std::string pre_mod_refusal (const nlohmann::json &parsed, const std::string &tool_name)
 Why a PRE_TOOL_CALL modification must be refused (gh#168).
 
static void overwrite_call_arguments (ToolCall &call, const nlohmann::json &args)
 Replace a call's arguments from a validated args object.
 
static std::vector< std::string > extract_pipeline_stages (const nlohmann::json &result_json)
 Extract directives from ServerResponse JSON and process them.
 
static std::unique_ptr< Directive > build_complete_directive (const nlohmann::json &result_json)
 Build a typed Directive from a directive-descriptor JSON.
 
static std::vector< ContextRef > extract_context_refs (const nlohmann::json &result_json)
 Parse the context array of a delegate/pipeline result (gh#162).
 
static std::unique_ptr< Directive > build_directive (const nlohmann::json &d, const nlohmann::json &result_json)
 Build a Directive from a parsed directive + result JSON.
 
static std::optional< std::pair< nlohmann::json, nlohmann::json > > extract_directive_array (const std::string &raw_result)
 Pull the "directives" array out of a tool ServerResponse JSON.
 
static std::string sanitize_display_name (const std::string &raw)
 Sanitize a display_name for use as a log-line bracket label.
 
static std::vector< char * > build_argv (const std::string &command, const std::vector< std::string > &args)
 Build a NULL-terminated argv from command + args.
 
static std::vector< char * > build_envp (const std::vector< std::string > &env_strs)
 Build a NULL-terminated envp from env strings.
 
static std::string extract_parent_id (const nlohmann::json &j)
 Extract optional parent_conversation_id from JSON.
 
static void parse_result_fields (const nlohmann::json &result, AuditEntry &entry)
 Parse the result sub-object from JSON into AuditEntry fields.
 
static std::string col_text (sqlite3_stmt *stmt, int col)
 Get text from a sqlite3 column, returning empty string for NULL.
 
static std::optional< std::string > col_opt_text (sqlite3_stmt *stmt, int col)
 Get optional text from a sqlite3 column.
 
static json col_nullable_int (sqlite3_stmt *stmt, int col)
 Get a nullable integer column as a JSON value.
 
static void bind_opt_text (sqlite3_stmt *stmt, int idx, const std::optional< std::string > &val)
 Bind optional text to a parameter position.
 
static void bind_opt_int (sqlite3_stmt *stmt, int idx, const std::optional< int > &val)
 Bind optional int to a parameter position (NULL if unset).
 
static void bind_delegation_insert (sqlite3_stmt *s, const DelegationRecord &rec)
 Bind a Delegation record onto the delegations-INSERT statement's 11 placeholders.
 
static bool guard_parent_conversation (const std::string &parent_conversation_id, const std::string &delegating_tier, const std::string &target_tier, std::string &delegation_id, std::string &child_conversation_id)
 Reject an empty parent_conversation_id with a clear error and reset the out params (gh#48 defense-in-depth).
 
static std::vector< std::string > get_applied_migrations (sqlite3 *db)
 Get names of already-applied migrations.
 
static bool apply_migration (sqlite3 *db, const Migration &mig)
 Apply a single migration and record it.
 
static bool is_applied (const std::vector< std::string > &applied, const char *name)
 Check if a migration name is in the applied list.
 
static std::string read_file (const std::filesystem::path &path)
 Read file contents as string.
 
static bool write_file (const std::filesystem::path &path, const std::string &content)
 Write string to file.
 
static std::vector< std::string > split_lines (const std::string &content)
 Split string into lines.
 
static bool list_contains (const std::vector< std::string > &lines, size_t start, std::string_view pattern)
 Check if a YAML sequence already contains a pattern.
 
static auto find_list_end (std::vector< std::string > &lines, size_t list_start)
 Find the end of a YAML sequence (last "- " item).
 
static auto find_section_end (std::vector< std::string > &lines, std::vector< std::string >::iterator start)
 Find the end of a YAML section (indented block).
 
static std::string join_lines (const std::vector< std::string > &lines)
 Join lines back into a string with trailing newline.
 
static bool insert_permission_item (std::vector< std::string > &lines, std::string_view pattern, const std::string &perms_key, const std::string &list_line, const std::string &item)
 Insert a permission item into the parsed YAML lines.
 

Variables

static const char *const kStateNames []
 Lookup table for AgentState names indexed by enum value.
 
static auto logger = log::get("identity_manager")
 
static const std::vector< std::string > s_reserved_names
 Reserved identity names that cannot be used.
 
static std::unordered_map< std::string, size_t > s_tier_system_hash
 Per-tier system prompt hash for diff detection across delegations.
 
static std::unordered_map< std::string, entropic::PromptLogDedup > s_tier_prompt_dedup
 gh#152: bodies already shown in this tier's prompt log.
 
static auto logger = entropic::log::get("mcp.external_bridge")
 
static std::mutex s_bound_sockets_mu
 
static std::unordered_set< std::string > s_bound_sockets
 
 fixed = std::regex_replace(fixed, std::regex(R"(,\s*\])"), "]")
 
 try
 
static constexpr const char * VISION_INSTRUCTION
 Vision instruction appended to system prompt.
 
constexpr uint64_t kComputeBytesAtUbatch512 = 1222ull * 1024ull * 1024ull
 Measured compute scratch for ONE context at a 512-token ubatch (vram_footprint.h: 1222 MiB, gemma-4 E4B with an MTP head).
 
constexpr int kComputeReferenceUbatch = 512
 The ubatch that figure was measured at.
 
constexpr int kDefaultUbatch = 512
 llama.cpp's default ubatch, assumed when the tier does not set one.
 
constexpr int kUbatchLadder [] = {512, 256, 128}
 Values auto will step down through, descending.
 
constexpr const char * kExpertTensorRegex
 Tensor-name pattern tail identifying a layer's ROUTED-expert weights.
 
constexpr uint64_t kPartialOffloadReserveBytes = 2048ull * 1024 * 1024
 VRAM held back for compute/graph buffers, which scale with ubatch and model internals rather than with layer count.
 
constexpr uint64_t kLargeModelThresholdBytes = 10ull * 1024 * 1024 * 1024
 Size above which a model counts as "large" for the waiver below.
 
constexpr uint64_t kMemlockUnlimited = UINT64_MAX
 Sentinel for an unlimited RLIMIT_MEMLOCK (gh#148).
 
constexpr int kNoSessionSlot = -1
 Sentinel for "no slot assigned".
 
constexpr uint64_t kBaseKvPerTokenF16 = 16ull * 1024ull
 KV bytes per token at f16, the rate the v2.2.4 estimate assumed.
 
constexpr int kAllLayersSentinel = 99
 gpu_layers at or above this means "every layer" (llama.cpp's 99).
 
static const char *const DIRECTIVE_NAMES []
 Serialize ServerResponse to JSON envelope.
 
static constexpr const char * MIGRATION_001_INITIAL
 @dg_internal
 
static constexpr const char * MIGRATION_002_FTS
 @dg_internal
 
static constexpr const char * MIGRATION_003_DELEGATIONS
 @dg_internal
 
static constexpr const char * MIGRATION_004_COMPACTION_SNAPSHOTS
 @dg_internal
 
static constexpr std::array< Migration, 4 > MIGRATIONS
 @dg_internal
 

Detailed Description

Activate model on GPU (WARM → ACTIVE).

Session key of the run executing on this thread (gh#166).

Compile a gitignore line into a Rule.

Convert gitignore pattern body to regex source.

Reloads model with n_gpu_layers from config, then creates inference context with KV cache.

Returns
true on success. @dg_internal
Version
2.1.8

Dispatch table: each glob token type has a small emit_* helper.

Parameters
patternPattern body (no leading ! or trailing /).
Returns
Regex source. @utility
Version
2.1.4

Strips leading ! (negation) and trailing / (dir_only). Determines anchor: pattern with embedded / (anywhere but at the end) is anchored at the base; otherwise the pattern matches against any path component.

@dg_internal

Version
2.1.4

Typedef Documentation

◆ CompactorFn

using entropic::CompactorFn = typedef std::function<CompactionResult( const std::vector<Message>& messages, const CompactionConfig& config, const std::string& identity)>

Internal C++ compactor function type.

Takes messages + config + identity, returns CompactionResult. Wraps C function pointers with C++ types for internal use.

Version
1.9.9

Definition at line 43 of file compactor_registry.h.

◆ DirectiveHandler

Directive handler function type.

Parameters
ctxCurrent loop context (mutable).
directiveThe directive to process.
resultAggregate result (accumulator).
Version
1.8.4

Definition at line 325 of file directives.h.

◆ OutsideRootApprover

Approver the server consults under allow_outside_root: optional.

Parameters
requestThe pending access (valid for the call only).
user_dataOpaque pointer given with the approver.
Returns
The verdict for this one call.
Version
2.13.0

Definition at line 133 of file filesystem.h.

◆ PermissionPersistFn

Permission persistence callback type.

Called when a user approves ALWAYS_ALLOW or ALWAYS_DENY so the pattern can be saved to disk. Injected by the facade.

Parameters
patternPermission pattern string.
allowtrue for allow, false for deny.
user_dataOpaque pointer (PermissionPersister*).
Version
1.8.8

Definition at line 714 of file engine_types.h.

◆ RunChildLoopFn

Callback type for running a child engine loop.

The engine provides this so DelegationManager can spawn child loops without a circular dependency on AgentEngine's full interface.

Parameters
ctxChild loop context.
user_dataOpaque pointer (AgentEngine instance).
Version
1.8.6

Definition at line 70 of file delegation.h.

◆ RunStreamFn

Signature of a run's stream-chunk sink (gh#208, v2.14.2).

Definition at line 185 of file run_scope.h.

◆ TokenCallback

Token callback type matching the C API signature.

Version
2.0.1

Definition at line 25 of file stream_think_filter.h.

◆ ToolExecutionFn

using entropic::ToolExecutionFn = typedef std::vector<Message> (*)( LoopContext& ctx, const std::vector<ToolCall>& tool_calls, void* user_data)

Tool execution callback type.

Called by the engine when tool calls are parsed from model output. The facade wires this to ToolExecutor::process_tool_calls().

Parameters
ctxMutable loop context.
tool_callsTool calls to process.
user_dataOpaque pointer (ToolExecutor instance).
Returns
Result messages to append to context.
Version
1.8.5

Definition at line 534 of file engine_types.h.

◆ ToolHandler

A non-ask tool's handler (v2.14.3).

Definition at line 1096 of file external_bridge.cpp.

Enumeration Type Documentation

◆ AdapterState

LoRA adapter lifecycle state.

Mirrors ModelState but for LoRA adapters. An adapter must be HOT for its weights to influence generation. Multiple adapters can be WARM simultaneously (loaded in RAM), but only one can be HOT per inference context.

Version
1.9.2
Enumerator
COLD 

Not loaded. No resources consumed.

WARM 

Loaded in RAM via llama_adapter_lora_init(). Ready to activate.

HOT 

Active on context via llama_set_adapter_lora(). Influencing generation.

Definition at line 112 of file config.h.

◆ AgentState

C++ enum class for agent execution states.

Maps 1:1 to C entropic_agent_state_t for cross-boundary use.

Version
1.8.0

Definition at line 36 of file engine_types.h.

◆ BackendCapability

Capabilities that an inference backend may or may not support.

The engine queries capabilities before using optional features. A backend that does not support a capability returns graceful errors (not crashes) if the feature is invoked anyway.

Design rationale:
Enum rather than string tags for compile-time exhaustiveness checking. New capabilities are appended (never reordered) for ABI stability. The trailing _COUNT sentinel is NOT a capability — it sizes the dispatch table and pins the declared cardinality so an appended capability fails the test until it is wired everywhere.

@req REQ-TYPE-004

Version
1.9.13
Enumerator
KV_CACHE 

KV cache state management (save/load/clear)

HIDDEN_STATE 

Recurrent hidden state management (save/load/reset)

STREAMING 

Streaming token-by-token generation.

RAW_COMPLETION 

Raw text completion without chat template.

GRAMMAR 

GBNF grammar-constrained generation.

LORA_ADAPTERS 

LoRA adapter hot-swapping (v1.9.2)

MULTI_SEQUENCE 

Multiple concurrent sequences on one model instance.

TOKENIZER 

Token counting / tokenizer access.

LOG_PROBS 

Log-probability retrieval (v1.9.10)

VISION 

Vision / multimodal input (v1.9.11)

SPECULATIVE_DECODING 

Speculative decoding compatibility.

PROMPT_CACHING 

Prompt cache prefix save/load (v1.8.3)

AUDIO 

Audio input via mtmd audio projector (gh#53, v2.3.0)

_COUNT 

Sentinel — must be last. Used for iteration/array sizing.

Definition at line 37 of file backend_capability.h.

◆ BudgetMode

Thinking-budget gating mode.

(gh#80, v2.5.0)

Charges generation effort that does NOT produce a tool call against a budget; a tool call resets the counter. On exhaustion the engine nudges the model to complete, then hard-cuts with a failure note visible in history. Opt-in: off is the default and preserves pre-v2.5.0 behavior exactly.

Version
2.5.0
Enumerator
off 

Disabled (default) — no thinking-budget gating.

tokens 

Gate on generated tokens since the last tool call.

wall_clock 

Gate on wall-clock seconds since the last tool call.

Definition at line 81 of file engine_types.h.

◆ ContentPartType

Content part type discriminant.

@req REQ-TYPE-006

Version
1.9.11
Enumerator
TEXT 

Plain text content.

IMAGE 

Image content (local path or data URI)

Definition at line 25 of file content.h.

◆ DelegationIsolation

How a delegation's filesystem writes are contained (gh#160).

Version
2.13.0
Enumerator
none 

Child tools share the session's working dir (default)

sandbox 

Child tools run in a copy; output is a patch.

Definition at line 1074 of file config.h.

◆ EmptyContentCause

Why a turn produced tokens but delivered no content.

Enumerator
not_empty 

Content survived; nothing to explain.

tool_call_only 

The whole turn was tool calls — normal (gh#159).

budget_truncated 

finish_reason == "length": ran out of tokens.

model_stopped 

Model ended the turn while still reasoning.

unknown 

Empty for a reason this rule cannot attribute.

Definition at line 34 of file empty_content_diagnosis.h.

◆ GrammarSource

Which source, if any, constrains the decode.

Version
2.10.4
Enumerator
none 

Unconstrained.

request 

GenerationParams::grammar (COMMON_GRAMMAR_TYPE_USER)

tier 

The TIER's identity frontmatter grammar: stem (gh#154).

Reaches the sampler through GenerationParams::grammar exactly like request does — which is precisely why it needed naming: a consumer reading a result could not tell a tier-configured grammar from one they passed, or from none at all.

tool_call 

Render-derived (COMMON_GRAMMAR_TYPE_TOOL_CALLS, needs prefill)

count 

Sentinel — MUST remain last.

Adding a source above this line breaks grammar_source_invariant_test, which is the point: gh#95, gh#108 and gh#134 were each a grammar source that reached the engine without ever reaching the sampler, and each got only a bespoke regression test. A fifth source must not be able to ship unwired.

Definition at line 35 of file grammar_source.h.

◆ IdentityOrigin

Origin of an identity – how it was created.

Version
1.9.6
Enumerator
STATIC 

Loaded from YAML frontmatter file at startup.

DYNAMIC 

Created at runtime via API.

Definition at line 31 of file identity.h.

◆ InterruptMode

How to handle generation interrupt.

Version
1.8.4
Enumerator
CANCEL 

Discard partial response, stop.

PAUSE 

Keep partial response, await input.

INJECT 

Keep partial, inject context, continue.

Definition at line 53 of file engine_types.h.

◆ MCPAccessLevel

MCP tool access level for per-identity authorization.

Two ordered levels: READ < WRITE. WRITE implies READ. Default for ungranted keys is NONE (no access). Default for new tools is WRITE (safe default — tools must opt into READ).

Version
1.9.4
Enumerator
NONE 

No access (default for ungranted keys)

READ 

Read-only operations (e.g., read_file, list_directory)

WRITE 

Read + write operations (e.g., write_file, execute)

Definition at line 38 of file config.h.

◆ McpJsonConfigVerdict

What configuration alone says about a discovered server.

Version
2.14.0
Enumerator
disabled 

Named in disabled_mcpjson_servers — never connect.

enabled 

Named in enabled_mcpjson_servers, or enable-all is set.

ask 

Config is silent; the pre-connect hook decides.

Definition at line 49 of file discovery_policy.h.

◆ ModelState

C++ enum class for model VRAM lifecycle states.

Maps 1:1 to C entropic_model_state_t for cross-boundary use. Internal C++ code uses this typed enum; C boundary uses the C enum.

Version
1.8.2
Enumerator
COLD 

On disk only, no RAM consumed.

WARM 

mmap'd + mlock'd in RAM

ACTIVE 

GPU layers loaded, full speed.

Definition at line 96 of file config.h.

◆ Offload

Where a tier's weights land, as far as the estimate can tell.

Enumerator
none 

gpu_layers == 0: weights cost no VRAM.

full 

-1 or >= 99: the whole file is resident.

partial_unknown 

A layer count we cannot price without GGUF metadata.

Definition at line 76 of file vram_footprint.h.

◆ OutsideRootAccess

What the filesystem server does with a path outside its root.

The YAML spelling of mcp.filesystem.allow_outside_root: false, true, or optional (v2.13.0). An enum rather than optional<bool> on purpose — if (cfg.allow_outside_root) on an optional<bool> compiles and is TRUE for an explicit false, which is exactly the mistake a security switch cannot afford.

Version
2.13.0
Enumerator
refuse 

false: every escape refused ("Path escapes project root")

allow 

true: every escape served, no prompt

optional 

optional: every escape asks the host's path approver

Definition at line 771 of file config.h.

◆ OutsideRootVerdict

The host's answer to an OutsideRootRequest (v2.13.0).

no_approver is distinct from rejected so the refusal can tell the operator the truth: "nobody was asked" and "somebody said no" are fixed by different configuration.

Version
2.13.0
Enumerator
approved 

Serve this one call.

rejected 

The approver said no.

no_approver 

No approver is registered — refuse, fail loud.

Definition at line 120 of file filesystem.h.

◆ PathAccess

What a filesystem tool is about to do with a path (v2.13.0).

Carried to the host's approver so it can say "wants to WRITE /etc/…", not just "wants /etc/…". read_file and list_directory read; write_file and edit_file write.

Version
2.13.0
Enumerator
read 

read_file, list_directory

write 

write_file, edit_file

Definition at line 95 of file filesystem.h.

◆ ToolApproval

Tool approval responses from user.

Version
1.8.4
Enumerator
DENY 

Deny this once.

ALLOW 

Allow this once.

ALWAYS_DENY 

Deny and save to config.

ALWAYS_ALLOW 

Allow and save to config.

Definition at line 63 of file engine_types.h.

◆ ToolResultKind

Categorical outcome of a single tool invocation.

Values are serialized into the POST_TOOL_CALL hook context JSON as the result_kind string. Do NOT reorder or remove values — clients treat the string form as a stable contract.

@req REQ-TYPE-003

Version
2.0.6-rc19
Enumerator
ok 

Tool dispatched, returned non-empty content.

error 

Tool server returned an error payload.

rejected_duplicate 

Precondition: duplicate in recent history.

rejected_schema 

Precondition: argument schema violation.

rejected_precondition 

Any other precondition reject (auth, tier, hook-cancel)

ok_empty 

Tool dispatched cleanly but returned no content (v2.1.0, #44)

delegation_failed 

entropic.delegate child failed (terminal_reason or budget). (#7, v2.1.4)

rejected_anti_spiral 

Anti-spiral hard threshold crossed; tool blocked. (#14, v2.1.4)

rejected_unauthorized 

Tool not in the locked tier's allowed_tools. (gh#83, v2.5.2)

Definition at line 32 of file tool_result.h.

◆ ValidationVerdict

Result of the full validation pipeline (critique + optional revision).

Encapsulates the final output after zero or more revision attempts. Returned by ConstitutionalValidator::validate() and exposed through the C API as JSON via entropic_validation_last_result().

Version
1.9.8

Outcome of a validation pipeline run.

Lets callers distinguish clean pass from safety-valve revert and from max-revisions-exhausted. Surfaces through ON_COMPLETE hook context and async task status so consumers know whether the returned content is trustworthy. (E1 / 2.0.6-rc17)

Version
2.0.6-rc17
Enumerator
passed 

No violations, content unchanged.

revised 

Violations found; revision applied.

rejected_reverted_length 

Revision gutted content >50%; original preserved.

rejected_max_revisions 

Revisions exhausted; last output returned as-is.

skipped 

Validation did not run (skip_tiers / pure-tool-call / empty)

paused_pending_consumer 

gh#30 (v2.1.5): auto_retry disabled and a critique failed.

Engine paused before entering the revision loop; consumer must call entropic_validation_resume_retry() or _accept_last().

passed_consumer_override 

gh#30 (v2.1.5): consumer called accept_last() to override a paused rejection.

Last attempt is the final answer.

Definition at line 70 of file validation.h.

Function Documentation

◆ action_envelope_to_call()

static std::optional< ToolCall > entropic::action_envelope_to_call ( const nlohmann::json &  j)
static

Map one parsed JSON object to a recovered ToolCall.

Accepts the canonical {"name":...} shape (via tool_call_from_json) and the parroted {"action":"<verb>",...} meta envelope — the latter mapped to the entropic.<verb> call ONLY when <verb> names a known meta-tool (its action verb equals its tool short-name). gh#88 audit: without this allow-list, TodoTool's sub-action verbs (add/update/remove) and arbitrary prose strings were recovered as bogus entropic.<x> no-op calls — the recovery would WARN "recovered 1" while injecting a call to a tool that does not exist.

Parameters
jParsed JSON object.
Returns
ToolCall, or nullopt if neither shape matches a real tool. @dg_internal
Version
2.7.1

Definition at line 264 of file adapter_base.cpp.

◆ agent_state_name()

const char * entropic::agent_state_name ( AgentState  state)

Get the string name for an AgentState value.

Parameters
stateAgent state.
Returns
Static string. Never NULL. @utility
Version
1.8.4
Parameters
stateAgent state.
Returns
Static string like "IDLE", "EXECUTING", etc. @utility
Version
1.8.4

Definition at line 36 of file engine_types.cpp.

◆ annotate_hard_stop()

static std::string entropic::annotate_hard_stop ( const std::string &  carried,
const std::string &  reason,
const std::string &  stop_noun 
)
static

Build an engine-forced stop's final assistant content.

Shared by BOTH engine-authored terminals — the iteration cap (gh#169) and the thinking-budget hard cut (gh#181). Either one ANNOTATES the agent's last substantive output instead of replacing it: DelegationManager::extract_summary reads the last assistant message, so replacing it handed the parent a placeholder where the child's work belonged. One annotator, because two hand-rolled copies of the same wording is how the two paths drift apart.

The two branches are worded differently on purpose — a child that produced nothing must stay distinguishable from one that produced work and then ran out. That distinction matters MORE on the budget path: the cut fires when a model narrates instead of calling a tool, so "it produced something first" is less often true there.

Parameters
carriedLast substantive assistant content ("" when none).
reasonReason clause, rendered inside the trailing bracket.
stop_nounWhat stopped the run ("cap" / "cut"), used only in the nothing-was-produced wording.
Returns
The content for the synthetic completion message. @dg_internal
Version
2.13.0

Definition at line 648 of file engine.cpp.

◆ any_cancelling_left()

static bool entropic::any_cancelling_left ( ExternalBridge *  bridge,
const std::string &  session_key 
)
static

True while one session's task is still phase=cancelling.

Parameters
bridgeBridge holding the task registry.
session_keySession being cleared (v2.14.0).
Returns
true when a task of that session is still cancelling. @utility
Version
2.0.6-rc16

Definition at line 664 of file external_bridge.cpp.

◆ any_message_has_images()

bool entropic::any_message_has_images ( const std::vector< Message > &  messages)

Convenience: true if any message carries image content_parts.

True if any parsed message carries image content_parts.

Parameters
messagesParsed message list.
Returns
true if at least one Message has has_images() true. @req REQ-TYPE-006
Version
2.1.8
Parameters
messagesParsed message list.
Returns
true if at least one ContentPart is IMAGE. @req REQ-TYPE-006
Version
2.1.8

Definition at line 128 of file messages_json.cpp.

◆ append_prefixed_tools()

static void entropic::append_prefixed_tools ( const std::string &  tools_json,
const std::string &  prefix,
nlohmann::json &  all 
)
static

Append a server's tools to an array, prefixing each name.

<server>.<tool> is the fully-qualified form the router later splits back apart, so prefixing here is what makes prefix routing uniform across server kinds.

Parameters
tools_jsonServer's raw tool-descriptor JSON array.
prefixServer name to prepend as <prefix>.<tool>.
[in,out]allDestination array, appended to in place. @req REQ-MCP-007
Version
2.10.1

Definition at line 192 of file server_manager.cpp.

◆ append_sequential_stop()

void entropic::append_sequential_stop ( GenerationParams &  params,
const std::string &  marker 
)
inline

Append a tool-call close marker to params.stop for sequential mode.

Pure engagement decision (no backend, no I/O) so it is CPU-unit-testable in isolation — the instrumentation guard that FAILS if the gh#103 sequential hard-stop does not engage (mirrors the gh#96 warm_keep_util decision helpers). No-op unless params.tool_call_mode == "sequential" and marker is non-empty; dedupes so an explicit per-call stop already carrying the marker is not duplicated.

Parameters
paramsGeneration params (stop list mutated).
markerFamily close marker (from close_marker_for_format / the backend). @req REQ-INFER-013
Version
2.8.2

Definition at line 93 of file tool_call_markers.h.

◆ append_text_part()

static void entropic::append_text_part ( const std::string &  type_val,
const std::string &  text_val,
std::string &  text 
)
static

Append text from a content part if type == "text".

Parameters
type_valParsed type string.
text_valParsed text string.
[out]textAccumulated text. @utility
Version
1.9.11

Definition at line 275 of file compactor_registry.cpp.

◆ apply_action_envelope_recovery()

void entropic::apply_action_envelope_recovery ( std::vector< ToolCall > &  calls,
const std::string &  raw 
)

gh#88: substitute recovered bare-JSON calls when a reliable (PEG_GEMMA4 / gemma) parse produced none; logs the recovery.

gh#88 reliable-path recovery substitution — see header.

No-op unless calls is empty AND a recovery is found. The WARN keeps residual/future context-priming visible instead of silently masking it. Used only on the common_chat-reliable path (interface_factory / orchestrator).

Parameters
callsIn/out parsed calls; replaced by the recovery iff empty + found.
rawRaw assistant output to recover from.
Version
2.7.1
Parameters
callsIn/out parsed calls; replaced by the recovery iff empty + found.
rawRaw assistant output to recover from. @req REQ-INFER-012
Version
2.7.1

Definition at line 320 of file adapter_base.cpp.

◆ apply_adapter_parse()

static void entropic::apply_adapter_parse ( InferenceBackend *  model,
ChatAdapter *  adapter,
GenerationResult &  result 
)
static

Split tool calls out of a result (gh#87: common_chat or adapter).

gh#87 Phase D: parse via common_chat (parse_response) ONLY when its captured format is multi-parameter safe (common_chat_parse_reliable — the dedicated PEG_GEMMA4 grammar). Autoparser families (Qwen, nemotron3) fall back to their hand-rolled multi-parameter adapter, because the PEG autoparser drops parameters past the first. Never both (double-parse guard). raw_content always preserves the pre-split output.

Parameters
modelBackend that produced the result (for common_chat routing).
adapterTier adapter for the autoparser/fallback path (may be null).
[in,out]resultGeneration result (content split, tools set). @req REQ-INFER-010
Version
2.10.3

Definition at line 601 of file orchestrator.cpp.

◆ apply_fenced_fallbacks()

static void entropic::apply_fenced_fallbacks ( const std::string &  raw,
LlamaCppBackend *  llama,
std::vector< ToolCall > &  calls 
)
static

Apply fenced-json and fenced-args-only fallback parsers (gh#122, gh#127).

Called when both the primary parse paths (common_chat PEG + adapter) yield zero calls. Tries the gh#122 named-fence path first; on miss, tries the gh#127 args-only schema-match path. calls is updated in-place.

Parameters
rawRaw model output.
llamaActive LlamaCppBackend (may be nullptr → gh#127 skipped).
calls[in/out] Tool call accumulator (no-op unless currently empty). @utility
Version
2.10.0

Definition at line 476 of file interface_factory.cpp.

◆ apply_migration()

static bool entropic::apply_migration ( sqlite3 *  db,
const Migration &  mig 
)
static

Apply a single migration and record it.

Parameters
dbSQLite database handle.
migMigration to apply.
Returns
true on success. @dg_internal
Version
2.0.0

Definition at line 417 of file database.cpp.

◆ apply_terminal_batch_rc()

static bool entropic::apply_terminal_batch_rc ( int  rc,
const char *  result_json,
GenerateResult &  result 
)
static

Map a TERMINAL batch return code onto the result, if it is one.

Terminal means the loop must not treat the turn as a model failure it can retry. Two codes qualify: a cancellation (gh#81, v2.4.2 — carries whatever partial content arrived, and maps to "interrupted" so the engine transitions to INTERRUPTED, mirroring resolve_stream_finish_reason), and a v2.13.0 context refusal (carries nothing, and no retry can shrink the prompt that caused it).

Extracted from generate_batch so that function stays inside the knots ABC gate once the second code joined it.

Parameters
rcBackend return code.
result_jsonRaw backend payload (may be NULL).
[out]resultResult populated when rc is terminal.
Returns
true when rc was terminal and result is now final. @utility
Version
2.13.0

Definition at line 592 of file response_generator.cpp.

◆ apply_tier_sampler_overrides()

void entropic::apply_tier_sampler_overrides ( GenerationParams &  params,
const TierSamplerOverrides &  ov 
)

Apply per-tier sampler overrides to params.

Pure precedence helper — see header.

(gh#82/gh#85)

Pure precedence helper, free function for unit-testability. For each knob, applies the tier-configured value ONLY when the optional is engaged AND the incoming param is still at the GenerationParams struct default — preserving an explicit per-call override.

Parameters
paramsGeneration params (mutated).
ovTier sampler overrides (nullopt fields are skipped). @utility
Version
2.5.3

(gh#82/gh#85)

Each field takes the tier's value only when the tier set one AND the caller left that field at its GenerationParams default — so a per-call knob is never overwritten by tier config.

Parameters
paramsGeneration parameters (mutated in place).
ovThe tier's optional sampler overrides. @req REQ-INFER-021
Version
2.8.2

Definition at line 2643 of file orchestrator.cpp.

◆ apply_workspace_app_context()

void entropic::apply_workspace_app_context ( entropic_handle_t  h,
const std::string &  workspace,
const std::optional< std::string > &  app_context 
)

Give a workspace's sessions prompts built on its own app_context (gh#179), or return them to the handle's.

Give a workspace's sessions prompts built on its own app_context.

Assembles exactly what configure assembles — constitution, app_context, tier identity — with the workspace's text in the app_context slot, and registers the result with the engine for the workspace.

Parameters
hEngine handle (configured).
workspaceWorkspace name.
app_contextThe workspace's text; nullopt = use the handle's. @req REQ-MCP-027
Version
2.14.0
Parameters
hEngine handle (configured).
workspaceWorkspace name.
app_contextThe workspace's text; nullopt = use the handle's. @req REQ-MCP-027
Version
2.14.0

Definition at line 209 of file entropic_mcp.cpp.

◆ arg_after()

std::string entropic::arg_after ( const std::vector< std::string > &  args,
const std::string &  flag 
)
inline

The value following flag in args, or "".

Parameters
argsCommand arguments.
flagFlag to look for (e.g. "--socket").
Returns
The next argument, or "" when absent. @utility
Version
2.14.0

Definition at line 84 of file discovery_policy.h.

◆ ask_in_turn()

static json entropic::ask_in_turn ( entropic_handle_t  handle,
ExternalBridge *  bridge,
const json &  args,
const std::string &  session_key,
int  client_fd,
const json &  progress_token 
)
static

Run a sync ask once this session's turn comes up (gh#144, gh#205).

Queue rather than race: the engine admits one turn per session and refuses the loser with ALREADY_RUNNING; from a shared host the right answer is to WAIT, so the refusal is never reached from here.

Parameters
handleEngine handle.
bridgeBridge owning the queue.
argsTool arguments.
session_keySession key.
client_fdSocket fd (streaming progress).
progress_tokenProgress token for streaming.
Returns
MCP tool result JSON. @req REQ-BRIDGE-001
Version
2.14.0

Definition at line 982 of file external_bridge.cpp.

◆ ask_status_tool()

static json entropic::ask_status_tool ( const ExternalMCPConfig &  cfg)
static

Definition for the ask_status tool (task_id lookup).

Parameters
cfgExternal MCP config supplying prefix and description overrides.
Returns
One MCP tool definition object. @utility
Version
2.12.0

Definition at line 258 of file external_bridge.cpp.

◆ ask_tool()

static json entropic::ask_tool ( const ExternalMCPConfig &  cfg)
static

Definition for the ask tool (prompt + optional async).

Parameters
cfgExternal MCP config supplying prefix and description overrides.
Returns
One MCP tool definition object. @utility
Version
2.14.0

Definition at line 209 of file external_bridge.cpp.

◆ assemble_compacted()

static std::vector< Message > entropic::assemble_compacted ( const Message *  system_msg,
Message  summary_msg,
const std::vector< const Message * > &  user_msgs,
const std::vector< const Message * > &  assistant_msgs 
)
static

Assemble the compacted list: system, summary, users, last asst.

Parameters
system_msgOptional system message (kept first).
summary_msgThe synthesized summary message.
user_msgsPreserved user messages.
assistant_msgsAssistant messages (only the last is kept).
Returns
Compacted message list. @utility
Version
2.3.7

Definition at line 215 of file compaction.cpp.

◆ assign_if_present()

template<typename T >
static void entropic::assign_if_present ( const nlohmann::json &  j,
const char *  key,
T &  dst 
)
static

Conditionally assign a typed JSON field into a destination.

Extracted (v2.3.14, gh#23 MVP item 2) to keep parse_params under the knots ABC gate as new MVP-10 knobs land. @utility

Version
2.3.14

Definition at line 79 of file interface_factory.cpp.

◆ audit_entry_from_json()

bool entropic::audit_entry_from_json ( const nlohmann::json &  j,
AuditEntry &  entry 
)

Deserialize AuditEntry fields from a JSON object.

Reads the per-call payload from a JSONL line. Session-level fields (version, timestamp, session_id, sequence) are ignored. Unknown fields are silently skipped.

Parameters
jJSON object (one line from audit.jsonl).
[out]entryPopulated entry.
Returns
true if all required fields were present and valid. @req REQ-STOR-008
Version
1.9.5
Parameters
jJSON object (one JSONL line).
[out]entryPopulated entry.
Returns
true if all required fields present and valid. @req REQ-STOR-008
Version
1.9.5

Definition at line 80 of file audit_entry.cpp.

◆ audit_entry_to_json()

nlohmann::json entropic::audit_entry_to_json ( const AuditEntry &  entry)

Serialize AuditEntry fields to a JSON object.

Produces the per-call payload portion of a JSONL line. params_json and directives_json are parsed into proper JSON objects/arrays (not double-encoded strings).

Parameters
entryThe audit entry to serialize.
Returns
JSON object with all entry fields. @req REQ-STOR-008
Version
1.9.5
Parameters
entryThe audit entry to serialize.
Returns
JSON object with all entry fields. @req REQ-STOR-008
Version
1.9.5

Definition at line 53 of file audit_entry.cpp.

◆ batch_error_result()

static GenerationResult entropic::batch_error_result ( const std::string &  msg)
static

Build a single error GenerationResult (gh#98 batch failures).

@utility

Version
2.8.0

Definition at line 2104 of file llama_cpp_backend.cpp.

◆ batch_is_viable()

bool entropic::batch_is_viable ( std::size_t  n,
int  n_parallel,
std::size_t  shared,
bool  hybrid,
std::size_t  total_suffix,
int  n_batch 
)
inline

Decide whether the same-prefix batch fast-path is safe + worthwhile.

When false, the backend falls back to running each request serially (the proven single-request path) — which is always correct, just without the shared-prefill win. The fast-path is taken only when ALL hold:

  • at least 2 requests (nothing to share with one);
  • the arch is NOT hybrid/recurrent (seq-level KV ops are unsafe there — gh#97; recurrent memory rejects partial seq_rm/seq_cp);
  • the batch fits the context's sequence slots (n <= n_parallel);
  • there is a real shared prefix to amortize (shared > 0);
  • the suffix tokens fit one decode batch (total_suffix <= n_batch), so the fan-out prefill never overruns the batch capacity.
Parameters
nNumber of requests.
n_parallelContext sequence-slot capacity (config n_parallel).
sharedShared prefix length (batch_shared_prefix_len result).
hybridTrue if the model is hybrid/recurrent.
total_suffixSum over requests of (len_i - shared).
n_batchDecode batch capacity (config n_batch).
Returns
true if the batch fast-path may be used. @utility
Version
2.8.0

Definition at line 80 of file batch_util.h.

◆ batch_shared_prefix_len()

template<typename Tok >
std::size_t entropic::batch_shared_prefix_len ( const std::vector< std::vector< Tok > > &  seqs)
inline

Longest shared token prefix across N request sequences (gh#98).

The number of leading tokens identical across ALL sequences — prefilled once into seq 0 and seq_cp'd to the other N-1 sequences before each request's unique suffix is decoded. Mirrors warm-keep's rule that at least the final token of every sequence must be re-decoded so its logits are fresh for sampling: the result is capped at shortest_len - 1, so every sequence retains a non-empty suffix.

Returns 0 (no sharing worthwhile) when fewer than 2 sequences are given, any sequence is empty, or the shortest sequence is a single token.

Parameters
seqsTokenized request prompts.
Returns
Shared prefix length in [0, shortest_len - 1]. @utility
Version
2.8.0

Definition at line 43 of file batch_util.h.

◆ bind_and_listen()

static bool entropic::bind_and_listen ( int  fd,
const std::filesystem::path &  path 
)
static

Bind+listen on an AF_UNIX socket, applying 0600 perms.

Parameters
fdPre-created socket fd.
pathBind path (already validated by socket_path_safe).
Returns
true on success. @req REQ-BRIDGE-001
Version
2.14.0

Definition at line 1361 of file external_bridge.cpp.

◆ bind_delegation_insert()

static void entropic::bind_delegation_insert ( sqlite3_stmt *  s,
const DelegationRecord &  rec 
)
static

Bind a Delegation record onto the delegations-INSERT statement's 11 placeholders.

Extracted from create_delegation (v2.1.12, gh#48) so the public function fits the knots SLOC ≤ 50 threshold after the defense-in- depth additions. Bind order matches the INSERT column order.

Parameters
sPrepared statement.
recDelegation record (read-only). @dg_internal
Version
2.3.7

Definition at line 580 of file backend.cpp.

◆ bind_opt_int()

static void entropic::bind_opt_int ( sqlite3_stmt *  stmt,
int  idx,
const std::optional< int > &  val 
)
static

Bind optional int to a parameter position (NULL if unset).

Parameters
stmtPrepared statement.
idxParameter index (1-based).
valValue to bind. @utility
Version
2.3.7

Definition at line 171 of file backend.cpp.

◆ bind_opt_text()

static void entropic::bind_opt_text ( sqlite3_stmt *  stmt,
int  idx,
const std::optional< std::string > &  val 
)
static

Bind optional text to a parameter position.

Parameters
stmtPrepared statement.
idxParameter index (1-based).
valValue to bind. @utility
Version
1.8.8

Definition at line 154 of file backend.cpp.

◆ bind_session_workspace()

static std::string entropic::bind_session_workspace ( entropic_handle_t  handle,
const std::string &  session_key,
const std::string &  workspace 
)
static

Bind a session to the requested workspace, idempotently (gh#205).

A client sends workspace on every call, so a session already bound to the same workspace is left alone — the engine refuses ANY bind once a session holds messages. A different workspace for a session with history is a typed error: its context belongs to the other repository.

Parameters
handleEngine handle.
session_keySession key.
workspaceRequested workspace path or name ("" = none).
Returns
"" on success, else a message for the caller. @dg_internal
Version
2.14.0

Definition at line 947 of file external_bridge.cpp.

◆ bound_workspace()

static std::string entropic::bound_workspace ( entropic_handle_t  handle,
const std::string &  session_key 
)
static

The session's current workspace binding, or "" (gh#205).

Parameters
handleEngine handle.
session_keySession key.
Returns
Bound workspace name, or "" when unbound. @dg_internal
Version
2.14.0

Definition at line 885 of file external_bridge.cpp.

◆ bridge_project_dir()

std::filesystem::path entropic::bridge_project_dir ( entropic_handle_t  h)

The project dir the external bridge derives its socket from.

Parameters
hEngine handle with config loaded.
Returns
config_dir, else the process cwd.
Version
2.14.0
Parameters
hEngine handle with config loaded.
Returns
config_dir, else the process cwd. @req REQ-BRIDGE-001
Version
2.14.0

Definition at line 179 of file entropic_mcp.cpp.

◆ build_argv()

static std::vector< char * > entropic::build_argv ( const std::string &  command,
const std::vector< std::string > &  args 
)
static

Build a NULL-terminated argv from command + args.

Parameters
commandExecutable.
argsArgument list.
Returns
char* vector (pointers into command/args; must outlive use). @utility
Version
2.3.7

Definition at line 421 of file transport_stdio.cpp.

◆ build_complete_directive()

static std::unique_ptr< Directive > entropic::build_complete_directive ( const nlohmann::json &  result_json)
static

Build a typed Directive from a directive-descriptor JSON.

Issue #10 (v2.1.4): the "complete" branch now extracts coverage_gap / gap_description / suggested_files from the result JSON and populates the typed CompleteDirective fields.

Parameters
dDirective JSON ("type": ...).
result_jsonParsed result JSON for parameter lookup.
Returns
Owned Directive (nullptr if type is unrecognized). @dg_internal
Version
2.1.6

Build a CompleteDirective from a result JSON (issue #10).

Parameters
result_jsonTool result JSON.
Returns
An owned CompleteDirective carrying the summary plus the typed coverage_gap / gap_description / suggested_files fields; the optional fields default to false/empty when the tool did not emit them. @req REQ-MCP-024
Version
2.3.7

Definition at line 1755 of file tool_executor.cpp.

◆ build_coverage_gap_message()

static std::string entropic::build_coverage_gap_message ( const std::string &  tier,
const DelegationResult &  result 
)
static

Build the [COVERAGE GAP] message body that goes back to lead when a relay-tier child returns coverage_gap=true (#10, v2.1.4).

Returns
The [COVERAGE GAP] message body to hand back to the lead tier. @req REQ-DELEG-003
Version
2.1.4

Definition at line 2712 of file engine.cpp.

◆ build_delegation_result_struct()

static ent_delegation_result_t entropic::build_delegation_result_struct ( const SandboxInfo &  sb_info,
const SandboxResult &  sandbox_result,
const DelegationResult &  result,
const std::vector< const char * > &  files_c,
size_t  files_len 
)
static

Deliver a finalized patch to consumer or pending/.

The complete callback is null-tolerant (default-deny → pending/). If the callback returns REJECT the patch is also persisted to pending/ for the consumer to recover later. The sandbox directory is removed by the caller (finalize_sandbox_for) after this call returns — independent of the consumer's decision (gh#29: engine never retains writable state).

Parameters
sb_infoSandbox identity.
sandbox_resultPatch artifact.
resultOriginal delegation result. @dg_internal
Version
2.3.7

Fill the C-ABI delegation-result struct from C++ values.

Parameters
sb_infoSandbox identity.
sandbox_resultPatch artifact.
resultOriginal delegation result.
files_cNULL-terminated touched-files array (must outlive use).
files_lenNumber of touched files.
Returns
Filled ent_delegation_result_t (borrows the inputs). @utility
Version
2.3.7

Definition at line 220 of file delegation.cpp.

◆ build_directive()

static std::unique_ptr< Directive > entropic::build_directive ( const nlohmann::json &  d,
const nlohmann::json &  result_json 
)
static

Build a Directive from a parsed directive + result JSON.

Parameters
dDirective descriptor JSON carrying the wire "type" name.
result_jsonParsed result JSON, source of the directive's typed parameters.
Returns
An owned typed Directive for stop_processing, delegate, complete or pipeline; nullptr for any other wire name, which the caller then skips rather than dispatching. @req REQ-MCP-002 @req REQ-MCP-024
Version
2.13.0

Definition at line 1814 of file tool_executor.cpp.

◆ build_envp()

static std::vector< char * > entropic::build_envp ( const std::vector< std::string > &  env_strs)
static

Build a NULL-terminated envp from env strings.

Parameters
env_strs"KEY=VALUE" strings.
Returns
char* vector (pointers into env_strs; must outlive use). @utility
Version
2.3.7

Definition at line 439 of file transport_stdio.cpp.

◆ build_grammar_entry()

static std::optional< GrammarEntry > entropic::build_grammar_entry ( const std::filesystem::path &  path)
static

Load all bundled grammars from a directory.

Parameters
grammar_dirPath to data/grammars/ directory.
Returns
Number of grammars loaded. @dg_internal
Version
1.9.3

Build a bundled GrammarEntry from a .gbnf file.

Parameters
pathGrammar file path.
Returns
Entry, or nullopt if the file is empty/unreadable. @utility
Version
2.3.7

Definition at line 55 of file grammar_registry.cpp.

◆ build_orchestrator_interface()

InferenceInterface entropic::build_orchestrator_interface ( ModelOrchestrator *  orchestrator,
const std::string &  default_tier,
InterfaceContext **  out_context 
)

Build an InferenceInterface wired to an orchestrator.

Build InferenceInterface wired to an orchestrator.

Pre-v2.2.6 this stored its callback user_data in a process-global s_ctx static. A second configure call deleted the first handle's context, leaving the first handle's interface pointing to freed memory (gh#58). The context is now owned by the caller: pass a non-null out_context and free it with destroy_orchestrator_interface() when the interface is no longer needed (typically alongside the orchestrator on engine destroy).

Parameters
orchestratorOrchestrator to wire (must outlive the interface).
default_tierDefault tier name for generation/routing.
out_contextReceives the heap-allocated context; caller owns.
Returns
Fully wired InferenceInterface.
Version
2.2.6
Parameters
orchestratorOrchestrator to wire.
default_tierDefault tier name.
Returns
Wired interface. @dg_internal
Version
2.4.2

Definition at line 592 of file interface_factory.cpp.

◆ build_snapshot()

static nlohmann::json entropic::build_snapshot ( const entropic_state_provider_t &  p,
bool  include_docs,
int  history_limit 
)
static

Build the diagnose snapshot JSON.

Parameters
providerState provider callbacks.
include_docsWhether to include documentation.
history_limitMax history entries.
Returns
Snapshot as JSON object. @dg_internal
Version
1.9.12

Definition at line 956 of file entropic_server.cpp.

◆ build_tool_call_from_json()

static ToolCall entropic::build_tool_call_from_json ( const nlohmann::json &  obj,
const std::string &  tc_str 
)
static

Parse tool calls from raw model output.

Parameters
raw_contentRaw model output.
Returns
(cleaned content, parsed tool calls). @dg_internal
Version
1.8.5

Build one ToolCall from a parsed JSON object.

Parameters
objJSON object with "name" and optional "arguments".
tc_strOriginal JSON string (used in id hash).
Returns
Populated ToolCall. @dg_internal
Version
2.0.2

Definition at line 1713 of file engine.cpp.

◆ build_tool_defs()

static nlohmann::json entropic::build_tool_defs ( const std::vector< std::string > &  tool_jsons)
static

Build the OpenAI-function <tools> JSON array for injection.

Parameters
tool_jsonsTool definition JSON strings.
Returns
JSON array of {type, function:{name,description,parameters}}. @dg_internal
Version
2.3.8

Definition at line 231 of file nemotron3_adapter.cpp.

◆ build_tool_evidence()

static std::string entropic::build_tool_evidence ( const std::vector< Message > &  messages,
size_t  max_results,
size_t  chars_per_result 
)
static

Build un-pruned tool-result evidence for the validator.

Issue #5 (v2.1.3): the validator's critique prompt previously received only a manifest (tool name + result size). For long delegations whose tool results had been pruned, the validator had no way to verify file:line citations against actual evidence — and false-flagged valid citations as hallucinated. This builds a separate evidence block that surfaces the un-pruned content (or the still-live content for un-pruned messages), bounded so the critique prompt doesn't blow up on a long delegation:

  • Most-recent max_results tool-result messages only
  • Each entry truncated to chars_per_result characters
  • Older messages aggregated into a tail "(N earlier results elided)" line so the validator knows evidence is bounded

Format is human-readable (mirrors build_tool_manifest) since it lands in a critique prompt consumed by the model.

Parameters
messagesConversation messages.
max_resultsMost-recent N tool-result messages to include.
chars_per_resultPer-result truncation budget.
Returns
Evidence block, empty if no tool results in messages. @utility
Version
2.3.7

Definition at line 2056 of file engine.cpp.

◆ build_tool_manifest()

static std::string entropic::build_tool_manifest ( const std::vector< Message > &  messages)
static

Build tool call manifest from conversation messages.

Scans for messages with metadata["tool_name"] (tool results stored by ToolExecutor) and builds a human-readable summary line per call.

Parameters
messagesConversation messages.
Returns
Manifest string, empty if no tool calls. @utility
Version
2.1.3

Definition at line 1972 of file engine.cpp.

◆ build_tool_results_json()

static std::string entropic::build_tool_results_json ( const std::vector< Message > &  messages)
static

Build a JSON array of tool results from context messages.

Extracts messages with metadata["tool_name"] and serializes them as [{"name":"...", "content":"..."}] for the ON_COMPLETE hook.

Parameters
messagesConversation messages.
Returns
JSON array string. @utility
Version
2.0.10

Definition at line 2256 of file engine.cpp.

◆ call_docs_provider()

static std::string entropic::call_docs_provider ( char *(*)(const char *, void *)  fn,
const char *  section,
void *  ud 
)
static

Call docs callback with section param.

Parameters
fnDocs callback.
sectionSection name (nullptr for full doc).
udUser data.
Returns
String content. @dg_internal
Version
1.9.12

Definition at line 932 of file entropic_server.cpp.

◆ call_history_provider()

static std::string entropic::call_history_provider ( char *(*)(int, void *)  fn,
int  max_entries,
void *  ud 
)
static

Call history callback with max_entries param.

Parameters
fnHistory callback.
max_entriesMax entries to return.
udUser data.
Returns
JSON string. @dg_internal
Version
1.9.12

Definition at line 909 of file entropic_server.cpp.

◆ call_provider()

static std::string entropic::call_provider ( char *(*)(void *)  fn,
void *  ud 
)
static

Call a state provider callback and wrap result.

Every introspection tool reads engine state through the entropic_state_provider_t callback struct, and each individual callback is null-checked here rather than dereferenced.

Parameters
fnCallback returning malloc'd string (or nullptr).
udUser data for callback.
Returns
The callback's string, copied and its buffer freed; "{}" when the callback is absent or returned null. @req REQ-MCP-024
Version
1.9.12

Definition at line 886 of file entropic_server.cpp.

◆ calls_satisfy_schema()

bool entropic::calls_satisfy_schema ( const std::vector< ToolCall > &  calls,
const std::string &  tools_json 
)

Check that every call's declared required parameters are present.

Parameters
callsParsed tool calls.
tools_jsonStaged MCP tool defs.
Returns
true when nothing is provably missing — including the vacuous cases of no calls or no staged schema, and calls naming a tool outside the staged set, which are left alone. @req REQ-INFER-010
Version
2.10.3

The detector for common_chat's silent first-parameter-only extraction. A call naming a tool absent from tools_json is left alone — unknown tools are not this function's business.

Parameters
callsParsed tool calls.
tools_jsonStaged MCP tool defs (array of {name, inputSchema, ...}).
Returns
true when nothing is provably missing.
Version
2.10.3

Definition at line 110 of file response_parse.cpp.

◆ cancel_current_run()

bool entropic::cancel_current_run ( )

Cancel the run executing on this thread (gh#158).

gh#158: cancel this thread's run — see header.

The write counterpart of current_run_cancelled(), for the one site that needs to stop a run FROM INSIDE it: the pause prompt, when the consumer declines to inject anything, means "abandon this turn". Pre-2.13.0 that site raised AgentEngine::interrupt_flag_ — the handle-wide flag — which with keyed runs aborts every other session's turn as well.

Returns
true when a run scope was installed on this thread and its token was set; false when there is none, in which case the caller must fall back to whatever handle-wide flag it owns. @req REQ-LOOP-006
Version
2.13.0
Returns
true when a token was installed and has been set. @req REQ-LOOP-006
Version
2.13.0

Definition at line 68 of file run_scope.cpp.

◆ cancel_inflight_async_tasks()

static void entropic::cancel_inflight_async_tasks ( entropic_handle_t  handle,
ExternalBridge *  bridge,
const std::string &  session_key 
)
static

Cancel any async tasks currently running on the bridge.

Raises engine interrupt, flips still-running tasks into phase="cancelling", and polls up to ~1s for detached workers to finish. After the poll, unconditionally bumps the observer generation via detach_phase_observer() so any post-poll callbacks from a still- running worker are silently discarded. (P1-8, 2.0.6-rc16; observer-gen force-detach: E5+E6, 2.1.0)

Parameters
handleEngine handle (for interrupt).
bridgeBridge whose tasks_ registry is being canceled.
session_keySession being cleared; nothing else is touched. @req REQ-BRIDGE-001
Version
2.1.0

Definition at line 691 of file external_bridge.cpp.

◆ capture_diff()

static bool entropic::capture_diff ( const std::filesystem::path &  base,
const std::filesystem::path &  head,
std::string &  patch 
)
static

Run git diff --no-index between base and head, capture patch.

Parameters
baseSnapshot directory.
headFinal sandbox directory.
[out]patchCaptured unified diff (may be empty when no changes).
Returns
true on success (zero or one exit code from git diff). @utility
Version
2.1.5

Definition at line 439 of file sandbox.cpp.

◆ carry_context()

static size_t entropic::carry_context ( const nlohmann::json &  args,
nlohmann::json &  result 
)
static

Copy a context argument into the result, dropping junk (gh#162).

Entries without a path are dropped rather than forwarded: a context reference with nothing to open is noise in the child's opening message, and small models treat noise as instruction.

Parameters
argsParsed tool arguments.
[out]resultResult JSON to populate with a "context" array.
Returns
Number of usable references carried through. @utility
Version
2.13.0

Definition at line 338 of file entropic_server.cpp.

◆ check_create_preconditions()

static entropic_error_t entropic::check_create_preconditions ( const IdentityConfig &  config,
const IdentityManagerConfig &  mgr_config,
const std::unordered_map< std::string, IdentityConfig > &  identities 
)
static

Check create preconditions before validation.

Parameters
configIdentity config to check.
mgr_configManager configuration.
identitiesCurrent identity map.
Returns
ENTROPIC_OK if preconditions pass, error code otherwise. @req REQ-IDEN-002
Version
1.9.6

Definition at line 83 of file identity_manager.cpp.

◆ check_enum()

static std::string entropic::check_enum ( const std::string &  key,
const nlohmann::json &  allowed,
const nlohmann::json &  val 
)
static

Check one property's enum and type constraints.

Parameters
keyProperty name.
propProperty schema.
valArgument value.
Returns
Error string, or empty on pass. @utility
Version
2.0.6

Check a single value against an enum constraint.

Parameters
keyProperty name.
allowedEnum array from schema.
valArgument value.
Returns
An empty string when the value is one of the declared options; otherwise a message naming the property, the offending value and the full set of valid options. @req REQ-MCP-013
Version
2.0.6

Definition at line 341 of file tool_executor.cpp.

◆ check_mutable()

static entropic_error_t entropic::check_mutable ( const std::string &  name,
const std::unordered_map< std::string, IdentityConfig > &  identities,
std::unordered_map< std::string, IdentityConfig >::const_iterator &  out_it 
)
static

Check that a mutable identity exists and is dynamic.

Parameters
nameIdentity name.
identitiesIdentity map.
Returns
Iterator to identity on success, end() on failure. Sets out_err to the error code on failure. @req REQ-IDEN-002
Version
1.9.6

Definition at line 114 of file identity_manager.cpp.

◆ check_property_constraints()

static std::string entropic::check_property_constraints ( const std::string &  key,
const nlohmann::json &  prop,
const nlohmann::json &  val 
)
static

Check one property's enum, type and range constraints.

Parameters
keyProperty name.
propProperty schema.
valArgument value.
Returns
An empty string when the value satisfies the enum (if declared), the type (if declared) and the numeric range (if declared, v2.14.0); otherwise the first failing check's error, in that order. @req REQ-MCP-013
Version
2.14.0

Definition at line 424 of file tool_executor.cpp.

◆ check_range()

static std::string entropic::check_range ( const std::string &  key,
const nlohmann::json &  prop,
const nlohmann::json &  val 
)
static

Check a numeric value against minimum / maximum (v2.14.0).

Bounds were declared by bundled schemas (followup.max_results) and by v2.14.0's paging arguments, but never enforced — an undocumented acceptance of out-of-range values.

Parameters
keyProperty name.
propProperty schema.
valArgument value.
Returns
"" when in range or not numeric; else a message naming the property, the value and the bound. @req REQ-MCP-013
Version
2.14.0

Definition at line 394 of file tool_executor.cpp.

◆ check_read_gates()

std::string entropic::check_read_gates ( FilesystemServer &  server,
const fs::path &  resolved,
const std::string &  display 
)

Execute read_file: resolve, size-check, read, hash, track.

Parameters
args_jsonJSON arguments.
Returns
ServerResponse with content or error. @dg_internal
Version
1.8.5

Run pre-read gates (existence, directory, ignore).

Path-relative ignore matching uses the server's IgnoreMatcher (#15, v2.1.4). v2.14.0: the whole-file size gate is gone — a large file is read a window at a time (gh#201); max_read_bytes is now the window's byte budget.

Parameters
serverOwning server (source of the root and ignore rules).
resolvedAlready root-confined path.
displayPath as shown to the model.
Returns
An empty string when the read may proceed; otherwise a structured error — not_found (whose message names list_directory, gh#124), is_directory for a directory argument (gh#116), or ignored for a path excluded by .gitignore/.explorerignore. @req REQ-MCP-021 @req REQ-MCP-022
Version
2.14.0

Definition at line 1390 of file filesystem.cpp.

◆ check_required_fields()

static std::string entropic::check_required_fields ( const nlohmann::json &  schema,
const nlohmann::json &  args 
)
static

Check required fields are present.

Parameters
schemaParsed JSON Schema object.
argsParsed tool arguments.
Returns
An empty string when every declared required field is present; otherwise "Missing required argument: <name>" for the first absent one. @req REQ-MCP-013
Version
2.0.6

Definition at line 307 of file tool_executor.cpp.

◆ check_type()

static std::string entropic::check_type ( const std::string &  key,
const std::string &  type,
const nlohmann::json &  val 
)
static

Check a single value against a type constraint.

Parameters
keyProperty name.
typeExpected JSON Schema type string.
valArgument value.
Returns
An empty string when the value matches the declared type; otherwise "Type mismatch for '<key>': expected <type>". An unrecognised type name reads as a mismatch. @req REQ-MCP-013
Version
2.0.6

Definition at line 364 of file tool_executor.cpp.

◆ classify_offload()

Offload entropic::classify_offload ( int  gpu_layers)
inline

Classify a tier's offload request into a priceable placement.

A specific positive layer count below the sentinel cannot be turned into bytes without knowing the model's total layer count, which needs GGUF metadata this estimate deliberately does not read.

Parameters
gpu_layersTier's configured offload layer count.
Returns
Which placement the estimate can assume. @req REQ-INFER-019
Version
2.11.0

Definition at line 184 of file vram_footprint.h.

◆ classify_tool_result()

static ToolResultKind entropic::classify_tool_result ( const std::string &  content)
static

Classify a tool result by its content (error/empty/ok).

Parameters
contentResult content (already size-capped, so the kind describes the bounded form the model saw).
Returns
ToolResultKind::error for error-shaped content, ToolResultKind::ok_empty for byte-level-empty content, ToolResultKind::ok otherwise — error trumps empty trumps ok (#44). @req REQ-MCP-019
Version
2.3.7

Definition at line 1009 of file tool_executor.cpp.

◆ close_marker_for_format()

std::string entropic::close_marker_for_format ( common_chat_format  fmt)
inline

Map a resolved common_chat format to its single-tool-call close marker.

Single-return (knots returns ≤ 3). PEG_NATIVE / PEG_SIMPLE use the PEG section_end default </tool_call> (qwen3 / hermes / nemotron-style). All other formats return "" (no reliable per-call marker → batch-safe fallback).

Parameters
fmtResolved common_chat format (from the last tool render).
Returns
</tool_call> for the PEG native/simple families, <tool_call|> for gemma4, and "" for CONTENT_ONLY or any unknown format — "" is always safe: it injects no stop, so batch behaviour stays byte-identical and no parse can be corrupted. @req REQ-INFER-013
Version
2.8.2

Definition at line 52 of file tool_call_markers.h.

◆ coerce_call_string_args()

static void entropic::coerce_call_string_args ( ToolCall &  tc,
const nlohmann::json &  tools 
)
static

Coerce one call's numeric args to strings per the tool schema.

Parameters
tcTool call (arguments_json + arguments mutated in place).
toolsParsed MCP tool array. @dg_internal
Version
2.7.2

Definition at line 369 of file adapter_base.cpp.

◆ coerce_string_typed_args()

void entropic::coerce_string_typed_args ( std::vector< ToolCall > &  calls,
const std::string &  tools_json 
)

gh#90: coerce numeric scalars back to strings for string-typed tool parameters.

gh#90 string-typing coercion entry point — see header.

gemma's <|"|></tt> string-escape loses type through PEG_GEMMA4 — a numeric-looking string arg (e.g. <tt>grade_level:\<|"|>3<|"|\></tt>) arrives as a JSON number, a string-typed schema then rejects it (&lsquo;3 is not of type 'string&rsquo;<tt>), and the delegation circuit-breaks. For each call, when the staged tool schema declares a parameter</tt>"type":"string"and the parsed value is a JSON number, coerce it to its string form (updates both arguments_jsonand thearguments` map). No-op when tools_json is empty/invalid or the parameter is genuinely non-string. Applied on the common_chat-reliable (gemma) parse path.

Parameters
callsIn/out parsed tool calls.
tools_jsonStaged MCP tool defs (array of {name, inputSchema,...}).
Version
2.7.2
Parameters
callsIn/out parsed calls; numeric args re-typed in place.
tools_jsonStaged MCP tool defs (JSON array) carrying the schema. @req REQ-INFER-012
Version
2.7.2

Definition at line 397 of file adapter_base.cpp.

◆ col_nullable_int()

static json entropic::col_nullable_int ( sqlite3_stmt *  stmt,
int  col 
)
static

Get a nullable integer column as a JSON value.

Parameters
stmtPrepared statement.
colColumn index.
Returns
json(nullptr) for SQL NULL, json(value) otherwise. @utility
Version
2.9.9

Definition at line 141 of file backend.cpp.

◆ col_opt_text()

static std::optional< std::string > entropic::col_opt_text ( sqlite3_stmt *  stmt,
int  col 
)
static

Get optional text from a sqlite3 column.

Parameters
stmtPrepared statement.
colColumn index.
Returns
Column text or nullopt if NULL. @utility
Version
1.8.8

Definition at line 127 of file backend.cpp.

◆ col_text()

static std::string entropic::col_text ( sqlite3_stmt *  stmt,
int  col 
)
static

Get text from a sqlite3 column, returning empty string for NULL.

Parameters
stmtPrepared statement.
colColumn index.
Returns
Column text or empty string. @utility
Version
1.8.8

Definition at line 114 of file backend.cpp.

◆ collect_array_names()

static std::vector< std::string > entropic::collect_array_names ( const nlohmann::json &  j)
static

Collect "name" fields from a JSON array of objects.

Parameters
jJSON array.
Returns
Vector of name strings. @dg_internal
Version
1.9.12

Definition at line 1154 of file entropic_server.cpp.

◆ collect_object_keys()

static std::vector< std::string > entropic::collect_object_keys ( const nlohmann::json &  j)
static

Collect keys from a JSON object into a vector.

Parameters
jJSON object.
Returns
Vector of key strings. @dg_internal
Version
1.9.12

Definition at line 1138 of file entropic_server.cpp.

◆ common_prefix_len()

template<typename Tok >
std::size_t entropic::common_prefix_len ( const std::vector< Tok > &  a,
const std::vector< Tok > &  b 
)
inline

Length of the longest common token prefix of two sequences.

Parameters
aFirst sequence (resident KV tokens).
bSecond sequence (incoming prompt tokens).
Returns
Number of leading tokens that match position-for-position. @utility
Version
2.7.5

Definition at line 30 of file warm_keep_util.h.

◆ compile_grep_or_error()

std::regex entropic::compile_grep_or_error ( const std::string &  pattern,
std::string &  err 
)

Compile a regex or return a structured tool error.

Parameters
patternRegex source.
[out]errSet to a non-empty JSON error string on failure.
Returns
The compiled regex on success; on failure a never-matching regex with err set to a structured invalid_regex error — a bad pattern from the model is a tool error, never a throw through the dispatch path. @req REQ-MCP-021
Version
2.1.4

Definition at line 1762 of file filesystem.cpp.

◆ compute_allowance_bytes()

uint64_t entropic::compute_allowance_bytes ( const FootprintInputs &  base,
int  n_ubatch 
)
inline

VRAM to hold back for graph/activation scratch.

The footprint estimator does not count compute buffers and documents why: they are sized by ubatch and model internals, not by anything the estimate reads. A speculative configuration holds TWO contexts and pays the cost twice.

Held back by auto specifically. An operator naming gpu_layers has decided for themselves; auto has not, so it must leave room for the term it cannot compute.

Scaled by ubatch, because that is what the cost tracks. Two measurements from this project anchor it: 1222 MiB per context for a gemma-4 E4B MTP head at ubatch 512, and roughly 520 MiB across all contexts for the 26B-A4B at IQ2 at ubatch 128. A flat allowance sized for the first refuses the second — which is a configuration this project has measured running at 30 of 30 layers with headroom to spare. Refusing a placement that demonstrably works is the failure this whole change exists to stop, so the allowance moves with the knob the cost moves with.

Parameters
baseFootprint inputs — draft_bytes non-zero means two contexts.
n_ubatchPhysical batch size; <= 0 assumes llama.cpp's default.
Returns
Bytes to subtract from free VRAM before choosing a placement. @dg_internal
Version
2.13.1

Definition at line 128 of file auto_placement.h.

◆ compute_max_read_bytes()

static int entropic::compute_max_read_bytes ( const FilesystemConfig &  config,
int  model_context_bytes 
)
static

Compute max read bytes from config and model context.

Parameters
configFilesystem configuration.
model_context_bytesModel context window in bytes.
Returns
The explicit config max_read_bytes when set; else a percentage of the model context; else a 32KB default — the gate that turns an oversized read into a size_exceeded error instead of a blown context budget. @req REQ-MCP-021
Version
2.0.4

Definition at line 2022 of file filesystem.cpp.

◆ compute_socket_path()

std::filesystem::path entropic::compute_socket_path ( const std::filesystem::path &  project_dir)

Compute project-unique Unix socket path for self-detection.

Compute project-unique Unix socket path.

Parameters
project_dirAbsolute path to project directory.
Returns
Socket path: ~/.entropic/socks/{hash8}.sock
Version
1.8.7

Deterministic in the canonical project path, which is what lets discovery recognise and skip the engine's OWN socket rather than connecting to itself.

Parameters
project_dirProject directory.
Returns
~/.entropic/socks/{hash8}.sock (HOME falling back to /tmp). @req REQ-MCP-025
Version
1.8.7

Definition at line 288 of file mcp_json_discovery.cpp.

◆ concat_messages_fallback()

static std::string entropic::concat_messages_fallback ( const std::vector< Message > &  messages)
static

Plain "role: content" join used when templating fails.

Parameters
messagesConversation history.
Returns
Concatenated fallback prompt. @utility
Version
2.3.7

Definition at line 1479 of file llama_cpp_backend.cpp.

◆ concat_user_echo()

static std::string entropic::concat_user_echo ( const std::vector< Message > &  messages)
static

Concatenate user-role message text for session-log echo.

Parameters
messagesIncoming messages for the streaming turn.
Returns
Newline-joined user text (skips system/assistant turns). @dg_internal
Version
2.1.8

Definition at line 4162 of file engine.cpp.

◆ context_fit_breakdown()

std::string entropic::context_fit_breakdown ( const ContextFit &  f)
inline

Per-contributor token breakdown, as one clause.

Parameters
fMeasured prompt sizing.
Returns
"staged tools N tok (M tools, B bytes), system prompt ... ". @utility
Version
2.13.0

Definition at line 114 of file context_fit.h.

◆ context_fit_history_tokens()

int entropic::context_fit_history_tokens ( const ContextFit &  f)
inline

Tokens left over once system prompt and tool block are accounted.

Parameters
fMeasured prompt sizing.
Returns
Non-negative remainder attributed to the message history. @utility
Version
2.13.0

Definition at line 76 of file context_fit.h.

◆ context_fit_largest_contributor()

std::string entropic::context_fit_largest_contributor ( const ContextFit &  f)
inline

Name the single largest contributor to the overflow.

This is the whole point of the diagnosis: tool block, system prompt and history each have a DIFFERENT fix (narrow allowed_tools, shorten the identity, raise context_length), and an operator told only the total has to guess which one.

Parameters
fMeasured prompt sizing.
Returns
Human-readable name of the dominant contributor. @utility
Version
2.13.0

Definition at line 94 of file context_fit.h.

◆ context_fit_overflows()

bool entropic::context_fit_overflows ( const ContextFit &  f)
inline

Whether this turn's prompt cannot fit the tier's context at all.

The test is deliberately the unarguable one: a prompt at or beyond context_length leaves the model zero positions to emit into, so no downstream behaviour can rescue it. It does NOT reserve room for max_tokens — a prompt that fits but leaves less headroom than the caller asked for is a "length" finish, not a refusal, and clamping it silently is the very thing this guard exists to stop.

Parameters
fMeasured prompt sizing.
Returns
true when the turn must be refused before any decode. @req REQ-INFER-026
Version
2.13.0

Definition at line 65 of file context_fit.h.

◆ context_overflow_message()

std::string entropic::context_overflow_message ( const ContextFit &  f)
inline

The refusal an operator reads, carrying every number they need.

Names the token count, the tier's context_length, the overshoot, the dominant contributor and the full breakdown — then the two knobs that can actually change the outcome. No silent trim, no auto-raise.

Parameters
fMeasured prompt sizing (expected to satisfy context_fit_overflows).
Returns
One-line diagnosis for the error result and the ERROR log. @req REQ-INFER-026
Version
2.13.0

Definition at line 135 of file context_fit.h.

◆ create_adapter()

std::unique_ptr< ChatAdapter > entropic::create_adapter ( const std::string &  name,
const std::string &  tier_name,
const std::string &  identity_prompt 
)

Create adapter by name (gh#87 Phase D hybrid).

Create an adapter instance by name.

Autoparser families (qwen35 / qwen36 / nemotron3) resolve to their per-family multi-parameter adapter. Everything else — including gemma4, whose tool calls are parsed by common_chat's dedicated grammar — falls back to GenericAdapter (identity assembly + generic fallback parse).

Lookup is case-insensitive, and an unrecognised name falls back to GenericAdapter rather than failing — a misconfigured adapter name must not take the tier down.

Parameters
nameAdapter name from config.
tier_nameIdentity tier name.
identity_promptAssembled identity prompt.
Returns
Owned adapter instance: the matching family adapter for a registered key, GenericAdapter for anything else. @req REQ-INFER-012
Version
2.7.0 (Phase D)
Parameters
nameAdapter name from config (e.g. "qwen35", "generic").
tier_nameIdentity tier name.
identity_promptAssembled prompt from PromptManager.
Returns
Owned adapter. Falls back to GenericAdapter if unknown.
Version
1.8.2

Definition at line 123 of file adapter_registry.cpp.

◆ create_listen_socket()

static int entropic::create_listen_socket ( const std::filesystem::path &  path)
static

Create, bind, and listen on a unix domain socket.

v2.1.7 hardening (gh#34): containing dir 0700, socket file 0600, symlink-and-non-socket-safe bind. Path canonicalization + the hash naming scheme (see compute_socket_path) already provide a unique per-project path inside ~/.entropic/socks/; these checks defend against the residual cases where the path is squatted or perms have been loosened.

Parameters
pathSocket filesystem path.
Returns
Listening fd, or -1 on failure. @req REQ-BRIDGE-001
Version
2.14.0

Definition at line 1392 of file external_bridge.cpp.

◆ current_run_cancel()

const std::atomic< bool > * entropic::current_run_cancel ( )

The cancel token of the run executing on this thread, if any.

gh#158: this thread's run cancel token — see header.

Returns
Pointer to the run's cancel flag, or nullptr when no run scope is active on this thread (a plain API call, a consumer thread, a test). @req REQ-LOOP-006
Version
2.13.0
Returns
Pointer to the run's cancel flag, or nullptr outside a run. @req REQ-LOOP-006
Version
2.13.0

Definition at line 37 of file run_scope.cpp.

◆ current_run_cancelled()

bool entropic::current_run_cancelled ( )

Whether THIS thread's run has been cancelled.

gh#158: has this thread's run been cancelled — see header.

The form every poll site wants: a transport or a decode loop asks "should I stop?", not "what is my token?". Returns false when no scope is installed, so a caller outside a run is never spuriously cancelled.

Returns
true when a run scope is active on this thread AND its flag is set. @req REQ-LOOP-006
Version
2.13.0
Returns
true when a run scope is active AND its flag is set. @req REQ-LOOP-006
Version
2.13.0

Definition at line 45 of file run_scope.cpp.

◆ current_run_session()

std::string entropic::current_run_session ( )

The session key of the run executing on this thread (gh#166).

gh#166: this thread's run session key — see header.

Same mechanism and same justification as the cancel token above: a run is a blocking call on the caller's thread, and everything it does — including asking the facade "which tools does this turn see?" — happens on that thread. gh#166 binds a session to a WORKSPACE, so the tool root and the tool list are no longer handle-wide constants; the one call that needs them (get_tool_prompt, on the inference callback seam) is reached through i_inference_callbacks.h, an INTERFACE header that does not change without a proposal. Publishing the key per thread answers the question without touching that contract.

Returns
The running turn's session key, or "" outside a keyed run. @req REQ-LOOP-009
Version
2.13.0
Returns
The running turn's session key, or "" outside a keyed run. @req REQ-LOOP-009
Version
2.13.0

Definition at line 95 of file run_scope.cpp.

◆ decode_tool_calls_json()

static std::vector< ToolCall > entropic::decode_tool_calls_json ( const std::string &  tc_str)
static

Decode a JSON tool-calls array string into ToolCall vector.

Parameters
tc_strJSON array string ("[]" or "" yields empty result).
Returns
Parsed ToolCall vector (empty on parse failure or empty input). @dg_internal
Version
2.0.2

Definition at line 1736 of file engine.cpp.

◆ derive_async_final_state()

static AsyncFinalState entropic::derive_async_final_state ( entropic_handle_t  handle,
entropic_error_t  err,
char *  result_json 
)
static

Translate entropic_run's return code into a final task state.

On success, extracts the final clean assistant text from result_json and frees it. On cancellation/error, reports the last-error message. (P1-5, 2.0.6-rc16)

Parameters
handleEngine handle (for last-error lookup).
errReturn code from entropic_run.
result_jsonJSON result (owned; freed on success, else NULL).
Returns
AsyncFinalState ready to be stored on the task. @req REQ-BRIDGE-001
Version
2.10.2

Definition at line 603 of file external_bridge.cpp.

◆ derive_auto_placement()

AutoPlacement entropic::derive_auto_placement ( const GgufShape &  shape,
const FootprintInputs &  base,
uint64_t  free_vram_bytes,
int  n_ubatch = 0 
)
inline

Choose the placement that uses the card best without overcommitting.

Tries, in order of preference:

  1. Everything resident.
  2. Everything resident at a smaller n_ubatch (v2.13.2) — measured to cost prefill only, where every option below it costs decode too.
  3. Everything resident with experts progressively moved host-side — a MoE only, and preferred over dropping layers because it keeps attention on the card.
  4. Progressively fewer layers, for a dense model or when even all experts host-side is not enough.
Parameters
shapeGGUF shape from read_gguf_shape.
baseFootprint inputs: context, cache types, sessions, mmproj, draft head, and vram_reserve_mb headroom. Its gpu_layers is ignored — that is what this decides.
free_vram_bytesFree VRAM on the target device right now.
n_ubatchTier's physical batch size; 0 assumes llama.cpp's default. Auto may return a SMALLER one in AutoPlacement::n_ubatch; it never returns a larger.
Returns
The chosen placement; known == false when the shape is unusable or nothing fits, and the caller must then leave the configuration as the operator wrote it. @req REQ-INFER-019
Version
2.13.2

Definition at line 331 of file auto_placement.h.

◆ derive_pool_geometry()

PoolGeometry entropic::derive_pool_geometry ( const ModelConfig &  cfg)
inline

Derive the context geometry a tier's config implies.

Parameters
cfgTier model config.
Returns
The geometry build_cparams should apply. @req REQ-INFER-019
Version
2.12.0

Definition at line 66 of file session_pool_util.h.

◆ describe()

static std::string entropic::describe ( const ExternalMCPConfig &  cfg,
const char *  suffix,
const char *  fallback 
)
static

Resolve a tool's description, honouring any consumer override.

gh#145 (v2.12.0): the description is what a MODEL reasons over when choosing a tool, and the stock text describes the transport rather than the capability — so a host with one specific job can replace it. An absent or unknown key leaves the built-in text untouched.

Parameters
cfgExternal MCP config carrying any overrides.
suffixBare tool suffix.
fallbackBuilt-in description.
Returns
The override when one is configured, else fallback. @utility
Version
2.12.0

Definition at line 141 of file external_bridge.cpp.

◆ describe_grammar()

GrammarProvenance entropic::describe_grammar ( const GenerationParams &  params,
const std::string &  tool_grammar 
)
inline

Describe what constrained one decode, for the result record (gh#154).

Reads the SAME two inputs apply_grammar_source reads — the resolved params.grammar and the render-derived tool grammar — through the same resolve_grammar_source, so the record cannot disagree with what the sampler did. That is the property worth having: a provenance field computed from a parallel rule would be a second thing to keep in sync, and gh#95 / gh#108 / gh#134 are all instances of that going wrong.

A key that was NAMED but produced no text reports resolved: false with the naming source still in source — the fail-open state a consumer previously could only detect by a MISSING log line.

Parameters
paramsResolved generation params (post resolve_grammar_key).
tool_grammarRender-derived tool-call GBNF ("" when none).
Returns
Provenance for GenerationResult::grammar. @req REQ-INFER-008
Version
2.13.0

Definition at line 207 of file grammar_source.h.

◆ destroy_orchestrator_interface()

void entropic::destroy_orchestrator_interface ( InterfaceContext *  context)

Free a context returned by build_orchestrator_interface().

Safe to call on nullptr.

Version
2.2.6

@dg_internal

Version
2.2.6

Definition at line 619 of file interface_factory.cpp.

◆ device_memory_query_count()

uint64_t entropic::device_memory_query_count ( )

How many device free-VRAM queries this process has made (gh#198).

How many times this process has asked the device for free VRAM.

Returns
The count. @req REQ-INFER-019
Version
2.14.0

gh#198: the query is the call that creates a CUDA primary context (ggml_backend_dev_memory → cudaMemGetInfo), ~138 MiB on a GTX 1080 Ti, so "did an idle handle touch the device" is exactly "did this count move". Counted on every build, including CPU-only ones where the query returns 0, so the property is testable without a GPU.

Returns
Number of calls to query_device_free_vram_bytes() so far. @req REQ-INFER-019
Version
2.14.0

Definition at line 84 of file device_memory.cpp.

◆ diagnose_empty_content()

EmptyContentCause entropic::diagnose_empty_content ( bool  content_empty,
bool  produced_tokens,
const std::string &  finish_reason,
bool  has_tool_calls 
)
inline

Classify an empty-content turn from what the decode reported.

gh#159: has_tool_calls has NO default, deliberately. The defect was that this function had no tool-call input at all, so a turn whose entire output was a tool call — content empty, raw non-empty, finish "stop", which is the NORMAL shape on a sequential tool-call tier — was byte-for-byte the gh#137 shape and got gh#137's diagnosis. A default would let a future call site silently re-enter that state; requiring the argument makes every caller say what it knows.

The tool-call branch is checked FIRST, ahead of finish_reason: a parsed call is evidence the turn did its job, whatever ended the decode. A budget-starved mandatory-tool turn is a different diagnostic and is owned by warn_if_budget_starved_required_turn (gh#134), which guards on ZERO tool calls.

Parameters
content_emptyWhether the post-strip content is empty.
produced_tokensWhether the model emitted anything at all.
finish_reasonDecode finish reason ("stop", "length", "error", ...).
has_tool_callsWhether the adapter parsed at least one tool call out of this turn.
Returns
The cause, which decides what advice is honest to give. @req REQ-INFER-010
Version
2.13.0

Definition at line 68 of file empty_content_diagnosis.h.

◆ diff_files()

static std::vector< std::filesystem::path > entropic::diff_files ( const std::filesystem::path &  base,
const std::filesystem::path &  head 
)
static

List files differing between base and head via diff -rq-style logic.

Parameters
baseSnapshot directory.
headFinal sandbox directory.
Returns
Vector of relative paths. @utility
Version
2.3.7

Definition at line 486 of file sandbox.cpp.

◆ directive_type_name()

static const char * entropic::directive_type_name ( entropic_directive_type_t  type)
static

Map directive type enum to wire-format string.

Range-checked on both ends so an out-of-range enum value serialises as "unknown" rather than reading past the name table.

Parameters
typeDirective type.
Returns
The fixed wire name for an in-range value, "unknown" otherwise. @req REQ-MCP-002
Version
1.8.5

Definition at line 309 of file server_base.cpp.

◆ discovered_server_json()

std::string entropic::discovered_server_json ( const ExternalServerConfig &  cfg,
const std::filesystem::path &  root 
)
inline

The pre-connect hook's context JSON for one discovered server.

Parameters
cfgServer config.
rootRoot the server would run in.
Returns
JSON string (see ENTROPIC_HOOK_PRE_MCP_SERVER_CONNECT). @utility
Version
2.14.0

Definition at line 144 of file discovery_policy.h.

◆ dispatch_ask()

static json entropic::dispatch_ask ( entropic_handle_t  handle,
ExternalBridge *  bridge,
const json &  args,
int  client_fd,
const json &  progress_token 
)
static

Route entropic.ask — sync (streaming) or async.

Parameters
handleEngine handle.
bridgeBridge (for async task registry).
argsTool arguments.
client_fdSocket fd.
call_idRequest id.
Returns
MCP tool result JSON. @req REQ-BRIDGE-001
Version
2.12.0-rc1

Definition at line 1005 of file external_bridge.cpp.

◆ dispatch_inspect()

static std::string entropic::dispatch_inspect ( const entropic_state_provider_t &  p,
const std::string &  target,
const std::string &  key,
nlohmann::json &  data 
)
static

Dispatch an inspect query to the appropriate provider.

Parameters
pState provider callbacks.
targetQuery target.
keyOptional filter key.
[out]dataThe target's data.
Returns
"" on success, else a declared error (unknown_target, not_found). @dg_internal
Version
2.14.0

Definition at line 1286 of file entropic_server.cpp.

◆ dispatch_simple_target()

static bool entropic::dispatch_simple_target ( const entropic_state_provider_t &  p,
const std::string &  target,
const std::string &  key,
nlohmann::json &  data 
)
static

Dispatch inspect for simple (non-filterable) targets.

Parameters
pState provider.
targetTarget name.
keyOptional key (history: entry count; docs: section).
[out]dataTarget data — JSON for state/metrics/history, the documentation text for docs.
Returns
true if target was handled. @dg_internal
Version
2.14.0

Definition at line 1250 of file entropic_server.cpp.

◆ dispatch_tool()

static json entropic::dispatch_tool ( entropic_handle_t  handle,
ExternalBridge *  bridge,
const json &  params,
int  client_fd,
const std::string &  call_id 
)
static

Dispatch a tools/call to the appropriate handler.

entropic.ask streams progress notifications to client_fd during generation, then returns the final clean text as the tool result. When async=true, spawns a background thread and returns task_id.

Parameters
handleEngine handle.
bridgeBridge instance (for async task registry).
paramsJSON-RPC params (name + arguments).
client_fdSocket fd for streaming (the ask tool only).
call_idJSON-RPC request id for progress correlation.
Returns
MCP tool result JSON. @req REQ-BRIDGE-001
Version
2.14.3

Definition at line 1141 of file external_bridge.cpp.

◆ dup()

static char * entropic::dup ( const std::string &  s)
static

Heap-allocate a C string copy.

Parameters
sSource string.
Returns
strdup'd copy (caller frees). @utility
Version
2.0.1

Definition at line 163 of file interface_factory.cpp.

◆ effective_n_draft()

static int entropic::effective_n_draft ( int  n_max)
static

Draft-window size setup_mtp_draft will actually use (gh#106).

setup_mtp_draft normalises a non-positive n_max to 16. The envelope check must apply the SAME normalisation or it validates a number the engine never uses.

Parameters
n_maxRequested window, possibly non-positive.
Returns
The effective window size. @req REQ-INFER-015
Version
2.11.0 @dg_internal

Definition at line 837 of file llama_cpp_backend.cpp.

◆ emit_to_current_run_stream()

bool entropic::emit_to_current_run_stream ( const char *  chunk,
size_t  len 
)

Deliver a chunk to the stream sink published on THIS thread.

Deliver a chunk to this thread's run stream sink (gh#208).

gh#208 (v2.14.2): a streaming run's sink is per run, not per handle. The engine used to store it in the handle-wide callbacks slot, where a second concurrent streaming run overwrote it — routing one run's tokens to the other's consumer and, once that run returned, into a dead stack frame.

Parameters
chunkChunk bytes.
lenChunk length.
Returns
true when a sink is installed on this thread (and was called). @utility @req REQ-LOOP-008
Version
2.14.2
Parameters
chunkChunk bytes.
lenChunk length.
Returns
true when a sink is installed (and was called). @utility @req REQ-LOOP-008
Version
2.14.2

Definition at line 137 of file run_scope.cpp.

◆ enrich_manifest_with_history()

static std::string entropic::enrich_manifest_with_history ( const std::string &  base,
const ToolExecutionInterface &  tool_exec 
)
static

Append executor history (if any) to the tool manifest.

Enriches the validator revision prompt with iteration numbers and elapsed times pulled from ToolExecutor's ToolCallHistory ring buffer via the ToolExecutionInterface::history_json callback. (P1-11, 2.0.6-rc16)

Parameters
baseExisting manifest from messages.
tool_execTool execution interface.
Returns
Enriched manifest (base + history lines if available). @utility
Version
2.0.6-rc16

Definition at line 2098 of file engine.cpp.

◆ estimate_vram_footprint()

FootprintEstimate entropic::estimate_vram_footprint ( const FootprintInputs &  in)
inline

Estimate the VRAM a tier will occupy, or report that it cannot.

Parameters
inTier footprint inputs.
Returns
The estimate, with known == false when the placement is unpriceable. @req REQ-INFER-019
Version
2.13.1

Definition at line 219 of file vram_footprint.h.

◆ expand_workspace_root()

static std::string entropic::expand_workspace_root ( std::string  s,
const std::string &  root 
)
static

Replace every ${ENTROPIC_WORKSPACE_ROOT} with root (v2.14.1).

Parameters
sText from a declared server entry.
rootThis server set's root.
Returns
The expanded text. @utility
Version
2.14.1

Definition at line 1441 of file server_manager.cpp.

◆ expected_bridge_socket()

std::filesystem::path entropic::expected_bridge_socket ( entropic_handle_t  h)

The socket this handle's external bridge binds, or empty when the handle runs no bridge (v2.14.0, gh#200).

The socket this handle's bridge binds, or empty (gh#200).

One function for the bridge and the self-connection guard, so the guard can never compare against a path the bridge does not bind — the exact disagreement gh#200 reported.

Parameters
hEngine handle with config loaded.
Returns
Socket path, or empty.
Version
2.14.0
Parameters
hEngine handle with config loaded.
Returns
Socket path, or empty when the bridge is disabled. @req REQ-MCP-025
Version
2.14.0

Definition at line 191 of file entropic_mcp.cpp.

◆ expert_block_pattern()

std::string entropic::expert_block_pattern ( int  layer)
inline

The override pattern for ONE layer's expert tensors.

Mirrors upstream's llm_ffn_block_regex(idx, LLM_FFN_EXPS_REGEX): blk\.<idx> followed by the expert tail. The blk\. prefix is anchored by the literal \. that opens the tail, so the pattern for layer 1 does NOT match blk.10.ffn_up_exps.weight — after blk.1 the next character must be a dot.

Parameters
layerZero-based layer index.
Returns
ECMAScript regex matching only that layer's routed-expert tensors. @req REQ-INFER-027
Version
2.13.0

Definition at line 93 of file expert_offload.h.

◆ expert_offload_conflict_reason()

std::string entropic::expert_offload_conflict_reason ( const ModelConfig &  cfg)
inline

Configuration-time refusal for a combination that cannot mean what it says.

Checked before any file is opened, so it costs nothing and fires at validate_config with the tier named. Three cases, none of them clamped:

  • Negative N. There is deliberately no "all layers" sentinel. -1 means "every layer" for gpu_layers because llama.cpp defines it that way; nothing defines it here, and inventing it would need a layer count the config layer does not have.
  • N > 0 with gpu_layers: 0. The whole model is already host-side; there is nothing on the card to move off it. Accepting this would make the knob a no-op, and a no-op that an operator explicitly asked for is exactly the fail-open this codebase refuses.
  • N > 0 with gpu_layers: auto. Since v2.13.1 auto derives the expert split itself, from the model's real expert-tensor bytes. Setting both asks two things to decide one placement; drop this knob and let auto choose, or state gpu_layers explicitly and keep your own split.
Parameters
cfgTier config as parsed.
Returns
Empty when acceptable; an operator-actionable reason otherwise. @req REQ-CFG-006 @req REQ-INFER-027
Version
2.13.1

Definition at line 155 of file expert_offload.h.

◆ expert_offload_load_refusal()

std::string entropic::expert_offload_load_refusal ( int  cpu_moe_layers,
int  n_layer,
int  n_expert 
)
inline

Post-load refusal, against the numbers only the loaded model knows.

The two impossible combinations that CANNOT be judged from config alone — both need GGUF metadata (general.architecture, <arch>.expert_count, the block count), and entropic reads no GGUF metadata before loading. So this runs immediately after llama_model_load_from_file and FAILS the load; the caller frees the model. A prototype pays one wasted load to refuse rather than run a configuration that quietly did nothing:

  • Not a MoE model. Every pattern would match zero tensors and the operator would measure "expert offload changes nothing" and conclude something false about the technique.
  • N beyond the block count. The surplus patterns are harmless to llama.cpp, but the request is not satisfiable as stated, and silently treating it as "all layers" is the clamp this codebase does not make.
Parameters
cpu_moe_layersConfigured value; <= 0 accepts unconditionally.
n_layerBlock count reported by llama_model_n_layer.
n_expert<arch>.expert_count from GGUF metadata; 0 when absent.
Returns
Empty when acceptable; an operator-actionable reason otherwise. @req REQ-INFER-027
Version
2.13.1

Definition at line 207 of file expert_offload.h.

◆ expert_offload_patterns()

std::vector< std::string > entropic::expert_offload_patterns ( int  cpu_moe_layers)
inline

Patterns for the FIRST cpu_moe_layers layers, in layer order.

The first N layers, not an arbitrary set — that is upstream's semantic for --n-cpu-moe and there is no reason for a prototype to invent a second one. Zero or negative yields an empty list, which is what makes the absent config key produce no overrides at all.

Warning
"The first N layers" is not the same as "N layers' worth of experts". gemma4 decides per layer whether it has experts at all (has_expert = ffn_gate_inp != nullptr in models/gemma4.cpp), so on a model with dense early blocks some of the first N patterns match nothing and the VRAM actually freed is less than N layers' worth. That is upstream's behaviour too, and it matters when READING a measurement: compare load_tensors: buffer sizes, not the configured count.
Parameters
cpu_moe_layersNumber of layers whose experts go to the host.
Returns
One pattern per layer; empty when the feature is off. @req REQ-INFER-027
Version
2.13.0

Definition at line 119 of file expert_offload.h.

◆ explain_empty_content()

std::string entropic::explain_empty_content ( EmptyContentCause  cause)
inline

Operator-facing explanation for an empty-content turn.

Parameters
causeResult of diagnose_empty_content.
Returns
Advice matching the actual cause, empty when there is nothing to say. @req REQ-INFER-010
Version
2.13.0

Definition at line 93 of file empty_content_diagnosis.h.

◆ extract_args_only_fence()

static std::optional< nlohmann::json > entropic::extract_args_only_fence ( const std::string &  raw)
static

Extract and validate the fenced JSON block for args-only inference.

Parses exactly one fenced json block from raw, validates it is a JSON object with no name/tool key (handled by the gh#122 path), and returns it. Returns nullopt when the block is absent, malformed, multiple, or already has a name/tool key.

Parameters
rawRaw model output.
Returns
Parsed object if valid for args-only inference, nullopt otherwise. @utility
Version
2.10.0

Definition at line 413 of file interface_factory.cpp.

◆ extract_context_refs()

static std::vector< ContextRef > entropic::extract_context_refs ( const nlohmann::json &  result_json)
static

Parse the context array of a delegate/pipeline result (gh#162).

The MCP layer owns this because core.so takes typed structs, never JSON (design decision #21). Entries without a path are skipped — the tool boundary already dropped them, and a second reader must not resurrect what the first refused.

Parameters
result_jsonParsed tool result JSON.
Returns
Typed references, empty when the key is absent or malformed. @utility @req REQ-DELEG-006
Version
2.13.0

Definition at line 1783 of file tool_executor.cpp.

◆ extract_directive_array()

static std::optional< std::pair< nlohmann::json, nlohmann::json > > entropic::extract_directive_array ( const std::string &  raw_result)
static

Pull the "directives" array out of a tool ServerResponse JSON.

Parameters
raw_resultRaw ServerResponse JSON string.
Returns
The parsed envelope paired with its non-empty directives array; nullopt when the string does not parse as an object, carries no directives key, or the array is empty — the no-side-effect case, which needs no dispatch. @req REQ-MCP-002
Version
2.0.2

Definition at line 1858 of file tool_executor.cpp.

◆ extract_parent_id()

static std::string entropic::extract_parent_id ( const nlohmann::json &  j)
static

Extract optional parent_conversation_id from JSON.

Parameters
jJSON object.
Returns
Conversation ID string, or empty if absent/null. @dg_internal
Version
1.9.5

Definition at line 24 of file audit_entry.cpp.

◆ extract_pipeline_stages()

static std::vector< std::string > entropic::extract_pipeline_stages ( const nlohmann::json &  result_json)
static

Extract directives from ServerResponse JSON and process them.

Parses the directives array from the raw tool result, constructs typed Directive objects, and passes them to the engine's DirectiveProcessor via the hooks callback.

Parameters
ctxLoop context (mutated by directive handlers).
raw_resultServerResponse JSON string. @dg_internal
Version
2.0.1

Extract pipeline stage names from a result JSON object.

Parameters
result_jsonParsed result JSON.
Returns
Stage tier names (empty if absent). @dg_internal
Version
2.0.2

Definition at line 1722 of file tool_executor.cpp.

◆ extract_system_prompt()

static std::string entropic::extract_system_prompt ( const std::vector< Message > &  messages)
static

Extract the first system message content from messages.

Parameters
messagesConversation messages.
Returns
System prompt text, or empty string if none found. @utility
Version
2.0.7

Definition at line 2116 of file engine.cpp.

◆ extract_text()

std::string entropic::extract_text ( const std::vector< ContentPart > &  parts)

Extract concatenated text from content parts.

Parameters
partsContent parts array.
Returns
All text parts joined with spaces, images skipped. @req REQ-TYPE-006
Version
1.9.11
Parameters
partsContent parts array.
Returns
All text parts joined with spaces, images skipped. Empty string if parts is empty or contains no text. @req REQ-TYPE-006
Version
1.9.11

Definition at line 20 of file content.cpp.

◆ extract_tier()

static std::string entropic::extract_tier ( const char *  json_str,
const std::string &  default_tier 
)
static

Extract tier name from params JSON, falling back to default.

Parameters
json_strParams JSON (may contain "tier" field).
default_tierFallback tier name.
Returns
Tier name. @utility
Version
2.0.1

Definition at line 146 of file interface_factory.cpp.

◆ fill_batch_cell()

static void entropic::fill_batch_cell ( llama_batch &  b,
int  k,
llama_token  tok,
llama_pos  pos,
llama_seq_id  seq,
bool  want_logits 
)
static

Fill one cell of a multi-seq llama_batch (defined below).

Fill one cell of a multi-seq llama_batch.

Forward-declared because gh#144 (v2.12.0) made the per-token decode path build explicit batches, and that path sits above the definition.

Parameters
bBatch to fill.
kCell index.
tokToken id.
posPosition within the sequence.
seqSequence id.
want_logitsWhether this cell should emit logits. @utility
Version
2.12.0

@utility

Version
2.8.0

Definition at line 2117 of file llama_cpp_backend.cpp.

◆ filter_json_by_key()

static std::string entropic::filter_json_by_key ( const std::string &  json_str,
const std::string &  key,
const std::string &  label,
nlohmann::json &  data 
)
static

Select one entry of a provider's JSON by key (object key or array element name).

Parameters
json_strRaw JSON string.
keyKey to extract.
labelLabel for the error message.
[out]dataThe selected entry.
Returns
"" when found, else the declared not_found error listing what is available. @dg_internal
Version
2.14.0

Definition at line 1195 of file entropic_server.cpp.

◆ final_answer_from_context()

static json entropic::final_answer_from_context ( entropic_handle_t  handle,
const std::string &  session_key 
)
static

Read the live conversation and render the operator-visible answer.

gh#130 (v2.10.2): shared by both ask paths so the answer-vs-diagnostic rule cannot drift between them.

gh#144 (v2.12.0): reads THIS session's conversation. The unscoped read it replaced would have extracted one caller's answer from whichever conversation the shared accessor happened to return.

Parameters
handleEngine handle.
session_keySession whose answer to render.
Returns
MCP tool result JSON. @req REQ-API-012 @req REQ-BRIDGE-001
Version
2.12.0

Definition at line 371 of file external_bridge.cpp.

◆ find_first_user_task()

static std::string entropic::find_first_user_task ( const std::vector< Message > &  messages)
static

Find the first user-role message that isn't a tool result.

Parameters
messagesMessage list.
Returns
Content of first real user message, or empty string. @utility
Version
2.0.4

Definition at line 337 of file compaction.cpp.

◆ find_list_end()

static auto entropic::find_list_end ( std::vector< std::string > &  lines,
size_t  list_start 
)
static

Find the end of a YAML sequence (last "- " item).

Parameters
linesFile lines.
list_startIndex of the list key line.
Returns
Iterator past the last sequence item. @utility
Version
1.8.8

Definition at line 117 of file permission_persister.cpp.

◆ find_section_end()

static auto entropic::find_section_end ( std::vector< std::string > &  lines,
std::vector< std::string >::iterator  start 
)
static

Find the end of a YAML section (indented block).

Parameters
linesFile lines.
section_startIterator to section key.
Returns
Iterator past the indented block. @utility
Version
1.8.8

Definition at line 139 of file permission_persister.cpp.

◆ find_tagged()

static std::string entropic::find_tagged ( const std::vector< Message > &  messages,
const std::string &  source 
)
static

Find the first message matching a source tag.

Parameters
messagesMessage list.
sourceSource metadata value to match.
Returns
Content of matching message, or empty string. @utility
Version
2.0.4

Definition at line 318 of file compaction.cpp.

◆ find_unique_args_match()

static std::string entropic::find_unique_args_match ( const nlohmann::json &  obj,
const nlohmann::json &  tools 
)
static

Find the unique tool whose required params are all present in obj.

Returns the tool name when exactly one tool in tools satisfies the constraint. Returns empty when zero or more than one tool matches (ambiguous) to avoid false-positive tool-call synthesis.

Parameters
objParsed arguments JSON object (no name/tool key).
toolsJSON array of MCP tool definitions.
Returns
Matched tool name, or empty string. @utility
Version
2.10.0

Definition at line 377 of file interface_factory.cpp.

◆ fire_context_assemble_hook()

static void entropic::fire_context_assemble_hook ( const HookInterface &  hooks,
const LoopContext &  ctx 
)
static

Build + fire the ON_CONTEXT_ASSEMBLE info hook.

Parameters
hooksHook interface.
ctxLoop context. @req REQ-HOOK-002
Version
2.3.7

Definition at line 102 of file engine.cpp.

◆ fire_hook_info()

static void entropic::fire_hook_info ( const HookInterface &  hooks,
entropic_hook_point_t  point,
const char *  json 
)
static

Fire an informational hook if the interface is wired.

Parameters
hooksHook interface.
pointHook point.
jsonContext JSON. @dg_internal
Version
1.9.1

Definition at line 38 of file engine.cpp.

◆ fire_loop_end_hook()

static void entropic::fire_loop_end_hook ( const HookInterface &  hooks,
const LoopContext &  ctx 
)
static

Build + fire the ON_LOOP_END info hook.

Parameters
hooksHook interface.
ctxLoop context. @req REQ-HOOK-002
Version
2.3.7

Definition at line 69 of file engine.cpp.

◆ fire_loop_iteration_hook()

static void entropic::fire_loop_iteration_hook ( const HookInterface &  hooks,
const LoopContext &  ctx 
)
static

Build + fire the ON_LOOP_ITERATION info hook.

Parameters
hooksHook interface.
ctxLoop context. @req REQ-HOOK-002
Version
2.3.7

Definition at line 85 of file engine.cpp.

◆ fire_loop_start_hook()

static void entropic::fire_loop_start_hook ( const HookInterface &  hooks,
const LoopContext &  ctx 
)
static

Build + fire the ON_LOOP_START info hook.

Parameters
hooksHook interface.
ctxLoop context. @req REQ-HOOK-002
Version
2.3.7

Definition at line 53 of file engine.cpp.

◆ flag_raised()

static bool entropic::flag_raised ( const std::atomic< bool > *  flag)
static

Whether a nullable stop flag is set (gh#158).

Parameters
flagFlag pointer; nullptr means "no such flag", never "stop".
Returns
true when the flag exists and is set. @utility
Version
2.13.0

Definition at line 475 of file response_generator.cpp.

◆ fold_delegation_summary()

static void entropic::fold_delegation_summary ( LoopContext &  ctx,
const std::string &  summary 
)
static

gh#119 (v2.9.17): fold child summary into the lead's empty delegate turn.

push_delegation_result appends [DELEGATION COMPLETE] as a user message. Intermediate executor result messages may sit between it and the lead's empty assistant turn. Searches backward for the last empty assistant message and sets its content to the summary text so extract_final_text (external_bridge) returns the child's answer, not "" → "(no response)". Extracted from finalize_delegation_result to keep ABC under the 20.0 gate.

Parameters
ctxLoop context (messages mutated in-place).
summaryChild delegation summary text. @req REQ-LOOP-007
Version
2.9.17

Definition at line 2742 of file engine.cpp.

◆ followup_results()

static std::string entropic::followup_results ( const char *  raw)
static

Wrap the provider's records in the declared {"results": [...]}.

v2.14.0 (gh#203): followup.json always promised this envelope; the tool passed the provider's output through verbatim — a bare array. Records are reduced to the four fields i_mcp_server.h declares.

Parameters
rawProvider JSON array, or nullptr.
Returns
{"results": [{delegation_id, target_tier, summary, completed_at}]}. @dg_internal
Version
2.14.0

Definition at line 1465 of file entropic_server.cpp.

◆ footprint_inputs_for()

static FootprintInputs entropic::footprint_inputs_for ( const TierConfig &  tier_cfg,
uint64_t  weights_bytes,
int  vram_reserve_mb 
)
static

Gather a tier's footprint inputs for the pure estimator.

Resolves the vision projector's size when the tier declares one — it is the allocation that actually aborted the process in gh#142 and the v2.2.4 estimate ignored it entirely.

Parameters
tier_cfgThe tier's configuration.
weights_bytesSize of the tier's GGUF on disk.
Returns
Inputs for estimate_vram_footprint. @dg_internal @req REQ-INFER-019
Version
2.13.1

Definition at line 2786 of file orchestrator.cpp.

◆ format_generation_summary()

std::string entropic::format_generation_summary ( const GenerationSummary &  s)
inline

Format the one-line generation summary.

Plain decode reads: "Generated: 87 tokens, finish=stop, 3040ms, 28.5 tok/s"

Speculative decode APPENDS the draft accounting, so an A/B between the two arms can be read off the same field in both: "Generated: 87 tokens, finish=stop, 3040ms, 28.5 tok/s, drafted=1396, accepted=906, accept_rate=0.649"

Parameters
sThe finished generation's numbers.
Returns
The formatted line, without a trailing newline. @utility
Version
2.12.2

Definition at line 69 of file generation_summary.h.

◆ format_tool_evidence_entry()

static std::string entropic::format_tool_evidence_entry ( const Message &  msg,
size_t  chars_per_result 
)
static

Format one tool-result message for the evidence block.

Parameters
msgTool-result message.
chars_per_resultPer-result truncation budget.
Returns
Formatted "## <tool> [iter N]\n<src|truncated>\n\n" entry. @utility
Version
2.3.7

Definition at line 2004 of file engine.cpp.

◆ generate_task_id()

static std::string entropic::generate_task_id ( )
static

Generate a simple UUID-like task ID.

Returns
Hex string (16 chars from random_device + pid). @utility
Version
2.0.11

Definition at line 786 of file external_bridge.cpp.

◆ generate_uuid()

std::string entropic::generate_uuid ( )

Generate a UUID v4 string.

Returns
UUID string (e.g., "550e8400-e29b-41d4-a716-446655440000"). @req REQ-STOR-003
Version
1.8.8
Returns
UUID string. @req REQ-STOR-003
Version
1.8.8

Definition at line 980 of file backend.cpp.

◆ generation_cancelled()

static bool entropic::generation_cancelled ( const GenerationEvents &  events)
static

Whether the generation in progress must stop (gh#158).

Two independent reasons, exactly as StdioTransport::request_cancelled has them, and for the same reason. events.interrupt is the HANDLE-WIDE flag — entropic_interrupt(), "stop everything". current_run_cancelled() is the token of the run decoding right now, which is what entropic_interrupt_session(key) sets.

Pre-2.13.0 this path consulted the handle flag ALONE, which is the gap the gh#158 audit found in its own first half: keying the run guard gave a session its own cancel token, ba48877 taught the agent loop and the MCP transports to poll it, and left the DECODE — the longest-running thing a session does — answering only to the handle-wide flag. A per-session interrupt therefore could not stop the generation it named.

Parameters
eventsInterrupt/pause flag pair (nullable fields tolerated).
Returns
true when this generation should cancel. @utility
Version
2.13.0

Definition at line 50 of file response_generator.cpp.

◆ get_applied_migrations()

static std::vector< std::string > entropic::get_applied_migrations ( sqlite3 *  db)
static

Get names of already-applied migrations.

Parameters
dbSQLite database handle.
Returns
Vector of applied migration names. @dg_internal
Version
1.8.8

Definition at line 392 of file database.cpp.

◆ gpu_offload_refused()

bool entropic::gpu_offload_refused ( uint64_t  file_bytes,
int  gpu_layers,
uint64_t  free_vram_bytes 
)
inline

Whether a requested GPU offload provably cannot fit free VRAM.

Fires only on the case the measurement settles WITHOUT knowing the model's layer count: free VRAM at or below the compute-buffer reserve means no positive gpu_layers can work, however the file divides into layers. That is the "died at buffer allocation" report.

It deliberately does NOT try to judge a specific partial split. Doing so needs the layer count, which is GGUF metadata the admission gate does not read, and guessing it wrong refuses configurations that work — the worse failure, and the same reason estimate_footprint_bytes reports a partially offloaded tier as unpriceable rather than inventing a number.

Floor-gated to LARGE models for the same reason as mlock_refused: a 500 MB model on a card with 1.5 GB free runs fine, and the 2 GiB reserve is sized for 13 GB models.

Parameters
file_bytesSize of the GGUF on disk.
gpu_layersConfigured offload (0 = CPU-only, exempt).
free_vram_bytesFree VRAM; 0 means unmeasured and never refuses.
Returns
true when the configuration should be REFUSED. @req REQ-INFER-019
Version
2.13.0

Definition at line 235 of file partial_offload.h.

◆ grammar_source_count()

constexpr int entropic::grammar_source_count ( )
inlineconstexpr

Number of declared grammar sources, sentinel excluded.

Reads the trailing count sentinel, so the value tracks the declaration automatically: appending a source above the sentinel changes this number and fails the invariant test, which is the tripwire's whole purpose.

Returns
The sentinel's integer value — the count of declared sources including none, excluding the sentinel itself. @req REQ-TYPE-004 @req REQ-INFER-008
Version
2.10.4

Definition at line 69 of file grammar_source.h.

◆ grammar_source_name()

const char * entropic::grammar_source_name ( GrammarSource  source)
inline

Stable wire name for a grammar source.

Parameters
sourceResolved source.
Returns
"none" | "request" | "tier" | "tool_call". Serialized into entropic_metrics_json, so these strings are a consumer contract. @req REQ-INFER-008
Version
2.13.0

Definition at line 161 of file grammar_source.h.

◆ grammar_sources_collide()

bool entropic::grammar_sources_collide ( const std::string &  request_grammar,
const std::string &  tool_grammar 
)
inline

Whether both sources are active — a config error worth reporting.

Parameters
request_grammarGenerationParams::grammar.
tool_grammarRender-derived tool-call GBNF.
Returns
true when both are non-empty — the caller logs the collision at ERROR at the application site; false otherwise. @req REQ-INFER-008
Version
2.10.4

Definition at line 182 of file grammar_source.h.

◆ grep_preflight()

static std::string entropic::grep_preflight ( const json &  args,
const fs::path &  start,
const fs::path &  root,
Page &  requested,
std::regex &  re 
)
static

Validate a grep call: paging, regex, and that path exists.

Parameters
argsTool arguments.
startResolved path argument.
rootProject root (for the message).
[out]requestedParsed page.
[out]reCompiled regex.
Returns
"" or the first declared error (invalid_args, invalid_regex, not_found). @dg_internal
Version
2.14.0

Definition at line 1852 of file filesystem.cpp.

◆ grep_search()

static void entropic::grep_search ( const fs::path &  root,
const fs::path &  start,
const std::vector< std::string > &  file_patterns,
const std::regex &  re,
const IgnoreMatcher &  ignore,
WalkBudget &  budget,
PagedResult &  page 
)
static

Execute grep: brace-expand the file glob, compile the content regex (error-safe), iterate the tree applying the same classify_glob_entry filter glob uses.

Issues #13/#15 (v2.1.4).

@dg_internal

Version
2.1.4

Walk start applying the glob/ignore filter and grep files.

Parameters
rootProject root (patterns and shown paths are relative to it).
startDirectory to walk (the root, or the path argument).
file_patternsBrace-expanded glob patterns.
reCompiled content regex.
ignoreIgnore matcher.
[in,out]budgetEntry budget (gh#161) — grep needs it MORE than glob does, since it also opens every matching file.
[in,out]pagePage being collected. @req REQ-MCP-022
Version
2.14.0

Definition at line 1795 of file filesystem.cpp.

◆ grep_target()

static void entropic::grep_target ( FilesystemServer &  server,
const fs::path &  start,
const json &  args,
const std::regex &  re,
WalkBudget &  budget,
PagedResult &  page 
)
static

Search start — one file, or a tree under the glob filter.

Parameters
serverOwning server (root, ignore rules).
startResolved path argument.
argsTool arguments (glob).
reCompiled regex.
[in,out]budgetWalk budget.
[in,out]pagePage being collected. @dg_internal
Version
2.14.0

Definition at line 1827 of file filesystem.cpp.

◆ guard_parent_conversation()

static bool entropic::guard_parent_conversation ( const std::string &  parent_conversation_id,
const std::string &  delegating_tier,
const std::string &  target_tier,
std::string &  delegation_id,
std::string &  child_conversation_id 
)
static

Reject an empty parent_conversation_id with a clear error and reset the out params (gh#48 defense-in-depth).

Pre-v2.1.12 an empty parent slipped through to the FK-bound INSERT and failed silently against conversations(id). The engine populates the root conversation at run() init; this guards against any caller bypassing that path.

Parameters
parent_conversation_idParent ID (must be non-empty).
delegating_tierDiagnostic context.
target_tierDiagnostic context.
[out]delegation_idCleared on rejection.
[out]child_conversation_idCleared on rejection.
Returns
true if the parent is valid; false (and out params cleared) if empty. @dg_internal
Version
2.1.12

Definition at line 619 of file backend.cpp.

◆ handle_ask()

static json entropic::handle_ask ( entropic_handle_t  handle,
const json &  args,
const std::string &  session_key,
int  client_fd,
const json &  progress_token 
)
static

Handle entropic.ask — stream tokens then return final text.

Uses entropic_run_streaming to send MCP progress notifications for each token (streaming to client), then extracts the final clean assistant text from the conversation for the tool result. Used when mcp.external.ask_streaming: true (the default).

Parameters
handleEngine handle.
argsTool arguments.
client_fdSocket fd for streaming progress notifications.
call_idJSON-RPC request id (for progress token correlation).
Returns
MCP tool result JSON (final clean text). @req REQ-API-012 @req REQ-BRIDGE-001
Version
2.10.2

Definition at line 480 of file external_bridge.cpp.

◆ handle_ask_plain()

static json entropic::handle_ask_plain ( entropic_handle_t  handle,
const json &  args,
const std::string &  session_key 
)
static

Handle entropic.ask — non-streaming path (gh#115, v2.9.12).

Routes through entropic_run (no on_token callback) so that MTP can engage without hitting the streaming-incompatibility guard. Also avoids the run_streaming dump-site 316 throw. Used when the bridge is configured with mcp.external.ask_streaming: false.

Parameters
handleEngine handle.
argsTool arguments (must contain "prompt" string).
Returns
MCP tool result JSON (final clean text from entropic_run). @req REQ-API-012 @req REQ-BRIDGE-001
Version
2.14.0

Definition at line 442 of file external_bridge.cpp.

◆ handle_clear()

static json entropic::handle_clear ( entropic_handle_t  handle,
ExternalBridge *  bridge,
const std::string &  session_key 
)
static

entropic.context_clear MCP tool handler.

Before clearing, cancels any in-flight async ask tasks so they do not continue running against a stale context. (P1-8, 2.0.6-rc16)

Parameters
handleEngine handle.
bridgeBridge instance (used to reach the task registry).
Returns
MCP tool result JSON. @req REQ-BRIDGE-001
Version
2.14.0

Definition at line 717 of file external_bridge.cpp.

◆ handle_count()

static json entropic::handle_count ( entropic_handle_t  handle,
const std::string &  session_key 
)
static

Handle entropic.context_count.

Parameters
handleEngine handle.
Returns
MCP tool result JSON. @req REQ-BRIDGE-001
Version
2.0.8

Definition at line 741 of file external_bridge.cpp.

◆ handle_release()

static json entropic::handle_release ( entropic_handle_t  handle)
static

release: unload every resident model, keep everything else.

v2.14.3: an MCP client could take the card (any ask) but not give it back; the only route was a signal to the host process. Same semantics as SIGUSR1 under entropic serve: entropic_release_model(h, NULL). A turn in flight is refused as a tool error — the C API refuses rather than waits, and so does this — so the caller knows to retry.

Parameters
handleEngine handle.
Returns
MCP tool result: what was released, "nothing was resident", or an isError result naming why not. @req REQ-BRIDGE-001 @req REQ-INFER-019
Version
2.14.3

Definition at line 1073 of file external_bridge.cpp.

◆ handle_status()

static json entropic::handle_status ( entropic_handle_t  handle,
const ExternalBridge *  bridge 
)
static

Handle the status tool.

gh#144 (v2.12.0) adds the occupancy lines. The issue's second half was that a caller queued behind another's turn is indistinguishable from one talking to a hung engine — on a 4B-class local model a review is 15-90 seconds, so a routine wait was presented as an indefinite one. busy and queue_depth are what make the difference visible.

Appended as text lines rather than restructured into JSON on purpose: the result is an unstructured blob with an embedded metrics: payload that consumers already parse, and changing its shape would break them.

Parameters
handleEngine handle.
bridgeBridge instance, for the turn-queue counters.
Returns
MCP tool result JSON. @req REQ-BRIDGE-001
Version
2.12.0-rc1

Definition at line 527 of file external_bridge.cpp.

◆ has_all_required()

static bool entropic::has_all_required ( const nlohmann::json &  args,
const std::vector< std::string > &  required,
const std::string &  call_name 
)
static

Verify every required key is present, warning on the first absent one.

Split out of one_call_satisfies_schema to stay under the 3-return gate.

Parameters
argsParsed argument object.
requiredDeclared required parameter names.
call_nameTool name, for the diagnostic.
Returns
false on the first missing key. @utility
Version
2.10.3

Definition at line 65 of file response_parse.cpp.

◆ has_blocked_prefix()

static bool entropic::has_blocked_prefix ( const std::string &  key)
static

Check if key matches a blocked prefix pattern.

Parameters
keyVariable name.
Returns
true if key starts with a blocked prefix. @utility
Version
1.8.8

Definition at line 312 of file mcp_json_discovery.cpp.

◆ has_images()

bool entropic::has_images ( const std::vector< ContentPart > &  parts)

Check if content parts contain any image parts.

Parameters
partsContent parts array.
Returns
true if at least one IMAGE part exists. @req REQ-TYPE-006
Version
1.9.11

Definition at line 41 of file content.cpp.

◆ host_can_hold_warm_load()

bool entropic::host_can_hold_warm_load ( uint64_t  file_bytes,
uint64_t  available_bytes,
uint64_t  headroom_bytes = 1024ull * 1024 * 1024 
)
inline

Whether the host can hold a model's WARM load.

The WARM state maps the ENTIRE GGUF into CPU RAM regardless of gpu_layers — measured at 12952 MiB for a 13.6 GB file — and only the ACTIVE reload honours the partial-offload split. So peak host usage is the whole file, not the CPU-side remainder, which is why a 12 GB model is marginal on a 31 GB box rather than comfortable.

Parameters
file_bytesSize of the GGUF on disk.
available_bytesHost MemAvailable right now. The requirement is NOT file_bytes plus a constant. The engine loads WARM (whole file in host RAM), then unloads and reloads for ACTIVE, and those two residencies can overlap — so peak approaches TWICE the file size. A first cut used file + 2 GB, did not fire at ~15 GB available for a 12.6 GB model, and the load died anyway at buffer allocation. Two data points also rule out a pure size rule: the DENSE 13.6 GB gemma-4-26B succeeds where the smaller 12.6 GB hybrid Qwen fails, because the recurrent state is additional.
headroom_bytesSlack beyond the doubled residency for context, compute buffers and the process itself.
Warning
BEST-EFFORT, and known to miss cases. The caller's usual source for available_bytes is /proc/meminfo MemAvailable, which counts RECLAIMABLE PAGE CACHE — and after a model suite has run, the model files themselves ARE that cache. So it can report ~20 GB available while satisfying a 20 GB allocation would require evicting exactly the cache it counted, and the load dies anyway. Observed doing precisely that: this predicate admitted a 12.6 GB hybrid model at a reported ~15-20 GB available and the load was killed at buffer allocation.

It is kept because it costs nothing and does fire on a genuinely loaded machine. It is NOT a guarantee, and a green suite does not mean the gate protected anything. A reliable check would need a pressure-based metric (PSI) rather than a free-memory estimate.

Returns
true when the load should be attempted. An unknown availability (0) returns true: refusing to run because we could not measure is worse than trying. @req REQ-INFER-019
Version
2.12.0

Definition at line 111 of file partial_offload.h.

◆ host_memlock_limit_bytes()

uint64_t entropic::host_memlock_limit_bytes ( )

This process's RLIMIT_MEMLOCK soft limit (gh#148).

This process's RLIMIT_MEMLOCK, in bytes (gh#148).

See header.

RLIM_INFINITY and an unreadable limit both map to kMemlockUnlimited: a gate that cannot measure must not refuse.

Returns
Soft limit in bytes, or kMemlockUnlimited. @req REQ-INFER-019
Version
2.13.0

The ceiling on what use_mlock can pin. Reported so the admission gate can REFUSE a configuration that would lock more than the limit allows rather than discovering it as an OOM kill — pinned pages cannot be reclaimed under pressure, which is what turned partial offload of a 13 GB model from slow into fatal (v2.12.0).

Returns
The soft limit in bytes, or kMemlockUnlimited when unlimited or unreadable — both mean "this gate has nothing to say". @req REQ-INFER-019
Version
2.13.0

Definition at line 69 of file device_memory.cpp.

◆ iface_complete()

static int entropic::iface_complete ( const char *  prompt,
const char *  params_json,
char **  result_json,
void *  user_data 
)
static

Raw text completion via orchestrator.

@callback

Version
2.0.1

Definition at line 292 of file interface_factory.cpp.

◆ iface_generate()

static int entropic::iface_generate ( const char *  msgs_json,
const char *  params_json,
char **  result_json,
void *  user_data 
)
static

Generate via orchestrator.

@callback

Version
2.0.1

Definition at line 174 of file interface_factory.cpp.

◆ iface_generate_stream()

static int entropic::iface_generate_stream ( const char *  msgs_json,
const char *  params_json,
void(*)(const char *, size_t, void *)  on_token,
void *  token_ud,
int *  cancel,
void *  user_data 
)
static

Streaming generate via orchestrator.

gh#81 (v2.4.2): bridges int* cancel (engine-side ABI) to std::atomic<bool> cancel_flag (backend contract) per-token inside the on_token lambda. Pre-fix the local atomic was initialized once from *cancel at entry and never re-read, so an interrupt raised mid-stream by the engine's per-token callback (stream_token_callback raising *cancel_flag = 1) never reached the backend's decode loop. The backend polls the atomic but the atomic stayed false.

@callback

Version
2.4.2

Definition at line 205 of file interface_factory.cpp.

◆ iface_generate_with_cancel()

static int entropic::iface_generate_with_cancel ( const char *  msgs_json,
const char *  params_json,
char **  result_json,
int *  cancel,
void *  user_data 
)
static

Batch generate with cancel via orchestrator (gh#81, v2.4.2).

Batch shape with mid-decode cancellation. The pre-v2.4.2 iface_generate accepted no cancel pointer and ran the backend to natural stop; this entry adds the cancel bridge using a small poller thread (no per-token hook in the batch contract).

@callback

Version
2.4.2

Definition at line 237 of file interface_factory.cpp.

◆ iface_is_complete()

static int entropic::iface_is_complete ( const char *  ,
const char *  tool_calls_json,
void *   
)
static

Check if response is complete (no pending tool calls).

@callback

Version
2.0.1

Definition at line 574 of file interface_factory.cpp.

◆ iface_parse_tool_calls()

static int entropic::iface_parse_tool_calls ( const char *  raw,
char **  cleaned,
char **  tool_calls_json,
void *  user_data 
)
static

Parse tool calls from raw model output (gh#87 3b).

gh#87 Phase D: parse via common_chat (parse_response) only when its format is multi-parameter safe (common_chat_parse_reliable — the dedicated PEG_GEMMA4 grammar). Autoparser families (Qwen, nemotron3) fall back to their hand-rolled multi-parameter adapter. Routed on the last-used tier's backend so a routed (non-default) tier parses correctly.

gh#122 (v2.9.18): when both paths yield 0 calls and the output contains exactly one fenced json block, try extracting a {name, arguments} call from it. Handles models that emit tool calls in markdown fence format.

gh#127 (v2.10.0): if gh#122 also returns empty and the fenced block is an args-only object (no name key), match against the staged tool schemas — synthesise the call when exactly one tool's required params are all present.

The agent-loop half of the shared template-first / adapter-second rule — this branch used to be a byte-for-byte duplicate of the orchestrator's, which is how gh#108's fix could land on one path and miss the other.

Parameters
rawRaw model output (may be NULL, treated as empty).
[out]cleanedNewly allocated cleaned content; caller frees.
[out]tool_calls_jsonNewly allocated JSON array of calls.
user_dataInterfaceContext carrying the orchestrator.
Returns
0 always — parse failure degrades to zero calls, never an error. @req REQ-INFER-010
Version
2.10.3

Definition at line 543 of file interface_factory.cpp.

◆ iface_route()

static int entropic::iface_route ( const char *  msgs_json,
char **  result_json,
void *  user_data 
)
static

Route messages to tier via orchestrator.

@callback

Version
2.0.1

Definition at line 278 of file interface_factory.cpp.

◆ initialize_result()

static json entropic::initialize_result ( const ExternalMCPConfig &  cfg)
static

Build the MCP initialize response payload.

gh#145 (v2.12.0): serverInfo.name comes from mcp.external.server_name (default "entropic"). This is the string a PERSON reads in their MCP server list, which is why it is configured separately from tool_prefix — the latter is what a MODEL reasons over. version remains the engine's own version: the host owns its identity, but must not misreport the engine behind it.

Parameters
cfgExternal MCP config supplying the server name.
Returns
JSON result object. @utility
Version
2.12.0

Definition at line 1737 of file external_bridge.cpp.

◆ insert_permission_item()

static bool entropic::insert_permission_item ( std::vector< std::string > &  lines,
std::string_view  pattern,
const std::string &  perms_key,
const std::string &  list_line,
const std::string &  item 
)
static

Insert a permission item into the parsed YAML lines.

Handles the three cases — missing permissions: block, missing allow/deny list, and existing list — mutating lines in place.

Parameters
linesParsed config lines (mutated).
patternPermission pattern (for the already-present check).
perms_keyThe "permissions:" key line.
list_lineThe " allow:"/" deny:" line.
itemThe " - <pattern>" item line.
Returns
true if item was inserted (write needed); false if the pattern was already present. @dg_internal
Version
2.3.7

Definition at line 185 of file permission_persister.cpp.

◆ inspect_filterable()

static std::string entropic::inspect_filterable ( char *(*)(void *)  fn,
void *  ud,
const std::string &  key,
const std::string &  label,
nlohmann::json &  data 
)
static

Inspect a filterable target (config/identity/tool).

Parameters
fnProvider callback returning JSON.
udProvider user_data.
keyFilter key (empty = full).
labelError message label.
[out]dataThe whole value, or the selected entry.
Returns
"" on success, else the declared not_found error. @dg_internal
Version
2.14.0

Definition at line 1225 of file entropic_server.cpp.

◆ is_applied()

static bool entropic::is_applied ( const std::vector< std::string > &  applied,
const char *  name 
)
static

Check if a migration name is in the applied list.

Parameters
appliedApplied migration names.
nameMigration name to check.
Returns
true if already applied. @dg_internal
Version
1.8.8

Definition at line 449 of file database.cpp.

◆ is_blocked_env_var()

bool entropic::is_blocked_env_var ( const std::string &  key)

Environment variable blocklist for .mcp.json env field.

Check if an environment variable is blocked.

These variables cannot be set via .mcp.json for security reasons (CWE-426 — untrusted search path, CWE-94 — code injection).

Parameters
keyEnvironment variable name.
Returns
true if the key is blocked.
Version
1.8.7

The blocklist covers the variables that could hijack the child process — loader-injection (LD_PRELOAD, LD_LIBRARY_PATH, the DYLD_ family), lookup redirection (PATH, HOME, SHELL) and the engine's own ENTROPIC_ namespace (CWE-426 / CWE-94).

Parameters
keyVariable name.
Returns
true for an exact blocklist match or a blocked prefix (ENTROPIC_, DYLD_); false for anything else, which is passed through to the child verbatim. @req REQ-MCP-025
Version
1.8.7

Definition at line 332 of file mcp_json_discovery.cpp.

◆ is_entropic_bridge()

bool entropic::is_entropic_bridge ( const ExternalServerConfig &  cfg)
inline

Whether a stdio entry runs entropic mcp-bridge.

Parameters
cfgServer config.
Returns
true for the engine's own bridge relay. @utility
Version
2.14.0

Definition at line 97 of file discovery_policy.h.

◆ is_pure_tool_call()

static bool entropic::is_pure_tool_call ( const std::string &  content)
static

Check if content is a pure tool call with no prose.

Tool-call-only outputs contain no prose claims that constitutional rules can evaluate. Validating them wastes inference and risks false non-compliance on XML syntax.

Parameters
contentContent with think blocks already stripped.
Returns
true if content is only whitespace and tool_call XML. @req REQ-VALID-001
Version
2.0.6

Definition at line 1097 of file constitutional_validator.cpp.

◆ is_request_grammar()

bool entropic::is_request_grammar ( GrammarSource  source)
inline

Whether a source is applied as a request-side grammar.

tier and request differ only in REPORTING — both arrive as GenerationParams::grammar and are applied as COMMON_GRAMMAR_TYPE_USER. The application site asks this rather than comparing against request alone, so naming a further request-side source cannot silently stop the grammar being applied.

Parameters
sourceResolved source.
Returns
true for request and tier. @req REQ-INFER-008
Version
2.13.0

Definition at line 121 of file grammar_source.h.

◆ is_safe_cwd()

static bool entropic::is_safe_cwd ( const std::string &  cwd)
static

Reject working_dir values that would smuggle shell syntax.

The bash tool's security model is operator approval (the engine's tool-call gate), not pattern matching against the command. But working_dir is concatenated into a shell cd clause, so any shell metacharacter in cwd would escape the approval surface (the operator approves command, not the constructed shell string). This check rejects the obvious smuggling vectors and requires the cwd be an existing directory.

Parameters
cwdCaller-supplied working directory string.
Returns
true only when cwd contains none of ;&|$<>`, newline, quotes, globs or brackets AND names an existing directory; false otherwise, which rejects the call before any shell runs. @req REQ-MCP-023
Version
2.1.1-rc1

Definition at line 61 of file bash.cpp.

◆ is_tool_result()

static bool entropic::is_tool_result ( const Message &  msg)
static

Extract original user task from messages.

Parameters
messagesMessages to search.
Returns
Task text (truncated to 500 chars). @dg_internal
Version
1.8.4

Check if a message is a tool result rather than a user task.

Parameters
msgMessage to check.
Returns
true if the message appears to be a tool result. @utility
Version
2.0.4

Definition at line 304 of file compaction.cpp.

◆ join_csv()

static std::string entropic::join_csv ( const std::vector< std::string > &  v)
static

Join a vector of strings with comma separators.

Parameters
vStrings to join.
Returns
CSV string. @utility
Version
2.9.18

Definition at line 4664 of file engine.cpp.

◆ join_lines()

static std::string entropic::join_lines ( const std::vector< std::string > &  lines)
static

Join lines back into a string with trailing newline.

Parameters
linesLines to join.
Returns
Joined string. @utility
Version
1.8.8

Definition at line 156 of file permission_persister.cpp.

◆ json_escape() [1/3]

static std::string entropic::json_escape ( const std::string &  input)
static

Save pre-compaction snapshot via storage interface.

Parameters
conversation_idConversation to snapshot.
messagesMessages before compaction. @dg_internal
Version
1.8.8

Escape a string for JSON embedding.

Parameters
inputRaw string.
Returns
JSON-safe escaped string. @utility
Version
1.8.8

Definition at line 478 of file compaction.cpp.

◆ json_escape() [2/3]

static std::string entropic::json_escape ( const std::string &  input)
static

Escape a string for JSON embedding.

Parameters
inputRaw string.
Returns
JSON-safe escaped string. @utility
Version
1.9.9

Definition at line 46 of file compactor_registry.cpp.

◆ json_escape() [3/3]

static std::string entropic::json_escape ( const std::string &  s)
static

Escape a string for JSON embedding.

Parameters
sRaw string.
Returns
JSON-safe string (without surrounding quotes). @utility
Version
1.9.8

Definition at line 926 of file constitutional_validator.cpp.

◆ json_escape_char()

static const char * entropic::json_escape_char ( char  c)
static

Map a character to its JSON escape sequence.

Parameters
cInput character.
Returns
Escape string, or empty if no escaping needed. @utility
Version
1.9.9

Definition at line 26 of file compactor_registry.cpp.

◆ json_escape_engine()

static std::string entropic::json_escape_engine ( const std::string &  s)
static

JSON-escape a string (no surrounding quotes).

Parameters
sRaw string.
Returns
Escaped string safe for JSON embedding. @utility
Version
2.0.7

Definition at line 1949 of file engine.cpp.

◆ json_escape_into()

static void entropic::json_escape_into ( const std::string &  s,
std::string &  out 
)
static

Serialize messages to JSON for inference interface.

Parameters
messagesMessage list.
Returns
JSON array string (minimal format). @dg_internal
Version
1.8.4

JSON-escape one string into a growing buffer. @dg_internal

Version
2.1.8

Definition at line 753 of file response_generator.cpp.

◆ json_escape_table()

static const std::array< const char *, 256 > & entropic::json_escape_table ( )
static

256-entry table mapping bytes to JSON escape sequences.

Non-null entries replace the input byte with the escape string. Null entries pass the byte through unchanged.

Returns
Reference to static lookup table. @utility
Version
2.0.7

Definition at line 1929 of file engine.cpp.

◆ json_extract_text_from_array()

static bool entropic::json_extract_text_from_array ( JsonCursor &  c,
std::string &  text 
)
static

Extract concatenated text from a JSON content array.

Scans for {"type":"text","text":"..."} objects within a content array and joins their text values. Skips image parts.

Parameters
cJSON cursor (positioned at opening '[').
[out]textExtracted text.
Returns
true on success. @utility
Version
1.9.11

Definition at line 342 of file compactor_registry.cpp.

◆ json_parse_array()

static bool entropic::json_parse_array ( JsonCursor &  c,
std::vector< Message > &  messages 
)
static

Parse message objects from a JSON array cursor.

Parameters
cJSON cursor (positioned after opening '[').
[out]messagesOutput message vector.
Returns
true on success. @utility
Version
1.9.9

Definition at line 425 of file compactor_registry.cpp.

◆ json_parse_content_part()

static bool entropic::json_parse_content_part ( JsonCursor &  c,
std::string &  type_val,
std::string &  text_val 
)
static

Parse one content part object, extract type and text.

Parameters
cJSON cursor (positioned after opening '{').
[out]type_valThe "type" field value.
[out]text_valThe "text" field value.
Returns
true on success (object fully consumed). @utility
Version
1.9.11

Definition at line 253 of file compactor_registry.cpp.

◆ json_parse_message()

static bool entropic::json_parse_message ( JsonCursor &  c,
Message &  msg 
)
static

Parse one JSON object into a Message (role + content).

Parameters
cJSON cursor (positioned after opening '{').
[out]msgOutput message.
Returns
true on success. @utility
Version
1.9.9

Definition at line 407 of file compactor_registry.cpp.

◆ json_read_content_part_field()

static bool entropic::json_read_content_part_field ( JsonCursor &  c,
std::string &  type_val,
std::string &  text_val 
)
static

Read one field of a content part object into type/text.

Parameters
cJSON cursor (positioned at key start).
[out]type_valPopulated if key == "type".
[out]text_valPopulated if key == "text".
Returns
true on success. @utility
Version
1.9.11

Definition at line 230 of file compactor_registry.cpp.

◆ json_read_field()

static bool entropic::json_read_field ( JsonCursor &  c,
Message &  msg 
)
static

Read one key:value pair and apply to message fields.

Handles both string content and array content (multimodal). For array content, extracts text parts only.

Parameters
cJSON cursor (positioned at key start).
[out]msgMessage to populate.
Returns
true on success. @utility
Version
1.9.11

Definition at line 372 of file compactor_registry.cpp.

◆ json_read_one_content_part()

static bool entropic::json_read_one_content_part ( JsonCursor &  c,
std::string &  text 
)
static

Parse one content part object and append text if applicable.

Parameters
cJSON cursor (positioned at '{').
[out]textAccumulated text output.
Returns
true on success. @utility
Version
1.9.11

Definition at line 320 of file compactor_registry.cpp.

◆ json_read_string()

static bool entropic::json_read_string ( JsonCursor &  c,
std::string &  out 
)
static

Read a JSON quoted string from cursor.

Parameters
cJSON cursor (positioned at or before opening quote).
[out]outDecoded string.
Returns
true on success. @utility
Version
1.9.9

Definition at line 151 of file compactor_registry.cpp.

◆ json_skip_composite()

static void entropic::json_skip_composite ( JsonCursor &  c)
static

Skip a JSON array or object in cursor (nested-aware).

Parameters
cJSON cursor (positioned at opening '[' or '{'). @utility
Version
1.9.11

Definition at line 177 of file compactor_registry.cpp.

◆ json_skip_to_element()

static char entropic::json_skip_to_element ( JsonCursor &  c)
static

Read one content part object from an array cursor.

Expects cursor at element start ('{' or ',' or ']'). Skips commas, parses the object, appends text to output if type=text.

Parameters
cJSON cursor.
[out]textAccumulated text.
Returns
1 = continue, 0 = array end reached, -1 = error. @utility
Version
1.9.11

Advance cursor past commas/whitespace to next element.

Parameters
cJSON cursor.
Returns
Character at next element, or '\0' if past end. @utility
Version
1.9.11

Definition at line 302 of file compactor_registry.cpp.

◆ json_skip_value()

static void entropic::json_skip_value ( JsonCursor &  c)
static

Skip one JSON value (string, primitive, array, or object).

Parameters
cJSON cursor. @utility
Version
1.9.11

Definition at line 201 of file compactor_registry.cpp.

◆ json_skip_ws()

static void entropic::json_skip_ws ( JsonCursor &  c)
static

Skip whitespace in a JSON cursor.

Parameters
cJSON cursor. @utility
Version
1.9.9

Definition at line 117 of file compactor_registry.cpp.

◆ json_unescape_char()

static char entropic::json_unescape_char ( char  ch)
static

Decode one JSON escape sequence character.

Parameters
chThe character after the backslash.
Returns
Decoded character. @utility
Version
1.9.9

Definition at line 130 of file compactor_registry.cpp.

◆ kv_bytes_per_token()

double entropic::kv_bytes_per_token ( const FootprintInputs &  in)
inline

Per-token KV cost in bytes for this tier's cache configuration.

Averages the key and value scales, which may differ — a tier may quantize one and not the other.

Parameters
inTier footprint inputs.
Returns
Bytes of KV cache per token of context. @req REQ-INFER-019
Version
2.11.0

Definition at line 205 of file vram_footprint.h.

◆ kv_scale_for_cache_type()

double entropic::kv_scale_for_cache_type ( const std::string &  type)
inline

Cost of a KV cache type relative to f16.

ggml packs 32 elements per quantized block, so the per-element cost is the block size over 32, expressed here against f16's 2 bytes/element. An unrecognised type is priced as f16 so the estimate never silently under-counts and lets through a load that will not fit.

Parameters
typeCache type string from the tier config ("f16", "q4_0", ...).
Returns
Multiplier against the f16 rate. @req REQ-INFER-019
Version
2.11.0

Definition at line 151 of file vram_footprint.h.

◆ large_model_tests_waived()

bool entropic::large_model_tests_waived ( uint64_t  file_bytes)
inline

Whether an operator has explicitly waived one LARGE model's test.

The MemAvailable predicate above is best-effort and documented as unreliable, which makes it a poor basis for a RELEASE record — the same commit skips or does not depending on page-cache state at that instant. ENTROPIC_SKIP_LARGE_MODEL_TESTS=1 records the decision explicitly, so results.json says the same thing on every run.

The size floor is HERE rather than at the call sites on purpose. A waiver that applies to every model is not an allowance, it is a mute button: set it once and a whole green suite means nothing. Both model-test load paths consult this one predicate, so neither can drift into that shape.

Deliberately opt-IN: unset, a capable host still attempts the load. This records an operator's decision; it does not make one.

Parameters
file_bytesSize of the GGUF on disk. A model at or below kLargeModelThresholdBytes is never waivable and returns false however the environment is set.
Returns
true only when the allowance is set AND the model is large. @req REQ-INFER-019
Version
2.12.0

Definition at line 150 of file partial_offload.h.

◆ last_substantive_assistant()

static std::string entropic::last_substantive_assistant ( const LoopContext &  ctx)
static

The last assistant message with something in it (gh#169).

"Substantive" is byte-level: any content that is not entirely whitespace. The loop has not yet pushed its cap message when this runs, so there is no engine-authored marker to filter out.

Parameters
ctxLoop context.
Returns
The content, or "" when the run produced none. @dg_internal
Version
2.13.0

Definition at line 610 of file engine.cpp.

◆ launches_own_bridge()

bool entropic::launches_own_bridge ( const ExternalServerConfig &  cfg,
const std::filesystem::path &  own_socket,
const std::filesystem::path &  spawn_root 
)
inline

Whether launching cfg would connect this handle to itself.

Mirrors entropic mcp-bridge's own resolution: --socket wins, else the socket derived from --project-dir, else from the cwd the child is given (cfg.working_dir, which ServerManager fills with its root).

Parameters
cfgServer config.
own_socketThe socket this handle's bridge binds; empty = no bridge.
spawn_rootRoot the child would run in when cfg.working_dir is empty.
Returns
true when it is our own bridge. @utility
Version
2.14.0

Definition at line 118 of file discovery_policy.h.

◆ list_available_keys()

static std::string entropic::list_available_keys ( const nlohmann::json &  j)
static

List available keys from a JSON value for error messages.

Parameters
jJSON object or array with "name" fields.
Returns
Comma-separated key list. @dg_internal
Version
1.9.12

Definition at line 1172 of file entropic_server.cpp.

◆ list_contains()

static bool entropic::list_contains ( const std::vector< std::string > &  lines,
size_t  start,
std::string_view  pattern 
)
static

Check if a YAML sequence already contains a pattern.

Parameters
linesFile lines.
startIndex of the list key line.
patternPattern to search for.
Returns
true if found. @utility
Version
1.8.8

Definition at line 96 of file permission_persister.cpp.

◆ list_page()

static void entropic::list_page ( const fs::path &  dir,
const json &  args,
Page  requested,
int  max_walk,
json &  result 
)
static

Collect one page of a directory listing into result.

Parameters
dirDirectory to list.
argsTool arguments (recursive, max_depth).
requestedRequested page.
max_walkWalk cap (filesystem.max_walk_entries).
[in,out]resultResult object (gets entries + ending). @dg_internal
Version
2.14.0

Definition at line 1959 of file filesystem.cpp.

◆ load_tool_definition()

ToolDefinition entropic::load_tool_definition ( const std::string &  tool_name,
const std::string &  server_prefix,
const std::string &  data_dir 
)

Load a tool definition from a JSON file.

Parameters
tool_nameTool name (e.g., "read_file").
server_prefixServer directory name (e.g., "filesystem").
data_dirBase directory for tool JSON files.
Returns
Parsed ToolDefinition.
Exceptions
std::runtime_errorif file not found or invalid. @utility
Version
1.8.5

Reads the bundled data/tools/<server>/<tool>.json descriptor, whose inputSchema (camelCase) is the schema ToolExecutor later validates arguments against.

Parameters
tool_nameTool name (e.g., "read_file").
server_prefixServer directory name (e.g., "filesystem"); an empty prefix reads directly from data_dir.
data_dirBase directory for tool JSON files.
Returns
Parsed ToolDefinition carrying name, description and the serialised inputSchema; when the descriptor declares an outputSchema (v2.14.0, gh#203) it is kept, and its rendered "Response format" section is appended to the description.
Exceptions
std::runtime_errorwhen the descriptor file cannot be opened; nlohmann parse errors propagate for malformed JSON or a missing name/inputSchema key. @req REQ-MCP-013
Version
2.14.0

Definition at line 297 of file tool_base.cpp.

◆ log_orchestration()

static void entropic::log_orchestration ( const GenerationResult &  result,
const std::string &  selected,
const std::string &  adapter_name,
const GenerationParams &  params,
double  routing_ms,
double  swap_ms 
)
static

Log the per-orchestration tier/adapter/timing summary.

Parameters
resultGeneration result (carries timings).
selectedSelected tier name.
adapter_nameAdapter that ran.
paramsResolved params (for grammar info).
routing_msRouting time.
swap_msModel-swap time. @utility
Version
2.3.7

Definition at line 770 of file orchestrator.cpp.

◆ log_other_message()

static void entropic::log_other_message ( size_t  i,
const Message &  msg,
entropic::PromptLogDedup &  dedup 
)
static

Log one non-system message, in full the first time only.

gh#152: this used to log every message in full on every turn. The list grows monotonically, so a message emitted at turn 5 was re-logged by turns 6, 7, 8 … and a reader counting model output by grepping the log over-counted by roughly the number of remaining turns. A consumer read 147 lines against 380 across two A/B arms and took it for one arm looping 2.6x more; it was re-emission, and the hunt landed in their code.

The system message has been elided this way since v2.0.6. Extending it to the roles that ACCUMULATE is what makes the log read as the transcript it was already being read as.

Parameters
iPosition in the message list.
msgThe message.
dedupPer-tier record of bodies already shown. @utility
Version
2.12.2

Definition at line 108 of file response_generator.cpp.

◆ log_prompt()

static void entropic::log_prompt ( const std::vector< Message > &  messages,
const std::string &  tier 
)
static

Log the assembled prompt, each distinct body in full exactly once.

A reader can count model output from this log without over-counting; set ENTROPIC_LOG_FULL_PROMPT=1 for the unabridged pre-gh#152 dump when diagnosing what the model actually saw.

Parameters
messagesMessage list being sent to inference.
tierLocked tier name. @utility
Version
2.12.2

Definition at line 131 of file response_generator.cpp.

◆ log_system_message()

static void entropic::log_system_message ( size_t  i,
const Message &  msg,
const std::string &  tier 
)
static

Log the system message, in full only when it has changed.

Tracks the system prompt hash per-tier so consecutive delegations to the same tier correctly detect content drift.

Parameters
iPosition in the message list.
msgThe system message.
tierLocked tier name. @utility
Version
2.12.2

Definition at line 74 of file response_generator.cpp.

◆ looks_like_mtp_head()

bool entropic::looks_like_mtp_head ( int  n_layer)
inline

True when the model's layer count is consistent with an MTP head GGUF.

A Gemma-4 MTP assistant head has 1–2 transformer layers. A classical draft model (Llama/Mistral small-variant) has at least 4. Used by try_speculative_route_streaming (gh#107) to fail loud when such a GGUF is supplied without setting speculative.mtp: true.

Parameters
n_layerLayer count from llama_model_n_layer.
Returns
True for 1–2 layers; false otherwise. A true result means the classical separate-draft path must refuse the config rather than crash in fattn.cu. @req REQ-INFER-015
Version
2.10.0

Definition at line 146 of file mtp_envelope.h.

◆ make_conversation()

ConversationRecord entropic::make_conversation ( const std::string &  title = "New Conversation",
const std::optional< std::string > &  project_path = std::nullopt,
const std::optional< std::string > &  model_id = std::nullopt 
)

Create a new ConversationRecord with generated UUID and timestamps.

Create a ConversationRecord with generated fields.

Parameters
titleConversation title.
project_pathProject path (optional).
model_idModel identifier (optional).
Returns
Populated record ready for INSERT. @req REQ-STOR-003
Version
1.8.8
Parameters
titleTitle.
project_pathOptional project path.
model_idOptional model ID.
Returns
Populated record. @req REQ-STOR-003
Version
1.8.8

Definition at line 1029 of file backend.cpp.

◆ make_default_draft_model_config()

ModelConfig entropic::make_default_draft_model_config ( )
inline

Speculative decoding configuration (v2.1.11, gh#36).

Off by default. When enabled is true and a draft_model is set, the engine loads the draft into the SecondaryModelLoader's "draft" slot at init and routes main-tier generation through LlamaCppBackend::do_generate_speculative.

Placement axis: draft_n_gpu_layers selects CPU (0), full GPU (-1), or hybrid partial offload (>0 and < model_layers). The default of 0 puts the draft on CPU so the GPU stays saturated on the verifier — minimal VRAM cost.

Version
2.1.11

Build the v2.1.11 default ModelConfig for a speculative draft model.

Differs from the standard tier defaults in three places that the kernel currently depends on:

  • gpu_layers = 0 — CPU-resident draft (zero VRAM on top of primary). Override to -1 for full GPU when VRAM allows.
  • flash_attn = false — required for partial seq_rm support on MoE / GQA architectures (the kernel rolls back draft KV after each speculative round). Override to true ONLY if your model
    • backend can do partial seq_rm with flash attn enabled.
  • context_length = 8192 — modest; speculative drafts are typically 4–32 tokens per round, no need for a wide window.
  • n_threads = 4 — works on most laptops; bump to match physical core count for higher CPU draft throughput.

Every other field comes from ModelConfig's standard defaults.

Returns
A ModelConfig carrying the draft-model default spec. @req REQ-TYPE-005
Version
2.1.11

Definition at line 1232 of file config.h.

◆ make_delegation()

DelegationRecord entropic::make_delegation ( const std::string &  parent_conversation_id,
const std::string &  child_conversation_id,
const std::string &  delegating_tier,
const std::string &  target_tier,
const std::string &  task 
)

Create a new DelegationRecord with generated UUID and timestamp.

Create a DelegationRecord with generated fields.

Parameters
parent_conversation_idParent conversation ID.
child_conversation_idChild conversation ID.
delegating_tierTier initiating delegation.
target_tierTarget tier for child loop.
taskTask description.
Returns
Populated record ready for INSERT. @req REQ-STOR-003 @req REQ-STOR-005
Version
1.8.8
Parameters
parent_conversation_idParent conversation.
child_conversation_idChild conversation.
delegating_tierSource tier.
target_tierTarget tier.
taskTask description.
Returns
Populated record. @req REQ-STOR-003 @req REQ-STOR-005
Version
1.8.8

Definition at line 1049 of file backend.cpp.

◆ make_generation_record()

GenerationRecord entropic::make_generation_record ( const GenerationResult &  r)
inline

Project a result down to the record kept for metrics.

Parameters
rCompleted generation result.
Returns
The metric fields, without content or tool calls. @utility
Version
2.13.0

Definition at line 173 of file generation_result.h.

◆ make_git_response()

static ServerResponse entropic::make_git_response ( const std::string &  output,
int  exit_code 
)
static

Format a git result as JSON ServerResponse.

The single response shape all eight git tools answer in.

Parameters
outputCombined stdout+stderr from the git process.
exit_codeProcess exit code.
Returns
A ServerResponse with no directives whose result is a JSON object carrying exit_code and output — git tools have no engine-level side effects. @req REQ-MCP-023 @req REQ-MCP-002
Version
1.8.5

Definition at line 80 of file git.cpp.

◆ make_residency_entry()

static nlohmann::json entropic::make_residency_entry ( const std::string &  name,
const std::filesystem::path &  path,
int  context_length,
size_t  footprint,
int  vram_reserve_mb,
long long  last_ms 
)
static

JSON serialization of the current residency set.

@dg_internal

Version
2.2.4

Build one residency-snapshot JSON entry.

Parameters
nameTier name.
pathModel file path.
context_lengthTier context length (for KV estimate).
footprintResolved footprint bytes.
vram_reserve_mbConfigured headroom reserve.
last_msLast activation time (ms).
Returns
JSON entry object. @utility
Version
2.3.7

Definition at line 2921 of file orchestrator.cpp.

◆ mark_tasks_cancelling()

static bool entropic::mark_tasks_cancelling ( ExternalBridge *  bridge,
const std::string &  session_key 
)
static

Mark one session's queued/running tasks as cancelling.

Parameters
bridgeBridge holding the task registry.
session_keySession whose tasks are cancelled (v2.14.0).
Returns
true if any task was still in-flight. @utility
Version
2.0.6-rc16

Definition at line 640 of file external_bridge.cpp.

◆ mcp_access_level_name()

const char * entropic::mcp_access_level_name ( MCPAccessLevel  level)

Convert MCPAccessLevel to string representation.

Parameters
levelAccess level.
Returns
Static string: "NONE", "READ", or "WRITE". @req REQ-TYPE-003
Version
1.9.4

Definition at line 21 of file config.cpp.

◆ mcp_tools_to_common_chat()

static std::vector< common_chat_tool > entropic::mcp_tools_to_common_chat ( const std::string &  tools_json)
static

Convert entropic MCP tool JSON to common_chat_tool defs (gh#87).

Reads ServerManager::list_tools() shape — an array of {name, description, inputSchema} — into common_chat_tool (name + description + parameters-schema-string). Tools without a name are skipped. Malformed JSON yields an empty list (the render then proceeds tool-less rather than throwing).

Parameters
tools_jsonMCP tool-list JSON array string.
Returns
Parsed common_chat tool definitions. @utility
Version
2.7.0

Definition at line 1367 of file llama_cpp_backend.cpp.

◆ mcpjson_config_verdict()

McpJsonConfigVerdict entropic::mcpjson_config_verdict ( const std::string &  name,
const MCPConfig &  cfg 
)
inline

Config's verdict on one discovered server.

Disabled beats enabled.

Parameters
nameServer name from .mcp.json.
cfgThe set's MCP config.
Returns
disabled, enabled, or ask. @utility
Version
2.14.0

Definition at line 63 of file discovery_policy.h.

◆ mlock_refused()

bool entropic::mlock_refused ( bool  use_mlock,
uint64_t  file_bytes,
int  gpu_layers,
uint64_t  memlock_limit_bytes,
uint64_t  host_expert_bytes = 0 
)
inline

Whether an explicit use_mlock would be fatal for this model.

Locking pages that exceed RLIMIT_MEMLOCK does not merely fail to optimise: llama.cpp locks what it can, up to the limit, and the pages it DID lock cannot be reclaimed under pressure. That is what turned partial offload of a 13 GB model from slow into OOM-killed (v2.12.0). The harness discovered this and flipped use_mlock off behind the operator's back; the engine says so instead.

Floor-gated to LARGE models on purpose. use_mlock DEFAULTS to true, so an un-floored rule would refuse the ordinary case of a CPU-resident 4 GB model on a box with the usual 8 MB limit — a configuration that works today (llama.cpp warns and continues) and that nobody asked to change. Only a model too large for the card in the first place reaches the pressure this predicate is about.

Parameters
use_mlockThe configured value.
file_bytesSize of the GGUF on disk.
gpu_layersConfigured offload; -1 (all) is exempt because the host side is then transient rather than resident.
memlock_limit_bytesRLIMIT_MEMLOCK, or kMemlockUnlimited.
Returns
true when the configuration should be REFUSED. @req REQ-INFER-019
Version
2.13.0

Definition at line 185 of file partial_offload.h.

◆ mtp_head_classical_path_error()

std::string entropic::mtp_head_classical_path_error ( int  n_layer)
inline

Actionable error message for gh#107: MTP head on classical path.

Called by try_speculative_route_streaming when looks_like_mtp_head is true and speculative.mtp is false. The message names the layer count and the corrective config knob.

Parameters
n_layerLayer count from llama_model_n_layer.
Returns
Actionable INCOMPATIBLE_CONFIG message naming both the layer count and the corrective speculative.mtp: true knob. @req REQ-INFER-015
Version
2.10.0

Definition at line 163 of file mtp_envelope.h.

◆ mtp_head_guard_fires()

static bool entropic::mtp_head_guard_fires ( LlamaCppBackend *  draft,
GenerationResult &  result 
)
static

gh#107: return true (and populate result) when draft looks like an MTP head GGUF routed to the classical separate-draft path.

An MTP head GGUF (1-2 layers) crashes in fattn.cu when the classical generate_speculative_with_draft path creates a separate KV context. Fail loud with INCOMPATIBLE_CONFIG instead of crashing.

Parameters
draftDraft LlamaCppBackend (model must be loaded for the check).
result[out] Populated on true return with SPECULATIVE_INCOMPATIBLE_CONFIG naming the layer count and the speculative.mtp: true knob.
Returns
True when the guard fires and result is populated; false otherwise. @req REQ-INFER-015
Version
2.10.0

Definition at line 452 of file orchestrator.cpp.

◆ mtp_unsupported_reason()

std::string entropic::mtp_unsupported_reason ( float  temperature,
bool  has_grammar,
bool  streaming 
)
inline

Reason MTP cannot run for a request, or "" when the envelope is safe.

temperature is no longer a guard (gh#108, v2.9.4): the draft proposal is a deterministic point mass (see the file-level doc comment), so the existing exact-match accept step is lossless at any temperature, not just 0.

streaming is no longer a guard (gh#108, v2.10.0): generate_streaming now wraps on_token with StreamThinkFilter for incremental thinking-channel stripping, resolving the post-buffer-only limitation that motivated the original v2.9.1 guard.

Parameters
temperatureEffective sampling temperature (unused; see v2.9.4 note).
has_grammarTrue when a GBNF grammar constraint is active (unused; see v2.10.0 grammar note — propagated via to_common_sampling).
streamingTrue when a per-token callback is bound (unused; see v2.10.0 streaming note above).
Returns
Actionable message when MTP is unsupported for the request, else "". Every former condition has been removed as its underlying gap was actually fixed, so the envelope is now fully open and this always returns "" — narrowing it again means reinstating a guard, never a silent fallback. @req REQ-INFER-015
Version
2.10.0 [reviewed]

Definition at line 123 of file mtp_envelope.h.

◆ names_diff()

static std::vector< std::string > entropic::names_diff ( const std::set< std::string > &  a,
const std::set< std::string > &  b 
)
static

Names in a not in b (sorted set difference).

Parameters
aSuperset candidate.
bSet to subtract.
Returns
a \ b as a vector. @utility
Version
2.3.7

Definition at line 251 of file external_client.cpp.

◆ no_args_tool()

static json entropic::no_args_tool ( const ExternalMCPConfig &  cfg,
const char *  suffix,
const char *  fallback 
)
static

Definition for a tool that takes no arguments.

gh#145 (v2.12.0): three of the five tools share an empty inputSchema, so they share a builder. Also keeps tool_definitions() inside the SLOC gate.

Parameters
cfgExternal MCP config supplying prefix and description overrides.
suffixBare tool suffix.
fallbackBuilt-in description.
Returns
One MCP tool definition object. @utility
Version
2.12.0

Definition at line 164 of file external_bridge.cpp.

◆ normalize_grammar_key()

static std::string entropic::normalize_grammar_key ( const std::string &  grammar_value)
static

Normalize a frontmatter grammar value to a registry key.

Strips .gbnf extension if present: "compactor.gbnf" → "compactor". Values without extension are used as-is.

Parameters
grammar_valueRaw frontmatter value.
Returns
Normalized registry key. @utility
Version
1.9.3

Definition at line 2453 of file orchestrator.cpp.

◆ now_seconds()

static double entropic::now_seconds ( )
static

Get current time as seconds since epoch.

Returns
Time in seconds (double). @dg_internal
Version
1.8.4

Definition at line 120 of file engine.cpp.

◆ one_call_satisfies_schema()

static bool entropic::one_call_satisfies_schema ( const ToolCall &  call,
const std::string &  tools_json 
)
static

Check one call's declared required parameters are all present.

Parameters
callParsed tool call.
tools_jsonStaged MCP tool defs.
Returns
false only when a declared required parameter is provably absent. @utility
Version
2.10.3

Definition at line 89 of file response_parse.cpp.

◆ overwrite_call_arguments()

static void entropic::overwrite_call_arguments ( ToolCall &  call,
const nlohmann::json &  args 
)
static

Replace a call's arguments from a validated args object.

gh#168. BOTH representations are rewritten: arguments_json (what serialize_args hands the server and the hooks) and the arguments map (what tool_call_key hashes for duplicate detection). Writing only one would let a rewritten call collide with the original in the dup cache. Non-string values are dumped, matching the convention interface_factory uses when it builds a ToolCall from model output.

Parameters
callTool call to rewrite.
argsThe payload's args object. @dg_internal
Version
2.13.0

Definition at line 1166 of file tool_executor.cpp.

◆ parse_logit_bias_into()

static void entropic::parse_logit_bias_into ( const nlohmann::json &  j,
std::unordered_map< int32_t, float > &  dst 
)
static

Populate logit_bias map from a JSON object of token→bias.

Accepts {"123": -100.0} shape — string keys parsed to int32_t. Skips un-parseable keys silently. @utility

Version
2.3.16

Definition at line 92 of file interface_factory.cpp.

◆ parse_mcp_access_level()

bool entropic::parse_mcp_access_level ( const std::string &  name,
MCPAccessLevel &  out 
)

Parse MCPAccessLevel from string.

Parameters
nameString: "NONE", "READ", or "WRITE" (case-sensitive).
[out]outParsed access level.
Returns
true if parsed successfully, false on unknown string. @req REQ-TYPE-003
Version
1.9.4
Parameters
nameString: "NONE", "READ", or "WRITE" (case-sensitive).
outParsed access level.
Returns
true if parsed successfully. @req REQ-TYPE-003
Version
1.9.4

Definition at line 35 of file config.cpp.

◆ parse_messages()

static bool entropic::parse_messages ( const char *  json,
std::vector< Message > &  messages 
)
static

Parse a JSON array of message objects.

Parameters
jsonJSON array string.
[out]messagesOutput message vector.
Returns
true on success, false on parse error. @utility
Version
1.9.9

Definition at line 451 of file compactor_registry.cpp.

◆ parse_messages_json()

std::vector< Message > entropic::parse_messages_json ( const char *  json_str)

Parse a JSON array of messages into a vector of Message.

Parse a messages-array JSON string into Message structs.

Accepts both string-content and content-array (multimodal) shapes. For multimodal messages, populates Message::content_parts and sets Message::content = extract_text(content_parts) so callers that read content directly continue to work.

Tolerant of missing fields:

  • Missing "role" defaults to "user".
  • Missing "content" yields an empty content string.
Parameters
json_strNull-terminated JSON array string.
Returns
Parsed messages. Empty vector if the array is empty.
Exceptions
nlohmann::json::parse_erroron malformed JSON. @req REQ-TYPE-006
Version
2.1.8
Parameters
json_strNull-terminated JSON. NULL or non-array yields empty.
Returns
Parsed messages (empty on null/non-array input). @req REQ-TYPE-006
Version
2.1.8

Definition at line 110 of file messages_json.cpp.

◆ parse_model_response()

ParsedModelResponse entropic::parse_model_response ( LlamaCppBackend *  llama,
ChatAdapter *  adapter,
const std::string &  raw 
)

Parse a raw emission: template first, adapter second.

The single shared rule, used by both the orchestrator's buffered result and the agent-loop tool parse — duplicating the branch is how gh#108 reached one path and not the other. Tool-call extraction is either/or (two call lists cannot be merged); content cleanup composes, so the adapter's reasoning strip ALWAYS runs over whichever branch produced the content, and is idempotent so no path can be missed.

Parameters
llamaBackend, or nullptr when not llama.cpp-backed.
adapterResolved chat adapter, or nullptr.
rawRaw model output.
Returns
Cleaned content plus tool calls, with used_template set when the template branch won; with no backend, no captured arena, or a schema-incomplete template parse, the adapter's calls instead — and the raw text as content when there is no adapter either. @req REQ-INFER-010
Version
2.10.3
Parameters
llamaBackend, or nullptr when not llama.cpp-backed.
adapterResolved chat adapter, or nullptr.
rawRaw model output.
Returns
Cleaned content plus tool calls.
Version
2.10.3

Definition at line 172 of file response_parse.cpp.

◆ parse_msgs()

static std::vector< Message > entropic::parse_msgs ( const char *  json_str)
static

Parse JSON message array into Message vector.

Parameters
json_strJSON array of {role, content} objects.
Returns
Parsed messages. @utility
Version
2.0.1

Definition at line 56 of file interface_factory.cpp.

◆ parse_params()

static GenerationParams entropic::parse_params ( const char *  json_str)
static

Parse generation params from JSON string.

Parameters
json_strJSON params (may be null).
Returns
GenerationParams with parsed overrides. @utility
Version
2.12.0

Definition at line 115 of file interface_factory.cpp.

◆ parse_recovered_tool_call()

static std::optional< ToolCall > entropic::parse_recovered_tool_call ( const std::string &  fixed)
static

Parse a brace/quote-fixed JSON string into a ToolCall.

Parameters
fixedCleaned JSON string (may still be invalid → throws).
Returns
ToolCall if it has a name (any alias), else nullopt. @utility
Version
2.3.8

Definition at line 472 of file adapter_base.cpp.

◆ parse_result_fields()

static void entropic::parse_result_fields ( const nlohmann::json &  result,
AuditEntry &  entry 
)
static

Parse the result sub-object from JSON into AuditEntry fields.

Parameters
resultJSON result object.
[out]entryEntry to populate. @dg_internal
Version
1.9.5

Definition at line 39 of file audit_entry.cpp.

◆ parse_tool_result_text()

static std::string entropic::parse_tool_result_text ( const std::string &  result_json)
static

Extract the "result" text from an MCP result JSON envelope.

Parameters
result_jsonRaw result string from the server.
Returns
The envelope's result field when the string parses as JSON carrying one; otherwise the raw string verbatim, so a server that answered off-contract still surfaces its text. @req REQ-MCP-002
Version
2.3.7

Definition at line 482 of file tool_executor.cpp.

◆ parse_via_adapter()

static void entropic::parse_via_adapter ( ModelOrchestrator *  orch,
const std::string &  raw,
const std::string &  tier,
std::string &  out_cleaned,
std::vector< ToolCall > &  out_calls 
)
static

Parse tool calls via the adapter for the given tier (gh#89).

gh#89: uses the SAME routed tier (last_used_tier) so a non-default autoparser tier parses with the correct adapter, not the default. Returns the raw content and empty calls when no adapter is registered.

Parameters
orchModel orchestrator (adapter lookup).
rawRaw model output.
tierActive tier name.
out_cleanedCleaned content (raw if no adapter).
out_callsParsed tool calls (empty if no adapter or 0 found). @utility
Version
2.9.18

Definition at line 502 of file interface_factory.cpp.

◆ partial_gpu_layers_for()

int entropic::partial_gpu_layers_for ( uint64_t  file_bytes,
uint64_t  free_vram_bytes,
int  n_layers = 30 
)
inline

Layers to place on the GPU for an oversized model.

Parameters
file_bytesSize of the GGUF on disk.
free_vram_bytesFree VRAM reported by the device right now.
n_layersTotal layers. ESTIMATE when the caller does not know it: the count is GGUF metadata this header will not read, and the two models that reach here have 30 and 40. The default is deliberately the LOW end, because overestimating n_layers understates per-layer cost and computes MORE layers than fit — the dangerous direction. Underestimating merely leaves GPU capacity unused. Pass the real value when it is known.
Returns
Layer count in [0, n_layers]; 0 when nothing fits. @req REQ-INFER-019
Version
2.12.0

Definition at line 53 of file partial_offload.h.

◆ partition_messages()

static void entropic::partition_messages ( const std::vector< Message > &  messages,
size_t  start,
std::vector< const Message * > &  user_msgs,
std::vector< const Message * > &  assistant_msgs,
int &  stripped_count 
)
static

Partition messages (from start) into user/assistant/stripped.

Parameters
messagesInput messages.
startFirst index to classify (skips system).
[out]user_msgssource==user messages.
[out]assistant_msgsassistant-role messages.
[out]stripped_countCount of dropped messages. @utility
Version
2.3.7

Definition at line 186 of file compaction.cpp.

◆ peer_uid_matches()

static bool entropic::peer_uid_matches ( int  client_fd)
static

Validate that the connecting peer shares the engine's UID.

Defense-in-depth against same-machine cross-user attempts that somehow reach the socket. Even with 0700 containing dir + 0600 socket, an SO_PEERCRED check is cheap and pins the trust boundary to "same uid only" explicitly rather than relying on file perms being correctly applied. v2.1.7 hardening (gh#34).

Parameters
client_fdNewly accepted client fd.
Returns
true if peer uid matches our euid. @req REQ-BRIDGE-001
Version
2.1.7

Definition at line 1424 of file external_bridge.cpp.

◆ phase_change_definition()

static ToolDefinition entropic::phase_change_definition ( )
static

The inline phase_change definition, contract included.

v2.14.0 (gh#203): carries an outputSchema like every bundled descriptor, and its Response format is rendered from it.

Returns
The definition. @dg_internal
Version
2.14.0

Definition at line 722 of file entropic_server.cpp.

◆ phase_observer_cb()

static void entropic::phase_observer_cb ( int  state,
void *  ud 
)
static

State observer that projects VERIFYING onto task phase.

@dg_internal

Version
2.1.0

Definition at line 1795 of file external_bridge.cpp.

◆ pipeline_context()

static std::string entropic::pipeline_context ( size_t  stage_idx,
size_t  total,
const std::vector< std::string > &  stages,
const std::string &  prior_output 
)
static

Build pipeline context prefix for a stage.

Issue #11 (v2.1.4): the optional prior_output argument carries the previous stage's result forward as part of the next stage's task message. Pre-2.1.4 each stage ran in isolation against the ORIGINAL task only — surprising for prompt authors who reasonably expected pipeline to mean "Unix-style chained pipeline" and caused the multi-stage flow (e.g. researcher → reader) to lose intermediate output. The intent was always forward-carry; the isolation behavior was a bug.

Parameters
stage_idxZero-based stage index.
totalTotal number of stages.
stagesStage tier names.
prior_outputPrevious stage's summary/result (empty for stage 0).
Returns
Context string prepended to the task. @req REQ-DELEG-004
Version
2.1.4

Definition at line 579 of file delegation.cpp.

◆ pipeline_rejection()

static std::string entropic::pipeline_rejection ( const std::vector< std::string > &  stages,
const std::vector< std::string > &  tier_names,
const std::vector< std::string > &  require_context_tiers,
size_t  refs 
)
static

Parse pipeline args, validate stages, emit directives.

gh#129 (v2.10.0): each stage is validated against tier_names_ before any directive is emitted. Unknown tier names are rejected with a plain error string naming the offending stage and the valid options.

Parameters
args_jsonJSON with "stages", "task" and optional "context" file references (gh#162).
Returns
On success, a ServerResponse echoing the stages with pipeline + stop_processing directives. On fewer than two stages, a stage naming a tier not in tier_names, or a stage that declares requires_context with none supplied (gh#162), an error string quoting the offending stage — with NO directives, so nothing is dispatched. @req REQ-MCP-024 @req REQ-DELEG-006
Version
2.13.0

Why this pipeline cannot run, or "" when it can (gh#129, gh#162).

Extracted from PipelineTool::execute to keep it under the knots ABC + returns gates when the context check joined the stage check. v2.14.0: each refusal is a declared error — too_few_stages, unknown_stage or requires_context.

Parameters
stagesRequested stage tiers.
tier_namesConfigured tiers.
require_context_tiersTiers that refuse a contextless run.
refsNumber of context references supplied.
Returns
Declared error JSON, or "" when the pipeline is valid. @utility @req REQ-MCP-024 @req REQ-DELEG-006
Version
2.14.0

Definition at line 512 of file entropic_server.cpp.

◆ placement_fits()

bool entropic::placement_fits ( const FootprintInputs &  base,
const GgufShape &  shape,
int  gpu_layers,
int  cpu_moe_layers,
uint64_t  budget_bytes,
uint64_t *  used 
)
inline

Does a candidate placement fit the budget?

Parameters
baseFootprint inputs describing everything except placement.
shapeThe model's GGUF shape.
gpu_layersCandidate layer count.
cpu_moe_layersCandidate expert-offload count.
budget_bytesVRAM the placement must fit inside.
[out]usedEstimated bytes for this candidate.
Returns
True when the estimate is known and within budget. @dg_internal
Version
2.13.1

Definition at line 159 of file auto_placement.h.

◆ plan_batch_kv()

BatchKvPlan entropic::plan_batch_kv ( std::size_t  n,
int  session_slots,
const std::vector< int > &  temp_ids 
)
inline

Plan the sequence ids a same-prefix batch may use.

Every arm — including the first — is given a sequence at or above session_slots, so no arm can land on a slot a session holds. Before gh#158 arm 0 was hardcoded to sequence 0, which is slot 0's session.

Parameters
nRequest count.
session_slotsSequences reserved for the session pool (PoolGeometry::temp_seq_base; 1 when no pool is configured).
temp_idsSequence ids minted by the backend's temp pool, in order.
Returns
The plan the batch must follow. @req REQ-INFER-018 @req REQ-LOOP-009
Version
2.13.0

Definition at line 69 of file batch_kv_util.h.

◆ plan_disturbs_sessions()

bool entropic::plan_disturbs_sessions ( const BatchKvPlan &  plan,
int  session_slots 
)
inline

Whether a plan can disturb any session's resident KV.

The property the gh#158 regression test asserts, stated once here so the test and any future caller ask the same question.

Parameters
planPlan to check.
session_slotsSequences reserved for the session pool.
Returns
true when the plan would clear the whole cache or write a sequence a session owns. @req REQ-LOOP-009
Version
2.13.0

Definition at line 100 of file batch_kv_util.h.

◆ populate_from_hook_context()

void entropic::populate_from_hook_context ( AuditEntry &  entry,
const AuditHookContext &  ctx 
)

Populate AuditEntry fields from AuditHookContext state.

Parameters
entryEntry to populate (caller_id, depth, iteration, parent_id, status).
ctxHook context with engine state pointers. @dg_internal
Version
1.9.5
Parameters
entryEntry to populate.
ctxHook context with engine state pointers. @dg_internal
Version
1.9.5

Definition at line 246 of file audit_logger.cpp.

◆ pre_mod_refusal()

static std::string entropic::pre_mod_refusal ( const nlohmann::json &  parsed,
const std::string &  tool_name 
)
static

Why a PRE_TOOL_CALL modification must be refused (gh#168).

Parameters
parsedParsed payload (any JSON type).
tool_nameName of the call being modified.
Returns
Empty when the payload is acceptable; otherwise the reason, phrased for the ERROR log a host operator has to act on. @dg_internal
Version
2.13.0

Definition at line 1136 of file tool_executor.cpp.

◆ pre_mod_renames_tool()

static bool entropic::pre_mod_renames_tool ( const nlohmann::json &  parsed,
const std::string &  tool_name 
)
static

Does a PRE_TOOL_CALL payload try to change the call's identity?

gh#168. Absent tool_name is fine — the hook simply did not restate it. Anything else must be the string the call already carries; a non-string value counts as an attempted rename, not as "absent".

Parameters
parsedParsed (object) payload.
tool_nameThe fully-qualified name of the call being made.
Returns
true when the payload names a different tool. @dg_internal
Version
2.13.0

Definition at line 1120 of file tool_executor.cpp.

◆ prepare_socket_dir()

static void entropic::prepare_socket_dir ( const std::filesystem::path &  parent)
static

Prepare the socket containing directory with 0700 perms.

Creates the parent directory if absent and ensures it is mode 0700 so only the engine owner can enumerate sockets. v2.1.7 hardening (gh#34): explicit perms rather than relying on umask.

Parameters
parentDirectory path. @req REQ-BRIDGE-001
Version
2.1.7

Definition at line 1318 of file external_bridge.cpp.

◆ prompt_log_reference()

std::string entropic::prompt_log_reference ( size_t  index,
const std::string &  role,
size_t  size_chars,
size_t  content_hash 
)
inline

The one-line stand-in for a body already shown earlier in the log.

Carries enough to reconstruct the sequence — role, size and hash — so a reader can still tell WHICH message occupies the slot and match it to its earlier full rendering.

Parameters
indexPosition in the message list.
roleMessage role.
size_charsBody length in characters.
content_hashHash of the body.
Returns
The reference line, without a trailing newline. @utility
Version
2.12.2

Definition at line 116 of file prompt_log_util.h.

◆ prompt_log_unabridged()

bool entropic::prompt_log_unabridged ( )
inline

Whether the operator has demanded unabridged prompt logs.

The full prompt is genuinely valuable when diagnosing what the model actually saw, so eliding it must never be the only option. ENTROPIC_LOG_FULL_PROMPT=1 restores the pre-gh#152 behaviour verbatim.

Returns
true when every message should be logged in full, every turn. @utility
Version
2.12.2

Definition at line 96 of file prompt_log_util.h.

◆ push_delegation_cycle_rejected()

static void entropic::push_delegation_cycle_rejected ( LoopContext &  ctx,
const std::string &  target 
)
static

Append a structured cycle-rejection message to the loop context so the model can recover.

Names the offending tier and the ancestor chain. (P1-9, 2.0.6-rc16)

Parameters
ctxLoop context.
targetTarget tier that would have closed the cycle. @req REQ-DELEG-001
Version
2.0.6-rc16

Definition at line 2466 of file engine.cpp.

◆ push_delegation_isolation_unsafe()

static void entropic::push_delegation_isolation_unsafe ( LoopContext &  ctx,
const std::string &  target,
const std::vector< std::string > &  tools 
)
static

Append the "isolation cannot be honoured" reject message (gh#160).

An external MCP server is a separate process with its own cwd; the engine cannot move it into the sandbox. If the child can call one that does not declare readOnlyHint: true, the containment the consumer asked for is not in force — so the delegation is refused LOUDLY rather than run with a guarantee that is quietly false (the fail-fast rule decision #66's audit settled on).

Parameters
ctxLoop context (message + failure metadata land here).
targetTarget tier name.
toolsOffending fully-qualified tool names. @req REQ-DELEG-001 @req REQ-DELEG-005
Version
2.13.0

Definition at line 2544 of file engine.cpp.

◆ push_delegation_rejected()

static void entropic::push_delegation_rejected ( LoopContext &  ctx)
static

Append a delegation rejection message to the loop context.

Parameters
ctxLoop context. @req REQ-DELEG-001
Version
2.0.2

Definition at line 2446 of file engine.cpp.

◆ push_delegation_repeat_blocked()

static void entropic::push_delegation_repeat_blocked ( LoopContext &  ctx,
const std::string &  target,
int  n 
)
static

Append a "stop retrying same target" reject message (gh#64).

Triggered when the lead emits a delegation to a target that has just failed max_consecutive_failed_delegations times in a row. The lead is told concretely what to do next: respond to the user or try a different target.

@req REQ-DELEG-001

Version
2.3.0

Definition at line 2513 of file engine.cpp.

◆ push_delegation_result()

static void entropic::push_delegation_result ( LoopContext &  ctx,
const std::string &  target,
const DelegationResult &  result 
)
static

Append a delegation result message to the loop context.

Parameters
ctxLoop context.
targetTarget tier name.
resultDelegation result. @req REQ-DELEG-002
Version
2.0.2

Definition at line 2493 of file engine.cpp.

◆ push_resume_failure()

static void entropic::push_resume_failure ( LoopContext &  ctx,
const std::string &  reason,
const std::string &  delegation_id 
)
static

Lazy session-scoped SandboxManager accessor (gh#33, v2.1.6).

See engine.h for rationale on why this is engine-scoped rather than per-delegation.

Returns
Pointer to engine-owned manager, or nullptr if no repo_dir. @dg_internal
Version
2.1.6

Build a typed failure message for resume_delegation errors. @req REQ-DELEG-002

Version
2.1.6

Definition at line 3158 of file engine.cpp.

◆ query_device_free_vram_bytes()

uint64_t entropic::query_device_free_vram_bytes ( )

Free VRAM on the first GPU device ggml reports, in bytes.

Returns 0 rather than guessing when no GPU device is registered — a CPU-only build or a machine with no usable GPU. The caller reads 0 as "budget unknown" and leaves the admission gate disabled, which is the correct behaviour for a CPU tier: there is no VRAM to run out of.

Returns
Free VRAM bytes, or 0 when unknown. @req REQ-INFER-019
Version
2.14.0
Returns
Free VRAM bytes, or 0 when there is no GPU device or the build has no GPU backend — 0 means "unknown" and leaves the budget gate disabled. @req REQ-INFER-019
Version
2.11.0

Definition at line 41 of file device_memory.cpp.

◆ read_and_track()

json entropic::read_and_track ( FilesystemServer &  server,
const fs::path &  resolved,
const std::string &  display,
const json &  args,
std::string &  err 
)

Read the requested window and record the read for the session.

Parameters
serverOwning server (budget, tracker).
resolvedFile to read (already gated).
displayPath as shown to the model.
argsTool arguments (offset, limit).
[out]errDeclared error, when the window is invalid or a line exceeds the budget.
Returns
The declared success object (meaningful only when err is ""). @dg_internal
Version
2.14.0

Definition at line 1442 of file filesystem.cpp.

◆ read_file()

static std::string entropic::read_file ( const std::filesystem::path &  path)
static

Read file contents as string.

Parameters
pathFile path.
Returns
File contents or empty string. @utility
Version
1.8.8

Definition at line 45 of file permission_persister.cpp.

◆ read_gguf_shape()

GgufShape entropic::read_gguf_shape ( const std::string &  path)

Read a GGUF's shape from its metadata, without loading tensor data.

Parameters
pathFilesystem path to the .gguf.
Returns
The shape; known == false when unreadable or architecture-less. @req REQ-INFER-019
Version
2.13.1

Opens with no_alloc = true, so the cost is the header plus the tensor index regardless of the file's size.

Parameters
pathFilesystem path to the .gguf.
Returns
The shape; known == false when the file cannot be read or declares no architecture. Never throws — a metadata read failing must degrade auto to its previous behaviour, not fail a load. @req REQ-INFER-019
Version
2.13.1

Definition at line 64 of file gguf_metadata.cpp.

◆ read_image_bytes()

static std::vector< uint8_t > entropic::read_image_bytes ( const std::filesystem::path &  path,
size_t  max_file_size 
)
static

Validate + read an image file fully into a byte buffer.

Parameters
pathFile path.
max_file_sizeReject files larger than this.
Returns
File bytes.
Exceptions
std::runtime_errorif missing, oversized, or unreadable. @utility
Version
2.3.7

Definition at line 146 of file image_preprocessor.cpp.

◆ read_line()

static std::string entropic::read_line ( int  fd)
static

Read one newline-delimited line from a socket fd.

Parameters
fdSocket file descriptor.
Returns
Line content, or empty on error/disconnect. @utility
Version
2.0.8

Definition at line 1679 of file external_bridge.cpp.

◆ read_window()

std::string entropic::read_window ( const json &  args,
long  budget,
ReadWindow &  w 
)

The window a read_file call asks for, validated.

Parameters
argsTool arguments.
budgetByte budget (max_read_bytes).
[out]wParsed window.
Returns
"" or a declared invalid_args error. @dg_internal
Version
2.14.0

Definition at line 1421 of file filesystem.cpp.

◆ recommend_context_length()

int entropic::recommend_context_length ( const FootprintInputs &  in,
uint64_t  available_bytes 
)
inline

Largest context length that fits, for the "won't fit" recommendation.

Returns a value the caller can actually act on rather than a bare refusal. Never inflates a request that already fits, and returns 0 when no context fits at all (the weights alone exceed the card) or when the placement is unpriceable — in both cases there is no honest number to offer.

Parameters
inTier footprint inputs, carrying the requested context length.
available_bytesVRAM actually available on the device.
Returns
A context length in tokens, rounded down to a 512 multiple, or 0. @req REQ-INFER-019
Version
2.12.0

Definition at line 284 of file vram_footprint.h.

◆ record_to_json()

static nlohmann::json entropic::record_to_json ( const ToolCallRecord &  rec)
static

Serialize a single ToolCallRecord to JSON.

Parameters
recRecord to serialize.
Returns
JSON object with sequence, tool_name, params_summary, status, result_summary, elapsed_ms and iteration always present, plus error_detail only when the record carries one. @req REQ-MCP-020
Version
1.9.12

Definition at line 120 of file tool_call_history.cpp.

◆ recover_action_envelope_calls()

std::vector< ToolCall > entropic::recover_action_envelope_calls ( const std::string &  raw)

gh#88: recover tool calls a gemma model parroted as bare-JSON.

gh#88 bare-JSON recovery — see header for the full rationale.

common_chat (PEG_GEMMA4) parses only the native call-prefix form. When a session primes the model with {"action":"x",...} meta-tool result envelopes (see the engine defang), the model echoes that bare-JSON shape and the dedicated grammar yields nothing. This permissive fallback (parity with the retired Gemma4Adapter) maps a {"action":"<tool>",...} envelope to the entropic.<tool> call (remaining fields as arguments), and also accepts a plain {"name":...} object.

Parameters
rawRaw assistant output.
Returns
Recovered tool calls (empty when none match).
Version
2.7.1
Parameters
rawRaw assistant output.
Returns
Recovered tool calls; empty when no line parses as a {"action": …} envelope naming a real meta-tool. @req REQ-INFER-012
Version
2.7.1

Definition at line 297 of file adapter_base.cpp.

◆ regex_recovered_tool_call()

static std::optional< ToolCall > entropic::regex_recovered_tool_call ( const std::string &  json_str)
static

Last-ditch recovery: pull a tool name out via regex.

Parameters
json_strOriginal (possibly unparseable) string.
Returns
ToolCall with just id+name, or nullopt if no name found. @utility
Version
2.3.7

Definition at line 485 of file adapter_base.cpp.

◆ release_session_tool_state()

std::size_t entropic::release_session_tool_state ( entropic_handle_t  h,
const std::string &  key 
)

Release a session's per-session tool state on every server set (gh#158).

Release a session's per-session tool state — see engine_handle.h.

The filesystem server's read-before-write tracker and the entropic server's todo list are kept per SESSION. Called when that session's conversation ends — entropic_session_drop, _context_clear, _context_set, and entropic_context_clear for the active session — so a long-running host does not accumulate one entry per session it ever served. Visits the default set AND every workspace's: which set a session touched depends on when it was bound, and releasing an absent key is free.

Parameters
hEngine handle.
keySession key ("" = the default session).
Returns
Number of servers that held state for key. @req REQ-LOOP-009
Version
2.13.0

Lock order: the caller holds api_mutex; workspace_mutex is taken here, and under it only each server's leaf per-session lock. No run thread takes workspace_mutex while holding a per-session lock, so the order cannot invert. The ToolRootLock is deliberately NOT taken (see ServerManager::release_session).

Parameters
hEngine handle.
keySession key ("" = the default session).
Returns
Number of servers that held state for key. @req REQ-LOOP-009
Version
2.13.0

Definition at line 315 of file entropic_mcp.cpp.

◆ remove_anchor_messages()

static void entropic::remove_anchor_messages ( LoopContext &  ctx,
const std::string &  key 
)
static

Remove messages with a specific anchor key.

Parameters
ctxLoop context.
keyAnchor key to remove. @req REQ-COMPACT-002
Version
1.8.4

Definition at line 1882 of file engine.cpp.

◆ render_common_chat()

static std::optional< common_chat_params > entropic::render_common_chat ( llama_model *  model,
const std::vector< Message > &  messages,
const GenerationParams &  params,
const std::vector< common_chat_tool > &  tools,
bool  require_tool_call 
)
static

Shared common_chat render core for both template paths (gh#87).

Builds common_chat_templates_inputs (jinja, generation prompt, enable_thinking, optional tools) and applies the model's template. Returns the full common_chat_params so callers can use .prompt and — for the tools path — capture .format/.generation_prompt/ .parser for a later parse. Returns nullopt when the model isn't loaded, the template can't init, or apply throws (caller falls back to the low-level path).

Parameters
modelLoaded model (may be null → nullopt).
messagesConversation history.
paramsGeneration parameters (enable_thinking honored).
toolsTool defs for inputs.tools (empty for the legacy path).
require_tool_callTier's mandatory-tool flag; selects COMMON_CHAT_TOOL_CHOICE_REQUIRED (which makes upstream derive the tool-call grammar eagerly) over AUTO.
Returns
Rendered params carrying .prompt plus, on the tools path, the .format / .generation_prompt / .parser / .grammar the later parse and sampler need; nullopt when the model is unloaded, the template cannot init, or apply throws. @req REQ-INFER-009
Version
2.10.4

Definition at line 1437 of file llama_cpp_backend.cpp.

◆ render_response_format()

std::string entropic::render_response_format ( const std::string &  output_schema_json)

Render an outputSchema as the compact "Response format" text a model reads (gh#203).

Render an outputSchema as the "Response format" text (gh#203).

Every shape, key, optional marker ("key"?), enumerated error code and field description in the schema appears in the text; nothing else does.

Parameters
output_schema_jsonJSON Schema (raw string).
Returns
The rendered section (leading blank line included), or "" for an empty or unparseable schema. @utility
Version
2.14.0

Generated rather than hand-written so the prose a model reads cannot drift from the schema the contract tests hold handlers to — the defect class gh#120 → gh#201 showed.

Parameters
output_schema_jsonJSON Schema (raw string).
Returns
The rendered section, or "" for an empty/unparseable schema. @utility @req REQ-MCP-013
Version
2.14.0

Definition at line 244 of file tool_base.cpp.

◆ required_params()

static std::vector< std::string > entropic::required_params ( const std::string &  tools_json,
const std::string &  name,
bool &  found 
)
static

Required parameter names declared by a tool's inputSchema.

Parameters
tools_jsonStaged MCP tool defs.
nameTool name to look up.
[out]foundSet false when the tool is not in the staged set.
Returns
Required parameter names (empty when none/unknown). @utility
Version
2.10.3

Definition at line 31 of file response_parse.cpp.

◆ resident_tiers()

static std::string entropic::resident_tiers ( entropic_handle_t  handle)
static

Names of the models resident right now, from the snapshot.

Parameters
handleEngine handle.
Returns
Tier names, comma-separated; "" when nothing is resident. @utility
Version
2.14.3

Definition at line 1042 of file external_bridge.cpp.

◆ resolve_grammar_source()

GrammarSource entropic::resolve_grammar_source ( const std::string &  request_grammar,
const std::string &  tool_grammar,
bool  request_from_tier = false 
)
inline

Resolve which grammar wins.

The request grammar takes precedence: it is an explicit caller instruction, whereas the tool-call grammar is implied by staging tools. A caller that supplies both has a config error — the collision is logged loudly at the application site rather than silently resolved, because the losing constraint's absence would otherwise be undiagnosable.

Parameters
request_grammarGenerationParams::grammar.
tool_grammarRender-derived tool-call GBNF.
request_from_tiertrue when the request-side text came from the tier's frontmatter grammar: stem rather than from the caller (gh#154). Reporting-only: the two are applied identically.
Returns
GrammarSource::request / tier when a request-side grammar is present, GrammarSource::tool_call when only the render-derived grammar is, GrammarSource::none when neither is. @req REQ-INFER-008 @req REQ-TYPE-004
Version
2.13.0

Definition at line 94 of file grammar_source.h.

◆ resolve_stream_finish_reason()

static std::string entropic::resolve_stream_finish_reason ( int  rc,
size_t  content_size 
)
static

Resolve a stream's finish_reason from rc + content size.

gh#20 (v2.1.5) resolution order: CANCELLED → "interrupted"; EVAL_CONTEXT_FULL → "context_overflow"; error with partial content → "partial"; error with none → "error"; clean → "stop".

v2.13.0: the overflow refusal is given its OWN reason rather than folded into "error". "error" is not terminal for the loop — it falls through to the empty-turn ladder, which appends a correction message and retries a prompt that was already too big. Retrying it makes it bigger.

Parameters
rcBackend return code.
content_sizeAccumulated content length.
Returns
finish_reason string. @utility
Version
2.13.0

Definition at line 368 of file response_generator.cpp.

◆ resolve_target_model()

static llama_model * entropic::resolve_target_model ( const std::shared_ptr< InferenceBackend > &  tier_backend)
static

Resolve the active main-tier llama_model* for compat lookup.

Returns
Pointer to the loaded llama_model, or nullptr when no main tier is loaded or the backend is not LlamaCppBackend. @dg_internal
Version
2.1.11

Definition at line 2294 of file orchestrator.cpp.

◆ resolve_workspace()

static std::string entropic::resolve_workspace ( entropic_handle_t  handle,
const std::string &  workspace,
std::string &  err 
)
static

Resolve workspace to a workspace name, creating one for a path.

An absolute directory names the repository the caller is in; its canonical path IS the workspace name, so every client in that repository lands in the same workspace. Creating one no longer spawns the repository's .mcp.json (gh#199), and the caller is already an authenticated same-user client, so a path is safe to act on. Anything else must name a workspace the host created.

Parameters
handleEngine handle.
workspacePath or name from the ask arguments.
[out]errSet on failure.
Returns
Workspace name, or "" with err set. @dg_internal
Version
2.14.0

Definition at line 909 of file external_bridge.cpp.

◆ result_kind_to_string()

const char * entropic::result_kind_to_string ( ToolResultKind  kind)
inline

Serialize a ToolResultKind to its wire-stable string form.

Parameters
kindEnum value.
Returns
Static null-terminated string. Never NULL. @req REQ-TYPE-003
Version
2.5.2

Definition at line 51 of file tool_result.h.

◆ rpc_err()

static std::string entropic::rpc_err ( const json &  id,
int  code,
const std::string &  msg 
)
static

Build a JSON-RPC error response.

Parameters
idRequest ID.
codeError code.
msgError message.
Returns
Serialized JSON-RPC response. @utility
Version
2.0.8

Definition at line 87 of file external_bridge.cpp.

◆ rpc_ok()

static std::string entropic::rpc_ok ( const json &  id,
const json &  result 
)
static

Build a JSON-RPC success response.

Parameters
idRequest ID.
resultResult payload.
Returns
Serialized JSON-RPC response. @utility
Version
2.0.8

Definition at line 73 of file external_bridge.cpp.

◆ run_child_loop_trampoline()

static void entropic::run_child_loop_trampoline ( LoopContext &  ctx,
void *  user_data 
)
static

Trampoline for DelegationManager to call engine loop.

Parameters
ctxChild loop context.
user_dataAgentEngine pointer. @dg_internal
Version
2.4.3

Definition at line 2433 of file engine.cpp.

◆ run_git()

static std::pair< std::string, int > entropic::run_git ( const std::string &  repo_dir,
const std::string &  git_args 
)
static

Run a git command in a given directory via popen.

The shared execution path behind all eight git tools: every one is git -C <repo root> ..., so no tool can operate outside the repo the server was pointed at, and none carries its own command gating — operator approval is the gate.

Parameters
repo_dirRepository root directory.
git_argsArguments appended after "git -C repo_dir".
Returns
The combined stdout+stderr text paired with the process exit code; ("Failed to open git process", -1) when the pipe could not be opened. @req REQ-MCP-023
Version
2.0.0

Definition at line 41 of file git.cpp.

◆ run_plain_turn()

static entropic_error_t entropic::run_plain_turn ( entropic_handle_t  handle,
const std::string &  session_key,
const std::string &  tier,
const std::string &  prompt,
char **  result_json 
)
static

Run one non-streaming turn, under tier when one is given (gh#205).

Parameters
handleEngine handle.
session_keySession key.
tierTier or identity; "" routes as usual.
promptUser prompt.
[out]result_jsonSerialized result (free with entropic_free).
Returns
The run's error code. @utility
Version
2.14.0

Definition at line 391 of file external_bridge.cpp.

◆ run_stream_turn()

static entropic_error_t entropic::run_stream_turn ( entropic_handle_t  handle,
const std::string &  session_key,
const std::string &  tier,
const std::string &  prompt,
void(*)(const char *, size_t, void *)  on_token,
void *  ud 
)
static

Run one streaming turn, under tier when one is given (gh#205).

Parameters
handleEngine handle.
session_keySession key.
tierTier or identity; "" routes as usual.
promptUser prompt.
on_tokenToken callback.
udForwarded to on_token.
Returns
The run's error code. @utility
Version
2.14.0

Definition at line 415 of file external_bridge.cpp.

◆ s_name_regex()

static const std::regex entropic::s_name_regex ( "^{0,63}$"  [a-z][a-z0-9_-])
static

Compiled regex for identity name validation.

@dg_internal

Version
1.9.6

◆ sanitize_display_name()

static std::string entropic::sanitize_display_name ( const std::string &  raw)
static

Sanitize a display_name for use as a log-line bracket label.

Rich-based TUI consumers (and any markdown renderer) interpret substrings of the shape [/foo] as BBCode close tags and strip surrounding markup. A registered server name that started with / (e.g. by accident or by a path-like identifier) would therefore corrupt the consumer's terminal output. We also strip [, ], and control characters that could confuse downstream loggers. Falls back to "server" if the input sanitizes to empty.

Parameters
rawCaller-supplied display name (or command for fallback).
Returns
The name with any leading slash, all brackets and all control characters removed — safe to embed in [<name>] log/UI markup; the literal "server" when sanitizing leaves nothing. @req REQ-MCP-025
Version
2.1.5

Definition at line 64 of file transport_stdio.cpp.

◆ send_nonblocking()

static bool entropic::send_nonblocking ( int  fd,
const std::string &  payload 
)
static

One non-blocking write of a whole payload to one fd.

EAGAIN / EWOULDBLOCK (a slow consumer's full buffer), EBADF / EPIPE / ECONNRESET (a dead peer) and a partial write all collapse to "drop" — the long-term per-subscriber queue lives in proposal P2-20260429-001.

Parameters
fdDestination.
payloadBytes to write.
Returns
true when every byte was written. @utility
Version
2.14.0

Definition at line 2112 of file external_bridge.cpp.

◆ send_progress()

static void entropic::send_progress ( int  fd,
const std::string &  token_text,
const json &  progress_token,
uint64_t  seq 
)
static

Send an MCP progress notification with a text token.

Parameters
fdClient socket fd.
token_textToken string to send (carried in message).
progress_tokenThe caller's _meta.progressToken, else the request id (pre-2.14.0 behaviour, kept for clients that never send one).
seqMonotonic notification count (MCP's numeric progress). @utility
Version
2.0.10

Definition at line 337 of file external_bridge.cpp.

◆ sentinel_suffix_for_status()

static const char * entropic::sentinel_suffix_for_status ( const std::string &  status)
static

Map a terminal status string to a sentinel filename suffix.

@dg_internal

Version
2.1.4

Definition at line 2266 of file external_bridge.cpp.

◆ serialize_config()

static std::string entropic::serialize_config ( const CompactionConfig &  config,
const std::string &  identity,
int  token_count 
)
static

Serialize compaction config + identity to JSON.

Parameters
configCompaction config.
identityIdentity name.
token_countCurrent token count (0 if unknown).
Returns
JSON object string. @utility
Version
1.9.9

Definition at line 86 of file compactor_registry.cpp.

◆ serialize_content_parts()

static void entropic::serialize_content_parts ( const std::vector< ContentPart > &  parts,
std::string &  out 
)
static

Serialize a single multimodal content_parts array (gh#37, v2.1.8).

Emits [{"type":"text","text":"..."}, {"type":"image","path":"..."}] directly — keeps core free of nlohmann/json (design rule #21).

@dg_internal

Version
2.1.8

Definition at line 775 of file response_generator.cpp.

◆ serialize_messages()

static std::string entropic::serialize_messages ( const std::vector< Message > &  messages)
static

Serialize messages to minimal JSON array.

Parameters
messagesMessages to serialize.
Returns
JSON array string. @utility
Version
1.9.9

Definition at line 63 of file compactor_registry.cpp.

◆ serialize_messages_json()

static std::string entropic::serialize_messages_json ( const std::vector< Message > &  messages)
static

Serialize messages to minimal JSON array.

Parameters
messagesMessages to serialize.
Returns
JSON array string. @utility
Version
1.8.8

Definition at line 496 of file compaction.cpp.

◆ serialize_tool_calls()

std::string entropic::serialize_tool_calls ( const std::vector< ToolCall > &  calls)
inline

Serialize parsed tool calls to the C-ABI JSON array form.

Each argument value is parsed into its natural JSON type when it is valid JSON (number, bool, array, object, null); otherwise it is emitted as a JSON string. This mirrors what consumers receive across the .so boundary.

gh#118 (v2.9.16): XML-parsed argument strings carry raw model bytes; MTP-split codepoints cause nlohmann::json::dump() to throw type_error.316 INSIDE the inference_.parse_tool_calls callback, before the engine's mcp::sanitize_utf8 guard at parse_tool_calls:1386 can run. Dump with error_handler_t::replace to substitute U+FFFD for any invalid byte sequences — consistent with the sanitize_utf8 policy used at all other inbound UTF-8 boundaries.

Parameters
callsTool calls (from common_chat or a legacy adapter).
Returns
JSON array: [{name, arguments}, ...]. @utility
Version
2.9.16

Definition at line 47 of file tool_call_serialize.h.

◆ session_pool_conflict_reason()

std::string entropic::session_pool_conflict_reason ( const ModelConfig &  cfg)
inline

Why this tier's session-pool request cannot be honoured.

Returns a reason rather than a bool so the configure-time error names the conflicting keys — a typed error the operator can act on, never a silent clamp or fallback.

Parameters
cfgTier model config.
Returns
Empty when the config is coherent; otherwise the reason. @req REQ-INFER-019
Version
2.12.0

Definition at line 101 of file session_pool_util.h.

◆ session_scoped_tool()

static json entropic::session_scoped_tool ( const ExternalMCPConfig &  cfg,
const char *  suffix,
const char *  fallback 
)
static

Definition for a tool scoped to an optional session (gh#144).

session is optional and NOT in required: omitting it means the shared default session, which is exactly what a pre-2.12.0 client already gets.

Parameters
cfgExternal MCP config supplying prefix and description overrides.
suffixBare tool suffix.
fallbackBuilt-in description.
Returns
One MCP tool definition object. @utility
Version
2.12.0

Definition at line 186 of file external_bridge.cpp.

◆ snapshot_git_project()

static bool entropic::snapshot_git_project ( const std::filesystem::path &  source,
const std::filesystem::path &  target 
)
static

Copy git-tracked + untracked-not-ignored files from a project.

Parameters
sourceGit repository root.
targetDestination directory.
Returns
true on success. @utility
Version
2.1.5

Definition at line 313 of file sandbox.cpp.

◆ snapshot_plain_copy()

static bool entropic::snapshot_plain_copy ( const std::filesystem::path &  source,
const std::filesystem::path &  target 
)
static

Recursive copy for non-git sources (or sandbox-to-sandbox chains).

Parameters
sourceSource directory.
targetDestination directory.
Returns
true on success. @utility
Version
2.1.5

Definition at line 350 of file sandbox.cpp.

◆ socket_path_safe()

static bool entropic::socket_path_safe ( const std::filesystem::path &  path)
static

Reject a pre-existing path that is a symlink or non-socket.

Defends against swap-the-socket-file races where an attacker plants a symlink at the expected path before the engine starts. If the path exists and is anything other than a regular unix socket, the bind is refused. v2.1.7 hardening (gh#34).

Parameters
pathSocket path.
Returns
true if safe to bind (path absent or is a socket). @req REQ-BRIDGE-001
Version
2.1.7

Definition at line 1337 of file external_bridge.cpp.

◆ spec_accept_round()

static bool entropic::spec_accept_round ( SpeculativeRunState &  state,
const llama_vocab *  vocab,
int  max_tokens,
std::function< void(std::string_view)> &  on_token,
std::atomic< bool > &  cancel 
)
static

Run one speculative accept round; return false to stop.

@dg_internal

Version
2.3.7

Definition at line 4151 of file llama_cpp_backend.cpp.

◆ spec_build_batch()

static void entropic::spec_build_batch ( SpeculativeRunState &  state)
static

Build the target batch [id_last, draft0, ..., draftN-1].

Parameters
stateKernel state. @dg_internal
Version
2.1.11

Definition at line 3864 of file llama_cpp_backend.cpp.

◆ spec_check_preconditions()

static std::string entropic::spec_check_preconditions ( bool  target_active,
bool  draft_active,
llama_context *  ctx_tgt,
llama_context *  ctx_dft 
)
static

Validate speculative preconditions and reject NO-seq_rm.

Either FULL or PART seq_rm is acceptable — the kernel has both a partial-seq_rm fast path (PART) and a checkpoint-based path (FULL) that mirrors speculative-simple's use_ckpt branches. Only NO-seq_rm targets/drafts cannot be supported.

Returns
Empty string on success, diagnostic on failure. @dg_internal
Version
2.1.11 [reviewed]

Definition at line 4210 of file llama_cpp_backend.cpp.

◆ spec_ckpt_restore_dft()

static void entropic::spec_ckpt_restore_dft ( SpeculativeRunState &  state)
static

Restore the draft's pre-draft state so the upcoming target-batch decode on the draft re-fills cleanly.

@dg_internal

Version
2.1.11

Definition at line 4023 of file llama_cpp_backend.cpp.

◆ spec_ckpt_save_dft()

static void entropic::spec_ckpt_save_dft ( SpeculativeRunState &  state)
static

Drive one accept round: draft → decode → sample-and-accept → emit tokens.

Returns true to continue the outer loop. @dg_internal

Version
2.1.11 [reviewed]

Snapshot draft state before drafting (when use_ckpt_dft). @dg_internal

Version
2.1.11

Definition at line 3989 of file llama_cpp_backend.cpp.

◆ spec_ckpt_save_tgt()

static void entropic::spec_ckpt_save_tgt ( SpeculativeRunState &  state)
static

Snapshot target state right before the target decode of the speculative batch (when use_ckpt_tgt + non-empty draft).

@dg_internal

Version
2.1.11

Definition at line 4009 of file llama_cpp_backend.cpp.

◆ spec_cleanup()

static void entropic::spec_cleanup ( SpeculativeRunState &  state)
static

Free everything allocated by the kernel.

Parameters
stateKernel state. @dg_internal
Version
2.1.11

Definition at line 3850 of file llama_cpp_backend.cpp.

◆ spec_commit_accepted()

static bool entropic::spec_commit_accepted ( SpeculativeRunState &  state,
const std::vector< llama_token > &  ids,
const llama_vocab *  vocab,
int  max_tokens,
std::function< void(std::string_view)> &  on_token,
std::atomic< bool > &  cancel 
)
static

Walk accepted ids, emit tokens via callback, update state.

Returns true if the outer loop should stop. @dg_internal

Version
2.1.11

Definition at line 4098 of file llama_cpp_backend.cpp.

◆ spec_decode_both()

static bool entropic::spec_decode_both ( SpeculativeRunState &  state)
static

Decode the speculative batch on both contexts.

Populates state.error_* on failure.

Returns
true on success, false on decode failure. @dg_internal
Version
2.1.11 [reviewed]

Definition at line 3883 of file llama_cpp_backend.cpp.

◆ spec_emit_token()

static std::string entropic::spec_emit_token ( SpeculativeRunState &  state,
llama_token  id,
const llama_vocab *  vocab,
int  max_tokens,
std::function< void(std::string_view)> &  on_token,
std::atomic< bool > &  cancel 
)
static

Emit on_token for one accepted id, updating state and returning a stop signal when terminating conditions apply.

Outcomes:

  • "" continue;
  • "eos" hit end-of-generation token (sets finish_reason="stop")
  • "length" reached max_tokens
  • "cancel" cancel flag set (sets error_code=CANCELLED)

@dg_internal

Version
2.9.2

Definition at line 3940 of file llama_cpp_backend.cpp.

◆ spec_finalize()

static GenerationResult entropic::spec_finalize ( SpeculativeRunState &  state,
std::chrono::steady_clock::time_point  t0 
)
static

Speculative kernel against an explicit draft backend.

@dg_internal

Version
2.1.11

Assemble final GenerationResult + log metrics. Helper to keep the public entry under SLOC ≤ 50. @dg_internal

Version
2.12.2

Definition at line 4377 of file llama_cpp_backend.cpp.

◆ spec_init_run()

static std::string entropic::spec_init_run ( SpeculativeRunState &  state,
llama_model *  model_tgt,
const std::vector< llama_token > &  tokens,
const GenerationParams &  params,
int  n_draft_max,
const std::string &  draft_path,
const std::string &  tool_grammar,
bool  tool_grammar_lazy,
const std::string &  generation_prompt 
)
static

Initialize speculative run state (prefill + sampler + decoder).

@dg_internal

Version
2.10.4

Definition at line 4316 of file llama_cpp_backend.cpp.

◆ spec_init_sampler_and_decoder()

static std::string entropic::spec_init_sampler_and_decoder ( SpeculativeRunState &  state,
llama_model *  model_tgt,
const GenerationParams &  params,
int  n_draft_max,
const std::string &  draft_path,
const std::string &  tool_grammar,
bool  tool_grammar_lazy,
const std::string &  generation_prompt 
)
static

Initialize the kernel state: clear KV, prefill, sampler, speculative context, batch, and detect FULL-seq_rm checkpoint-mode for target/draft.

Returns "" on success or a diagnostic string. Cleans up on failure.

Checkpoint detection runs AFTER common_speculative_begin so the impl's batch is already allocated.

@dg_internal

Version
2.1.11

Init the sampler + speculative decoder for a run.

Extracted from spec_init_run to keep it knots-clean. Returns "" on success after wiring state.smpl/spec/batch + checkpoint flags; returns a diagnostic and cleans up on failure.

Parameters
stateSpeculative run state.
model_tgtTarget model (for the sampler).
paramsGeneration params.
n_draft_maxDraft cap (<=0 → 16).
draft_pathDraft model path (gates DRAFT_SIMPLE upstream).
Returns
Empty on success, diagnostic on failure. @utility
Version
2.10.4

Definition at line 4269 of file llama_cpp_backend.cpp.

◆ spec_prepare_draft()

static int entropic::spec_prepare_draft ( SpeculativeRunState &  state)
static

Drive one accept round: optional draft generation, decode on both contexts, sample-and-accept, emit tokens (or roll back via checkpoint on partial acceptance).

Returns true to continue the outer loop. @dg_internal

Version
2.1.11 [reviewed]

Draft tokens for a speculative round (or reuse carry-over).

Extracted from spec_accept_round. When state.draft is empty, runs the draft model under checkpoint save/restore; otherwise reuses the carried-over partial draft.

Parameters
stateSpeculative run state.
Returns
Number of tokens drafted this round. @utility
Version
2.3.7

Definition at line 4133 of file llama_cpp_backend.cpp.

◆ spec_rollback_partial()

static void entropic::spec_rollback_partial ( SpeculativeRunState &  state,
common_sampler *  smpl_save,
std::vector< llama_token > &  ids 
)
static

Partial-acceptance rollback: restore both contexts and the sampler to their pre-draft state, then arrange for the outer loop to re-decode with the partial accept as the new draft.

Matches speculative-simple's partial-acceptance path lines 258-281. @dg_internal

Version
2.1.11

Definition at line 4042 of file llama_cpp_backend.cpp.

◆ spec_run_draft()

static int entropic::spec_run_draft ( SpeculativeRunState &  state)
static

Trigger draft generation via common_speculative_draft.

Returns
Number of draft tokens proposed. @dg_internal
Version
2.13.0

Definition at line 3914 of file llama_cpp_backend.cpp.

◆ spec_run_from_tokens()

static GenerationResult entropic::spec_run_from_tokens ( llama_context *  ctx_tgt,
llama_context *  ctx_dft,
llama_model *  model_tgt,
const std::vector< llama_token > &  tokens,
const GenerationParams &  params,
std::function< void(std::string_view)> &  on_token,
std::atomic< bool > &  cancel,
int  n_draft_max,
const std::string &  draft_path,
std::chrono::steady_clock::time_point  t0,
const std::string &  tool_grammar,
bool  tool_grammar_lazy,
const std::string &  generation_prompt 
)
static

Public entry point for the speculative-decoding kernel.

Validates preconditions, tokenizes the prompt, initializes kernel state, drives the accept-round loop, and finalizes the result. Each phase is delegated to a static helper to satisfy the complexity gates (knots: cognitive ≤ 15, SLOC ≤ 50, returns ≤ 3).

Parameters
messagesConversation history.
paramsGeneration parameters (samplers, max_tokens, seed).
on_tokenCallback fired once per accepted token.
cancelCancellation flag (polled between accept rounds).
draftDraft backend (must be ACTIVE on the same model arch).
n_draft_maxMaximum draft window size (proposed tokens per round). Clamped to 16 if non-positive.
Returns
GenerationResult. @dg_internal
Version
2.1.11 [reviewed]

Run the speculative loop over already-tokenized input.

Extracted from generate_speculative_with_draft to keep it knots-clean. Inits the run state, drives the accept-round loop, and finalizes; cleans up + returns a typed error if init fails.

Parameters
ctx_tgtTarget context.
ctx_dftDraft context.
model_tgtTarget model (sampler + vocab).
tokensPrompt tokens (>= 2).
paramsGeneration parameters.
on_tokenPer-accepted-token callback.
cancelCancellation flag.
n_draft_maxDraft window cap.
draft_pathDraft model path.
t0Start timestamp for timing.
Returns
GenerationResult. @utility
Version
2.10.4

Definition at line 4487 of file llama_cpp_backend.cpp.

◆ spec_run_loop()

static void entropic::spec_run_loop ( SpeculativeRunState &  state,
const llama_vocab *  vocab,
int  max_tokens,
std::function< void(std::string_view)> &  on_token,
std::atomic< bool > &  cancel 
)
static

Run the accept-round loop until completion / EOS / cancel.

@dg_internal

Version
2.1.11

Definition at line 4344 of file llama_cpp_backend.cpp.

◆ spec_trim_rejected_drafts()

static void entropic::spec_trim_rejected_drafts ( SpeculativeRunState &  state)
static

Clear any stale KV positions left by rejected draft tokens.

After spec_decode_both populates positions [n_past_old, n_past_old + K] (one for id_last + K draft slots), the sampler accepts a prefix of length 1 + n_accepted ≤ 1 + K. n_past is then advanced to the next-write slot = old + 1 + n_accepted. Everything at or beyond state.n_past belongs to rejected drafts and must be removed before the next iteration's decode hits the same slots.

Matches upstream speculative-simple.cpp:323: llama_memory_seq_rm(get_memory(ctx), seq_id, n_past, -1). The previous n_past + 1 boundary was off-by-one and left the first rejected-draft slot polluted, causing rc=-1 on PART seq_rm contexts (Gemma 4) on the second iteration (Session 5).

PART contexts honour the seq_rm directly; FULL contexts effectively no-op (their KV is restored via the checkpoint dance in spec_rollback_partial instead).

@dg_internal

Version
2.1.11 [reviewed]

Definition at line 4085 of file llama_cpp_backend.cpp.

◆ split_lines()

static std::vector< std::string > entropic::split_lines ( const std::string &  content)
static

Split string into lines.

Parameters
contentInput string.
Returns
Vector of lines. @utility
Version
1.8.8

Definition at line 77 of file permission_persister.cpp.

◆ stage_active_tools()

static void entropic::stage_active_tools ( InferenceBackend *  model,
const GenerationParams &  params,
bool  require_tool_call 
)
static

Stage the turn's tool defs on the backend for common_chat (gh#87).

Forwards params.tools (per-tier MCP JSON, empty for a tool-less turn) to the backend so its render path emits the model's native tool-call format. No-op for non-LlamaCpp backends. Called before every generate dispatch.

Parameters
modelActive backend (may be null / non-LlamaCpp).
paramsResolved generation params (carries tools).
require_tool_callPer-tier mandatory-tool flag staged alongside the defs; drives the render's tool_choice. @req REQ-INFER-009
Version
2.10.4

Definition at line 576 of file orchestrator.cpp.

◆ staged_tool_count()

static int entropic::staged_tool_count ( const std::string &  tools_json)
static

Number of definitions in a staged MCP tool-list JSON array.

Parameters
tools_jsonStaged tool JSON ("" when no tools are staged).
Returns
Element count; 0 when absent or malformed. @utility
Version
2.13.0

Definition at line 2669 of file llama_cpp_backend.cpp.

◆ stream_token_callback()

static void entropic::stream_token_callback ( const char *  token,
size_t  len,
void *  user_data 
)
static

Token callback for streaming generation.

gh#158 (v2.13.0): the per-token interrupt poll consults this RUN's cancel token as well as the handle-wide flag, so entropic_interrupt_session stops the stream it names. The callback runs inline on the run's own thread, which is what makes the thread-local token readable here.

Parameters
tokenToken string.
lenToken length.
user_dataStreamAccumulator pointer. @req REQ-LOOP-008
Version
2.14.2

Definition at line 281 of file response_generator.cpp.

◆ stream_token_trampoline()

static void entropic::stream_token_trampoline ( const char *  data,
std::size_t  len,
void *  ud 
)
static

Trampoline: bridges TokenCallback C signature to std::function.

Parameters
dataToken bytes.
lenByte count.
udPointer to std::function<void(std::string_view)>. @utility
Version
2.10.0

Definition at line 1023 of file orchestrator.cpp.

◆ strip_reasoning()

static std::string entropic::strip_reasoning ( const std::string &  content,
const std::string &  open,
const std::string &  close 
)
static

Strip reasoning blocks from content before critique (gh#108).

The model's internal reasoning is not subject to constitutional review — passing it to the critique model makes it evaluate planning text as if it were claims about the codebase.

v2.10.3: the markers were hardcoded to <think>, so on a Gemma-4 tier this stripped nothing and the critique model saw raw <|channel> reasoning — precisely the failure this function exists to prevent. They are now supplied by the facade via set_thinking_markers(), sourced from the tier's adapter. Passed as plain strings because core cannot depend on inference.

Kept rather than deleted: validate() takes content as a parameter, so its contract must tolerate unstripped input from a direct caller — it cannot assume the engine's parse path ran first.

Parameters
contentRaw model output.
openOpening delimiter.
closeClosing delimiter.
Returns
Content with reasoning blocks removed. @req REQ-VALID-001
Version
2.10.3

Definition at line 1067 of file constitutional_validator.cpp.

◆ strip_thinking_channels()

void entropic::strip_thinking_channels ( std::string &  content,
std::string *  reasoning_out 
)

Strip Gemma 4 QAT reasoning channels (<|channel>…<channel|>) from content, accumulating the stripped text into reasoning.

The Gemma 4 QAT re-exports (it-qat / it-qat-mobile) are THINKING models: their template emits a <|channel>thought … <channel|> reasoning block before the final answer/tool-call — and ALWAYS when tools are staged. common_chat has no channel parser at this pin, so the block survives in msg.content. This moves it into reasoning so the user-facing content is clean. No-op for any content without the markers — safe for every non-channel family. (gh#106, v2.9.0)

gh#108 (v2.9.4): when a channel opens but never closes (generation hit max_tokens while still inside the reasoning block — a real non-convergence case seen on some quant/MTP combos, not just a hypothetical), everything from the open marker onward is still treated as reasoning and erased — correct, since no actual answer was ever produced — but this used to be silent: a caller saw only an empty content with no signal WHY. Now logs a WARN so this is diagnosable instead of indistinguishable from any other empty-content cause.

Parameters
content[in,out] Content to clean (channel spans removed in place).
reasoning_out[in,out,nullable] Accumulates the stripped reasoning text. @utility
Version
2.11.0

Definition at line 1737 of file llama_cpp_backend.cpp.

◆ summarize_params()

std::string entropic::summarize_params ( const std::string &  args_json)

Extract top-level JSON keys as a comma-separated summary.

Extract top-level JSON keys as comma-separated summary.

Parameters
args_jsonFull JSON arguments string.
Returns
Comma-separated key names (e.g., "path, content"). @utility
Version
1.9.12

Keys ONLY — argument values never enter the history buffer.

Parameters
args_jsonFull JSON arguments string.
Returns
Comma-separated top-level key names; the input verbatim when it is not a JSON object or fails to parse. @req REQ-MCP-020
Version
1.9.12

Definition at line 176 of file tool_call_history.cpp.

◆ swap_session_tool_dir()

void entropic::swap_session_tool_dir ( const std::string &  session_key,
const std::filesystem::path &  path,
bool  entering,
void *  ud 
)

The facade's gh#160 ScopedSandbox swap callback.

Move a session's servers into (or back out of) a sandbox.

Moves the session's server set (its workspace's, else the handle's default set) into path on entry and back out on restore. Installed on the engine by wire_session_roots; declared here — and exported, because the facade builds with hidden visibility — so a white-box test can drive the production swap rather than a copy of it (gh#158).

Parameters
session_keySession whose tools are being moved.
pathDirectory to point the servers at.
enteringTrue on sandbox entry, false on restore.
udEngine handle (entropic_handle_t). @req REQ-DELEG-005
Version
2.13.0

The implementation sandbox.h has described since v2.1.5 and nobody ever installed. entering drives a lock as well as the move: the in-process servers hold ONE working directory each, so two sandboxed delegations running at once (the default since gh#158) would otherwise interleave their swaps and write into each other's sandbox — or into the user's tree, once the first one restored.

gh#158 (second audit pass): the lock is the server set's own (ServerManager::enter_working_dir / leave_working_dir), and every in-process dispatch on that set now takes it SHARED. Until then only the swaps took it (a facade recursive_mutex), so an UNBOUND session dispatching during another session's sandboxed delegation resolved inside that session's sandbox. One lock per ServerManager is still one per workspace (gh#166), which is where the parallelism comes back.

Lives here rather than beside wire_session_roots because entropic.cpp is one extern "C" block and this is a C++ symbol: declared in engine_handle.h so a white-box test can drive the PRODUCTION swap through a real ScopedSandbox (gh#158).

Parameters
session_keySession whose tools are being moved.
pathDirectory to point the servers at.
enteringTrue on sandbox entry, false on restore.
udEngine handle. @req REQ-DELEG-005 @callback
Version
2.13.0 [reviewed]

Definition at line 283 of file entropic_mcp.cpp.

◆ task_complete_notification()

static json entropic::task_complete_notification ( const std::string &  task_id,
const std::string &  status 
)
static

The completion notification for an async task (Issue #4, v2.1.2).

The spec-defined notifications/progress rather than the old non-spec notifications/ask_complete, which some clients silently buffered or stalled on. progressToken is the task_id, correlating it back to the ask that returned that id. The result body is NOT shipped inline — consumers fetch it via ask_status — which caps the notification at ~200 bytes whatever was generated; status rides in message so a consumer can branch on done / error / cancelled without a round-trip.

Parameters
task_idTask id.
statusTerminal status.
Returns
JSON-RPC notification. @utility
Version
2.14.0

Definition at line 1925 of file external_bridge.cpp.

◆ tc_from_json_obj()

static std::vector< ToolCall > entropic::tc_from_json_obj ( const nlohmann::json &  j)
static

Build a ToolCall from a parsed JSON object with name/tool + arguments/parameters.

Returns
Single-element vector on success; empty vector on schema mismatch. @utility
Version
2.9.18

Definition at line 314 of file interface_factory.cpp.

◆ tier_grammar_unresolved()

bool entropic::tier_grammar_unresolved ( const GenerationParams &  params)
inline

A TIER named a grammar and nothing resolved it (gh#154).

Reads only what ModelOrchestrator::resolve_grammar_key already wrote, so there is no second copy of the precedence rule to keep in sync: the key is recorded BEFORE the registry lookup and grammar stays empty when the lookup misses, so the three fields together say "the tier asked, and nothing answered".

Deliberately narrow. A per-call params.grammar_key miss is NOT this: it may name a grammar the caller registers later, so it keeps the documented fail-open and reports itself through generations[].grammar.resolved == false. A tier stem is static config and the ENGINE selects the tier, so a miss there is a broken deployment the caller cannot see from the output — the decode would be unconstrained and shaped exactly like a constrained one.

Parameters
paramsParams after resolve_grammar_key has run.
Returns
true when a tier-derived key was named and resolved to nothing. @req REQ-INFER-007
Version
2.13.0

Definition at line 147 of file grammar_source.h.

◆ to_common_chat()

static std::vector< common_chat_msg > entropic::to_common_chat ( const std::vector< Message > &  messages)
static

Convert engine messages to common_chat_msg (gh#86, v2.6.1).

Role + content only. The legacy apply_chat_template path renders without tools (entropic injects tool prompts into the system message via ResponseGenerator::inject_tool_prompt); the gh#87 render_with_tools path supplies tools through inputs.tools instead.

Parameters
messagesSource messages.
Returns
Vector of common_chat_msg. @utility
Version
2.6.1

Definition at line 1340 of file llama_cpp_backend.cpp.

◆ to_entropic_tool_call()

static ToolCall entropic::to_entropic_tool_call ( const common_chat_tool_call &  cc)
static

Map a common_chat_tool_call to entropic's ToolCall (gh#87).

Name + id pass through; the JSON arguments string is kept verbatim in arguments_json (for passthrough dispatch) and also flattened into the string key-value arguments map (object values dumped back to JSON).

Parameters
ccNative common_chat tool call.
Returns
entropic ToolCall. @utility
Version
2.7.0

Definition at line 1397 of file llama_cpp_backend.cpp.

◆ to_llama_chat()

static std::vector< llama_chat_message > entropic::to_llama_chat ( const std::vector< Message > &  messages)
static

Convert engine messages to llama_chat_message views.

Parameters
messagesSource messages (must outlive the returned views).
Returns
Vector of {role, content} c_str pointers into messages. @utility
Version
2.3.7

Definition at line 1317 of file llama_cpp_backend.cpp.

◆ tool_definitions()

static json entropic::tool_definitions ( const ExternalMCPConfig &  cfg)
static

MCP tool definitions exposed by the bridge.

gh#145 (v2.12.0): names and descriptions are consumer-configurable. The defaults ("entropic" prefix, no description overrides) reproduce the pre-2.12.0 payload exactly.

Parameters
cfgExternal MCP config supplying prefix and description overrides.
Returns
JSON array of tool schemas. @utility
Version
2.14.3

Definition at line 287 of file external_bridge.cpp.

◆ tool_error_json()

std::string entropic::tool_error_json ( const std::string &  code,
const std::string &  message 
)

A declared tool error: {"error": code, "message": message}.

v2.14.0 (gh#203): the one shape every bundled tool refusal takes, with a code its outputSchema enumerates.

Parameters
codeError code.
messageHuman-readable message.
Returns
Serialized JSON object. @utility
Version
2.14.0
Parameters
codeError code (declared in the tool's outputSchema).
messageHuman-readable message.
Returns
Serialized JSON object. @utility @req REQ-MCP-015
Version
2.14.0

Definition at line 269 of file tool_base.cpp.

◆ tool_handlers()

static const std::unordered_map< std::string, ToolHandler > & entropic::tool_handlers ( )
static

Non-ask tools by suffix (v2.14.3).

A table rather than an else-if chain: adding release made the chain the deepest construct in the bridge (knots nesting 5). Keyed by the same tool_suffix constants tool_definitions() advertises (gh#145).

Returns
Suffix → handler. @utility
Version
2.14.3

Definition at line 1109 of file external_bridge.cpp.

◆ tool_is_read_only()

static bool entropic::tool_is_read_only ( const nlohmann::json &  tool)
static

Whether one tool descriptor asserts readOnlyHint: true (gh#160).

Parameters
toolTool descriptor from an MCP tools/list reply.
Returns
true only when the annotation is present AND true. @utility
Version
2.13.0

Definition at line 331 of file server_manager.cpp.

◆ tool_string_props()

static std::unordered_set< std::string > entropic::tool_string_props ( const nlohmann::json &  tools,
const std::string &  name 
)
static

String-typed property names for a tool in the staged MCP defs.

Parameters
toolsParsed MCP tool array.
nameTool name to match.
Returns
Property names whose schema declares "type":"string". @dg_internal
Version
2.7.2

Definition at line 342 of file adapter_base.cpp.

◆ tool_text()

static json entropic::tool_text ( const std::string &  text)
static

Wrap text in MCP tool result shape.

Parameters
textResult text.
Returns
MCP content array JSON. @utility
Version
2.0.8

Definition at line 101 of file external_bridge.cpp.

◆ trim_path_prefix()

static void entropic::trim_path_prefix ( std::string &  line,
std::string  p 
)
static

Strip a directory prefix p from the front of line.

Parameters
[in,out]linePath line to trim in place.
pPrefix directory (a trailing slash is added if missing). @utility
Version
2.3.7

Definition at line 466 of file sandbox.cpp.

◆ truncate_result()

std::string entropic::truncate_result ( const std::string &  text,
size_t  max_len 
)

Truncate a string to max_len characters with "..." suffix.

Truncate text with "..." suffix if too long.

Parameters
textInput text.
max_lenMaximum length before truncation.
Returns
Truncated string, or original if short enough. @utility
Version
1.9.12
Parameters
textInput text.
max_lenMaximum length before truncation (200 for the history result summary).
Returns
The input unchanged when it is within max_len; otherwise its first max_len characters with "..." appended. @req REQ-MCP-020
Version
1.9.12

Definition at line 205 of file tool_call_history.cpp.

◆ try_expert_offload()

bool entropic::try_expert_offload ( const GgufShape &  shape,
const FootprintInputs &  base,
uint64_t  budget,
AutoPlacement *  out 
)
inline

Try keeping every layer resident by moving experts host-side.

A MoE only, and tried BEFORE dropping layers: moving a layer off takes its attention with it, while moving that layer's experts off frees the bulk of its bytes and leaves attention on the card.

Parameters
shapeModel shape.
baseFootprint inputs.
budgetVRAM budget.
[out]outFilled in on success.
Returns
True when some expert split fits. @dg_internal
Version
2.13.1

Definition at line 221 of file auto_placement.h.

◆ try_fenced_args_object_call()

static std::vector< ToolCall > entropic::try_fenced_args_object_call ( const std::string &  raw,
const std::string &  tools_json 
)
static

Try to synthesise a tool call from a fenced args-only JSON object (gh#127).

Fires after the gh#122 named-object path returns empty. When the fenced block is a valid JSON object with NO name or tool key, checks tools_json for a unique tool whose required parameters are all present as object keys. If exactly one tool matches, synthesises a ToolCall with that name and the object as arguments. Zero or multiple matches → empty (no false positive).

Parameters
rawRaw model output.
tools_jsonJSON array of staged MCP tool definitions.
Returns
Single-element vector on unique match; empty otherwise. @utility
Version
2.10.0

Definition at line 446 of file interface_factory.cpp.

◆ try_fenced_json_call()

static std::vector< ToolCall > entropic::try_fenced_json_call ( const std::string &  raw)
static

Extract a tool call from a single fenced json block in raw model output (gh#122).

Fires only when both the PEG parser and adapter return 0 calls and the output contains exactly one fenced json block that matches the {name/tool, arguments/parameters} schema. Conservative: does nothing if the block is missing, malformed, or there are multiple blocks.

Parameters
rawRaw model output.
Returns
Single-element vector on success; empty on mismatch. @utility
Version
2.9.18

Definition at line 349 of file interface_factory.cpp.

◆ try_fewer_layers()

bool entropic::try_fewer_layers ( const GgufShape &  shape,
const FootprintInputs &  base,
uint64_t  budget,
AutoPlacement *  out 
)
inline

Last resort: take the largest layer count that fits.

Parameters
shapeModel shape.
baseFootprint inputs.
budgetVRAM budget.
[out]outFilled in on success.
Returns
True when any layer count fits. @dg_internal
Version
2.13.1

Definition at line 252 of file auto_placement.h.

◆ try_fully_resident()

bool entropic::try_fully_resident ( const GgufShape &  shape,
const FootprintInputs &  base,
uint64_t  budget,
AutoPlacement *  out 
)
inline

Try the best case: every layer and every expert on the card.

Parameters
shapeModel shape.
baseFootprint inputs.
budgetVRAM budget.
[out]outFilled in on success.
Returns
True when it fits. @dg_internal
Version
2.13.1

Definition at line 191 of file auto_placement.h.

◆ try_smaller_ubatch()

bool entropic::try_smaller_ubatch ( const GgufShape &  shape,
const FootprintInputs &  base,
uint64_t  free_vram_bytes,
int  configured,
AutoPlacement *  out 
)
inline

Try full residency at each ubatch below the configured one.

Tried BEFORE displacing experts or layers, and stopping at the FIRST value that fits rather than descending to a floor — "as far as needed" not "as far as possible". A prefill-heavy workload should lose the minimum, and 128 when 256 would have fit is a 2x prefill loss nobody asked for.

Parameters
shapeModel shape.
baseFootprint inputs.
free_vram_bytesWhole-device free VRAM (the allowance is per step).
configuredOperator's n_ubatch; 0 means llama.cpp's default.
[out]outFilled in on success, including the chosen n_ubatch.
Returns
True when some reduced ubatch fits everything. @dg_internal
Version
2.13.2

Definition at line 286 of file auto_placement.h.

◆ try_template_parse()

static bool entropic::try_template_parse ( LlamaCppBackend *  llama,
const std::string &  raw,
ParsedModelResponse &  out 
)
static

Tool calls from the template parser, when trustworthy.

Trustworthiness is an a-posteriori check, not a try/catch: common_chat's PEG autoparser silently extracts only the FIRST <parameter=> of a multi-parameter call and returns a well-formed ToolCall with arguments missing, so the result is validated against the staged schema.

Parameters
llamaBackend.
rawRaw output.
[out]outResult to populate on success.
Returns
true when the format is reliable AND the parsed calls satisfy the staged schema; false routes the caller to the adapter parser. @req REQ-INFER-010
Version
2.10.3

Definition at line 136 of file response_parse.cpp.

◆ utc_timestamp()

std::string entropic::utc_timestamp ( )

Get current UTC time as ISO 8601 string.

Returns
Timestamp string (e.g., "2026-03-23T12:00:00"). @req REQ-STOR-003
Version
1.8.8
Returns
Timestamp string. @req REQ-STOR-003
Version
1.8.8

Definition at line 1009 of file backend.cpp.

◆ utf8_char_len()

static int entropic::utf8_char_len ( unsigned char  byte)
static

Count expected bytes in a UTF-8 sequence from lead byte.

Parameters
byteLead byte.
Returns
Expected total bytes (1-4), or 0 if continuation byte. @utility
Version
2.0.2

Definition at line 75 of file stream_think_filter.cpp.

◆ validate_fields()

static std::string entropic::validate_fields ( const IdentityConfig &  config)
static

Validate phases and adapter_path fields.

Parameters
configConfig to validate.
Returns
Empty string on success, error message on failure. @req REQ-IDEN-002
Version
2.1.0

Definition at line 63 of file identity_manager.cpp.

◆ validate_phases()

static std::string entropic::validate_phases ( const std::unordered_map< std::string, PhaseConfig > &  phases)
static

Validate all phases in an identity config.

Parameters
phasesPhase map to validate.
Returns
Empty string on success, error message on failure. @req REQ-IDEN-002
Version
1.9.9

Definition at line 39 of file identity_manager.cpp.

◆ validate_tool_args()

static std::string entropic::validate_tool_args ( const std::string &  schema_json,
const nlohmann::json &  args 
)
static

Validate tool arguments against the tool's JSON Schema.

Checks required fields, enum constraints, and basic type matching. Returns an error string on violation, or empty on pass.

Parameters
schema_jsonThe tool's input_schema (JSON Schema string).
argsThe parsed arguments from the model.
Returns
An empty string when the arguments satisfy the schema — and also when the schema is absent or unparseable, which reads as "nothing to validate" rather than throwing; otherwise the first violation's description, required fields before per-property constraints. @req REQ-MCP-013
Version
2.0.6

Definition at line 455 of file tool_executor.cpp.

◆ warm_keep_cut()

template<typename Tok >
std::size_t entropic::warm_keep_cut ( const std::vector< Tok > &  resident,
const std::vector< Tok > &  incoming,
long  kv_pos_max 
)
inline

Decide how many resident-KV tokens warm-keep may reuse this turn.

Returns the cut: tokens [0, cut) are kept in KV (the divergent tail is seq_rm'd) and the incoming sequence is decoded from cut onward. A return of 0 means fall back to a cold prefill. Rules:

  • no resident KV, or an incoming prompt shorter than 2 tokens → 0;
  • the KV must actually hold the matched prefix (kv_pos_max+1 >= common), else something mutated seq 0 out-of-band (multimodal / complete / speculative / another conversation) → 0, fall back;
  • never reuse the whole sequence — always re-decode at least the final token so its logits are fresh for sampling (cut < incoming.size()).
Parameters
residentTokens recorded as resident in KV seq 0 (the last prompt).
incomingThe new prompt's tokens.
kv_pos_maxHighest occupied position in seq 0 (llama_memory_seq_pos_max), or < 0 if empty.
Returns
Reuse cut in [0, incoming.size()); 0 = cold fallback. @utility
Version
2.7.5

Definition at line 62 of file warm_keep_util.h.

◆ warn_if_budget_starved_required_turn()

static void entropic::warn_if_budget_starved_required_turn ( const GenerationResult &  result,
const std::string &  tier_name,
const std::unordered_map< std::string, TierConfig > &  tiers 
)
static

Diagnose a mandatory-tool turn that ran out of budget (gh#134).

Under tool_choice: REQUIRED the gemma4 grammar is zero_or_more(any) + tool_call: unbounded preamble, then a MANDATORY call. So the grammar guarantees a call comes EVENTUALLY, not that it arrives within max_tokens. Measured on E4B QAT: at 600 tokens the model could no longer quit with prose (correct) but burned the budget narrating and was cut off (finish_reason == "length", zero calls); at 2000 it emitted a call on all 10 turns.

That failure is a budget misconfiguration, not a model or grammar fault, and it is indistinguishable from a stall unless the engine says so — the same diagnostic dead end gh#130 fixed on the bridge. enable_thinking is the usual culprit because the thinking channel is what consumes the preamble.

Parameters
resultCompleted generation result.
tier_nameTier that produced it.
tiersTier table, for the per-tier require_tool_call lookup. @utility
Version
2.10.4

Definition at line 678 of file orchestrator.cpp.

◆ warn_if_content_vanished()

static void entropic::warn_if_content_vanished ( const GenerationResult &  result)
static

Explain a turn that produced tokens but delivered no content (gh#137).

The reasoning strip legitimately empties a generation that never closed its reasoning block — surfacing raw reasoning as the answer would be worse. But the operator has to know WHICH problem they have, and until v2.11.0 the engine gave one message for both, telling them to raise max_tokens.

gh#137 reported finish=stop with 154 chars delivering 0 chars. The model ended that turn itself; no budget increase can help, and the advice sent the reporter looking in the wrong place. This is the only site that can tell the difference, because it is the only one holding finish_reason.

gh#159: it is also the only site holding the PARSED TOOL CALLS, and it was not passing them. apply_adapter_parse runs before this, moving tool calls out of content — so a turn whose whole output was one tool call (the normal shape under tool_call_mode: sequential) arrived here as content empty / raw non-empty / finish "stop" and got gh#137's diagnosis verbatim, telling operators of enable_thinking: false tiers that an unterminated reasoning block was not converging. That fired on every tool-call turn of a session. A parsed call is not a fault, so it is reported at INFO.

Parameters
resultCompleted generation result. @req REQ-INFER-010
Version
2.13.0

Definition at line 642 of file orchestrator.cpp.

◆ warn_turn_diagnostics()

static void entropic::warn_turn_diagnostics ( const GenerationResult &  result,
const std::string &  tier_name,
const std::unordered_map< std::string, TierConfig > &  tiers 
)
static

Report every post-turn diagnostic from one call site (gh#137).

Folded into a single entry point because the caller is generate, which sits against the knots ABC ceiling — two adjacent warn calls pushed it over. Both checks are no-ops on a healthy turn.

Parameters
resultCompleted generation result.
tier_nameSelected tier.
tiersConfigured tiers, for the require_tool_call budget check. @req REQ-INFER-010
Version
2.11.0

Definition at line 710 of file orchestrator.cpp.

◆ wire_external_server_policy()

void entropic::wire_external_server_policy ( entropic_handle_t  h,
ServerManager &  servers,
bool  with_declared 
)

Give a server set the handle's external-server policy (v2.14.0).

The set receives the handle's .mcp.json enablement keys, the bridge socket to refuse, and an approver over the handle's ENTROPIC_HOOK_PRE_MCP_SERVER_CONNECT hooks — the same for the default set and every workspace, which is what makes a workspace stop spawning its root's .mcp.json (gh#199). Declared external_servers go to the default set only: they are the handle's, not every repository's.

Call before ServerManager::initialize().

Parameters
hEngine handle with config loaded.
serversServer set to configure.
with_declaredWhether this set connects mcp.external_servers. @req REQ-MCP-025
Version
2.14.0
Parameters
hEngine handle with config loaded.
serversServer set to configure.
with_declaredWhether this set connects mcp.external_servers. @req REQ-MCP-025
Version
2.14.0

Definition at line 242 of file entropic_mcp.cpp.

◆ wire_outside_root_approver()

void entropic::wire_outside_root_approver ( entropic_handle_t  h)

Point the DEFAULT server set's filesystem server at the handle's path-approval slot (v2.13.0).

Wire the default set's filesystem server to the handle's slot.

Installs a thunk, not the consumer's callback, so a later entropic_set_path_approval_callback takes effect without touching the server. Called once the default set exists; never for a workspace.

Parameters
hEngine handle with server_manager constructed. @req REQ-MCP-021
Version
2.13.0
Parameters
hEngine handle with server_manager constructed. @req REQ-MCP-021
Version
2.13.0

Definition at line 140 of file entropic_mcp.cpp.

◆ workspace_for()

EntropicWorkspace * entropic::workspace_for ( entropic_handle_t  h,
const std::string &  key 
)
inline

The workspace a session is bound to, or nullptr for the default.

gh#166 (v2.13.0). An unbound session — every session that existed before this release — resolves to nullptr and therefore to the handle-wide server_manager, which is why binding nothing changes nothing.

Parameters
hEngine handle.
keySession key ("" = default session).
Returns
Borrowed workspace, or nullptr when unbound/unknown. @req REQ-MCP-027
Version
2.13.0

Definition at line 237 of file engine_handle.h.

◆ workspace_servers()

entropic::ServerManager * entropic::workspace_servers ( entropic_handle_t  h,
const std::string &  key 
)
inline

The MCP servers a session's tools must run against (gh#166).

Parameters
hEngine handle.
keySession key ("" = default session).
Returns
The bound workspace's servers, else the handle's default set. @req REQ-MCP-027
Version
2.13.0

Definition at line 255 of file engine_handle.h.

◆ write_file()

static bool entropic::write_file ( const std::filesystem::path &  path,
const std::string &  content 
)
static

Write string to file.

Parameters
pathFile path.
contentContent to write.
Returns
true on success. @utility
Version
1.8.8

Definition at line 61 of file permission_persister.cpp.

◆ write_json_line()

static void entropic::write_json_line ( int  fd,
const json &  msg 
)
static

Write a JSON-RPC line to a socket fd.

Parameters
fdSocket file descriptor.
msgJSON object to serialize and write. @utility
Version
2.0.10

Definition at line 321 of file external_bridge.cpp.

Variable Documentation

◆ DIRECTIVE_NAMES

const char* const entropic::DIRECTIVE_NAMES[]
static
Initial value:
= {
"stop_processing",
"tier_change",
"delegate",
"pipeline",
"complete",
"clear_self_todos",
"inject_context",
"prune_messages",
"context_anchor",
"phase_change",
"notify_presenter",
}

Serialize ServerResponse to JSON envelope.

Parameters
responseResponse to serialize.
Returns
JSON string. @dg_internal
Version
1.8.5

Map directive type enum to wire-format string.

Parameters
typeDirective type.
Returns
Type string. @dg_internal
Version
1.8.5

Directive type enum → wire-format string lookup. @dg_internal

Version
1.8.5

Definition at line 284 of file server_base.cpp.

◆ fixed

entropic::fixed = std::regex_replace(fixed, std::regex(R"(,\s*\])"), "]")

Definition at line 514 of file adapter_base.cpp.

◆ kAllLayersSentinel

constexpr int entropic::kAllLayersSentinel = 99
constexpr

gpu_layers at or above this means "every layer" (llama.cpp's 99).

Definition at line 73 of file vram_footprint.h.

◆ kBaseKvPerTokenF16

constexpr uint64_t entropic::kBaseKvPerTokenF16 = 16ull * 1024ull
constexpr

KV bytes per token at f16, the rate the v2.2.4 estimate assumed.

Definition at line 70 of file vram_footprint.h.

◆ kComputeBytesAtUbatch512

constexpr uint64_t entropic::kComputeBytesAtUbatch512 = 1222ull * 1024ull * 1024ull
constexpr

Measured compute scratch for ONE context at a 512-token ubatch (vram_footprint.h: 1222 MiB, gemma-4 E4B with an MTP head).

Definition at line 86 of file auto_placement.h.

◆ kComputeReferenceUbatch

constexpr int entropic::kComputeReferenceUbatch = 512
constexpr

The ubatch that figure was measured at.

Definition at line 89 of file auto_placement.h.

◆ kDefaultUbatch

constexpr int entropic::kDefaultUbatch = 512
constexpr

llama.cpp's default ubatch, assumed when the tier does not set one.

Definition at line 92 of file auto_placement.h.

◆ kExpertTensorRegex

constexpr const char* entropic::kExpertTensorRegex
constexpr
Initial value:
=
"\\.ffn_(up|down|gate|gate_up)_(ch|)exps"

Tensor-name pattern tail identifying a layer's ROUTED-expert weights.

Copied verbatim from the vendored llama.cpp at this pin — LLM_FFN_EXPS_REGEX in extern/llama.cpp/common/common.h, the same constant --n-cpu-moe builds its overrides from. It is duplicated rather than included so this header stays vendor-free; expert_offload_test.cpp includes <common.h> and asserts the two are equal, so a pin bump that changes upstream's pattern fails a CPU unit test instead of silently offloading nothing.

llama.cpp matches it with std::regex_search against the full tensor name (llama-model-loader.cpp), so it is a SUBSTRING match. For the gemma4 MoE arch at this pin that covers blk.N.ffn_gate_exps.weight, blk.N.ffn_up_exps.weight, blk.N.ffn_down_exps.weight, the fused blk.N.ffn_gate_up_exps.weight, and their per-expert .scale siblings — and nothing else. The router (ffn_gate_inp), the shared/dense FFN (ffn_gate/ffn_up/ffn_down), every *_shexp, attention, norms and embeddings do NOT match, which is precisely the point: they stay wherever gpu_layers put them.

Version
2.13.0

Definition at line 76 of file expert_offload.h.

◆ kLargeModelThresholdBytes

constexpr uint64_t entropic::kLargeModelThresholdBytes = 10ull * 1024 * 1024 * 1024
constexpr

Size above which a model counts as "large" for the waiver below.

The two models that have ever needed the allowance are 12.6 GB and 13.6 GB; every other model in the suite is under 6 GB and must stay un-waivable, so a mis-set allowance cannot silently blank the run.

Definition at line 124 of file partial_offload.h.

◆ kMemlockUnlimited

constexpr uint64_t entropic::kMemlockUnlimited = UINT64_MAX
constexpr

Sentinel for an unlimited RLIMIT_MEMLOCK (gh#148).

Definition at line 157 of file partial_offload.h.

◆ kNoSessionSlot

constexpr int entropic::kNoSessionSlot = -1
constexpr

Sentinel for "no slot assigned".

Definition at line 45 of file session_residency.h.

◆ kPartialOffloadReserveBytes

constexpr uint64_t entropic::kPartialOffloadReserveBytes = 2048ull * 1024 * 1024
constexpr

VRAM held back for compute/graph buffers, which scale with ubatch and model internals rather than with layer count.

The v2.7.0 note records a compute-buffer OOM at 20 layers when only ~2 GB was spare, so this is deliberately generous.

Definition at line 34 of file partial_offload.h.

◆ kStateNames

const char* const entropic::kStateNames[]
static
Initial value:
= {
"IDLE", "PLANNING", "EXECUTING", "WAITING_TOOL", "VERIFYING",
"DELEGATING", "COMPLETE", "ERROR", "INTERRUPTED", "PAUSED",
}

Lookup table for AgentState names indexed by enum value.

@dg_internal

Definition at line 24 of file engine_types.cpp.

◆ kUbatchLadder

constexpr int entropic::kUbatchLadder[] = {512, 256, 128}
constexpr

Values auto will step down through, descending.

config.h calls 128, 256 and 512 the productive values; below 128 the prefill cost keeps rising while the VRAM freed flattens, so there is nothing useful further down.

Definition at line 99 of file auto_placement.h.

◆ logger [1/2]

auto entropic::logger = log::get("identity_manager")
static

Definition at line 17 of file identity_manager.cpp.

◆ logger [2/2]

auto entropic::logger = entropic::log::get("mcp.external_bridge")
static

Definition at line 48 of file external_bridge.cpp.

◆ MIGRATION_001_INITIAL

constexpr const char* entropic::MIGRATION_001_INITIAL
staticconstexpr

@dg_internal

Definition at line 35 of file database.cpp.

◆ MIGRATION_002_FTS

constexpr const char* entropic::MIGRATION_002_FTS
staticconstexpr
Initial value:
= R"sql(
CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(
content,
content='messages',
content_rowid='rowid'
);
CREATE TRIGGER IF NOT EXISTS messages_ai AFTER INSERT ON messages BEGIN
INSERT INTO messages_fts(rowid, content) VALUES (NEW.rowid, NEW.content);
END;
CREATE TRIGGER IF NOT EXISTS messages_ad AFTER DELETE ON messages BEGIN
INSERT INTO messages_fts(messages_fts, rowid, content)
VALUES('delete', OLD.rowid, OLD.content);
END;
CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
INSERT INTO messages_fts(messages_fts, rowid, content)
VALUES('delete', OLD.rowid, OLD.content);
INSERT INTO messages_fts(rowid, content) VALUES (NEW.rowid, NEW.content);
END;
)sql"

@dg_internal

Definition at line 82 of file database.cpp.

◆ MIGRATION_003_DELEGATIONS

constexpr const char* entropic::MIGRATION_003_DELEGATIONS
staticconstexpr
Initial value:
= R"sql(
CREATE TABLE IF NOT EXISTS delegations (
id TEXT PRIMARY KEY,
parent_conversation_id TEXT NOT NULL,
child_conversation_id TEXT NOT NULL,
delegating_tier TEXT NOT NULL,
target_tier TEXT NOT NULL,
task TEXT NOT NULL,
max_turns INTEGER,
status TEXT NOT NULL DEFAULT 'pending'
CHECK(status IN ('pending', 'running', 'completed', 'failed')),
result_summary TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
completed_at TIMESTAMP,
FOREIGN KEY (parent_conversation_id)
REFERENCES conversations(id) ON DELETE CASCADE,
FOREIGN KEY (child_conversation_id)
REFERENCES conversations(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_delegations_parent
ON delegations(parent_conversation_id);
CREATE INDEX IF NOT EXISTS idx_delegations_child
ON delegations(child_conversation_id);
)sql"

@dg_internal

Definition at line 106 of file database.cpp.

◆ MIGRATION_004_COMPACTION_SNAPSHOTS

constexpr const char* entropic::MIGRATION_004_COMPACTION_SNAPSHOTS
staticconstexpr
Initial value:
= R"sql(
CREATE TABLE IF NOT EXISTS compaction_snapshots (
id TEXT PRIMARY KEY,
conversation_id TEXT NOT NULL,
messages_json TEXT NOT NULL,
message_count INTEGER NOT NULL,
token_count_estimate INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (conversation_id)
REFERENCES conversations(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_snapshots_conversation
ON compaction_snapshots(conversation_id);
)sql"

@dg_internal

Definition at line 133 of file database.cpp.

◆ MIGRATIONS

constexpr std::array<Migration, 4> entropic::MIGRATIONS
staticconstexpr
Initial value:
= {{
{"001_initial", MIGRATION_001_INITIAL},
{"002_fts", MIGRATION_002_FTS},
{"003_delegations", MIGRATION_003_DELEGATIONS},
{"004_compaction_snapshots", MIGRATION_004_COMPACTION_SNAPSHOTS},
}}
static constexpr const char * MIGRATION_002_FTS
@dg_internal
Definition database.cpp:82
static constexpr const char * MIGRATION_004_COMPACTION_SNAPSHOTS
@dg_internal
Definition database.cpp:133
static constexpr const char * MIGRATION_001_INITIAL
@dg_internal
Definition database.cpp:35

@dg_internal

Definition at line 150 of file database.cpp.

◆ s_bound_sockets

std::unordered_set<std::string> entropic::s_bound_sockets
static

Definition at line 57 of file external_bridge.cpp.

◆ s_bound_sockets_mu

std::mutex entropic::s_bound_sockets_mu
static

Definition at line 56 of file external_bridge.cpp.

◆ s_reserved_names

const std::vector<std::string> entropic::s_reserved_names
static
Initial value:
= {
"default", "none", "all", "router"}

Reserved identity names that cannot be used.

Definition at line 20 of file identity_manager.cpp.

◆ s_tier_prompt_dedup

std::unordered_map<std::string, entropic::PromptLogDedup> entropic::s_tier_prompt_dedup
static

gh#152: bodies already shown in this tier's prompt log.

Definition at line 60 of file response_generator.cpp.

◆ s_tier_system_hash

std::unordered_map<std::string, size_t> entropic::s_tier_system_hash
static

Per-tier system prompt hash for diff detection across delegations.

Definition at line 57 of file response_generator.cpp.

◆ try

entropic::try
Initial value:
{
if (auto tc = parse_recovered_tool_call(fixed)) { return tc; }
} catch (...) {
return regex_recovered_tool_call(json_str);
}
return std::nullopt
static std::optional< ToolCall > parse_recovered_tool_call(const std::string &fixed)
Parse a brace/quote-fixed JSON string into a ToolCall.

Definition at line 518 of file adapter_base.cpp.

◆ VISION_INSTRUCTION

constexpr const char* entropic::VISION_INSTRUCTION
staticconstexpr
Initial value:
=
"\n\nYou can see and analyze images. When the user shares an "
"image, describe what you observe before responding to their "
"question."

Vision instruction appended to system prompt.

Definition at line 229 of file qwen35_adapter.cpp.