Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
manager.cpp File Reference

Prompt manager implementation — frontmatter parsing, identity loading. More...

#include <entropic/prompts/manager.h>
#include <entropic/types/logging.h>
#include "yaml_util.h"
#include <ryml.hpp>
#include <c4/std/string.hpp>
Include dependency graph for manager.cpp:

Go to the source code of this file.

Namespaces

namespace  entropic
 Activate model on GPU (WARM → ACTIVE).
 

Functions

static std::string entropic::prompts::trim (const std::string &s)
 Trim leading and trailing whitespace from a string.
 
static std::string entropic::prompts::parse_frontmatter (const std::string &content, const std::filesystem::path &path, ryml::Tree &tree, std::string &body)
 Parse YAML frontmatter from file content into a ryml tree.
 
ENTROPIC_EXPORT const char * entropic::prompts::prompt_type_to_string (PromptType type)
 Convert PromptType to string.
 
static PromptType entropic::prompts::prompt_type_from_string (const std::string &type_str, const std::filesystem::path &path, std::string &err)
 Map a frontmatter type string to a PromptType.
 
ENTROPIC_EXPORT std::string entropic::prompts::parse_prompt_file (const std::filesystem::path &path, PromptType expected_type, ParsedPrompt &result)
 Parse a prompt file: validate frontmatter, return body.
 
static void entropic::prompts::extract_phases (ryml::ConstNodeRef root, IdentityFrontmatter &fm)
 Extract phase configs from identity frontmatter.
 
static void entropic::prompts::extract_benchmark (ryml::ConstNodeRef root, IdentityFrontmatter &fm)
 Extract benchmark config from identity frontmatter.
 
static void entropic::prompts::extract_identity_flags (ryml::ConstNodeRef root, IdentityFrontmatter &fm)
 Extract identity-specific fields from a pre-parsed ryml tree.
 
static void entropic::prompts::extract_identity_fields (ryml::ConstNodeRef root, IdentityFrontmatter &fm)
 Extract all identity frontmatter fields into the struct.
 
ENTROPIC_EXPORT std::string entropic::prompts::load_identity (const std::filesystem::path &path, ParsedIdentity &identity)
 Load an identity file: parse frontmatter + body.
 
ENTROPIC_EXPORT std::string entropic::prompts::load_constitution (const std::optional< std::filesystem::path > &constitution_path, bool disabled, const std::filesystem::path &data_dir, std::string &body)
 Load constitution prompt with tri-state resolution.
 
ENTROPIC_EXPORT std::string entropic::prompts::load_app_context (const std::optional< std::filesystem::path > &app_context_path, bool disabled, const std::filesystem::path &data_dir, std::string &body)
 Load app_context prompt with tri-state resolution.
 
ENTROPIC_EXPORT ParsedIdentity entropic::prompts::resolve_tier_identity_full (const entropic::TierConfig &tier_config, const std::string &tier_name, const std::filesystem::path &data_dir)
 Resolve full parsed identity (body + frontmatter) for a tier.
 
ENTROPIC_EXPORT std::string entropic::prompts::resolve_tier_identity (const entropic::TierConfig &tier_config, const std::string &tier_name, const std::filesystem::path &data_dir)
 Resolve the system prompt body for a named tier.
 
ENTROPIC_EXPORT std::string entropic::prompts::assemble (const entropic::ParsedConfig &config, const std::filesystem::path &data_dir)
 Assemble the full system prompt from config.
 

Variables

static auto s_log = entropic::log::get("prompts")
 

Detailed Description

Prompt manager implementation — frontmatter parsing, identity loading.

Version
1.8.2

Definition in file manager.cpp.

Function Documentation

◆ assemble()

std::string entropic::prompts::assemble ( const entropic::ParsedConfig config,
const std::filesystem::path &  data_dir 
)

Assemble the full system prompt from config.

Loads constitution, app_context, and default tier identity, then concatenates them. Used by the facade during configure.

Parameters
configParsed engine config.
data_dirBundled data directory.
Returns
Assembled system prompt string (may be empty if all disabled).
Version
2.0.1

Loads constitution, app_context, and default tier identity, then concatenates. The data_dir is used for bundled fallback paths.

Parameters
configParsed engine config.
data_dirBundled data directory.
Returns
Assembled system prompt string.

Definition at line 515 of file manager.cpp.

◆ extract_benchmark()

static void entropic::prompts::extract_benchmark ( ryml::ConstNodeRef  root,
IdentityFrontmatter fm 
)
static

Extract benchmark config from identity frontmatter.

Parameters
rootryml root node.
[out]fmOutput identity frontmatter.
Version
1.8.2

Definition at line 213 of file manager.cpp.

◆ extract_identity_fields()

static void entropic::prompts::extract_identity_fields ( ryml::ConstNodeRef  root,
IdentityFrontmatter fm 
)
static

Extract all identity frontmatter fields into the struct.

Definition at line 273 of file manager.cpp.

◆ extract_identity_flags()

static void entropic::prompts::extract_identity_flags ( ryml::ConstNodeRef  root,
IdentityFrontmatter fm 
)
static

Extract identity-specific fields from a pre-parsed ryml tree.

Parameters
rootryml root node of the frontmatter.
[out]fmOutput identity frontmatter.
Version
2.0.6-rc18

Extract the scalar sampler/loop/flag fields of an identity.

Parameters
rootYAML root node.
[out]fmIdentity frontmatter to populate. @utility
Version
2.3.7

Definition at line 252 of file manager.cpp.

◆ extract_phases()

static void entropic::prompts::extract_phases ( ryml::ConstNodeRef  root,
IdentityFrontmatter fm 
)
static

Extract phase configs from identity frontmatter.

Parameters
rootryml root node.
[out]fmOutput identity frontmatter.
Version
1.8.2

Definition at line 187 of file manager.cpp.

◆ load_app_context()

std::string entropic::prompts::load_app_context ( const std::optional< std::filesystem::path > &  app_context_path,
bool  disabled,
const std::filesystem::path &  data_dir,
std::string &  body 
)

Load app_context prompt with tri-state resolution.

Resolution order: if disabled or app_context_path is nullopt, body is left empty (no bundled fallback — app_context is opt-in). If a path is provided and is a bare filename, it is resolved relative to data_dir/prompts/. Absolute paths and paths with directory components are used as-is.

Parameters
app_context_pathCustom path (nullopt = disabled by default).
disabledtrue if app_context explicitly disabled.
data_dirBundled data directory used to resolve bare filenames.
[out]bodyOutput app_context text (empty if disabled or nullopt).
Returns
Empty string on success, error on failure.
Version
1.8.1
Parameters
app_context_pathCustom path (nullopt = disabled).
disabledtrue if app_context explicitly disabled.
data_dirBundled data directory.
[out]bodyOutput app_context text.
Returns
Empty string on success, error on failure.
Version
1.8.2 @utility

Definition at line 406 of file manager.cpp.

◆ load_constitution()

std::string entropic::prompts::load_constitution ( const std::optional< std::filesystem::path > &  constitution_path,
bool  disabled,
const std::filesystem::path &  data_dir,
std::string &  body 
)

Load constitution prompt with tri-state resolution.

Parameters
constitution_pathCustom path (nullopt = bundled).
disabledtrue if constitution explicitly disabled.
data_dirBundled data directory for fallback.
[out]bodyOutput constitution text (empty if disabled).
Returns
Empty string on success, error on failure.
Version
1.8.1
Parameters
constitution_pathCustom path (nullopt = bundled).
disabledtrue if constitution explicitly disabled.
data_dirBundled data directory.
[out]bodyOutput constitution text.
Returns
Empty string on success, error on failure.
Version
1.8.2 @utility

Definition at line 362 of file manager.cpp.

◆ load_identity()

std::string entropic::prompts::load_identity ( const std::filesystem::path &  path,
ParsedIdentity identity 
)

Load an identity file: parse frontmatter + body.

Convenience wrapper that additionally parses all IdentityFrontmatter fields.

Parameters
pathPath to identity .md file.
[out]identityOutput parsed identity.
Returns
Empty string on success, error on failure.
Version
1.8.1
Parameters
pathPath to identity .md file.
[out]identityOutput parsed identity.
Returns
Empty string on success, error on failure.
Version
1.8.2 @utility

Definition at line 308 of file manager.cpp.

◆ parse_frontmatter()

static std::string entropic::prompts::parse_frontmatter ( const std::string &  content,
const std::filesystem::path &  path,
ryml::Tree &  tree,
std::string &  body 
)
static

Parse YAML frontmatter from file content into a ryml tree.

Splits content on "---" delimiters, validates structure, and returns the parsed YAML tree plus the markdown body. Shared between parse_prompt_file() and load_identity() to avoid double file reads.

Parameters
contentFull file content.
pathFile path (for error messages).
[out]treeOutput ryml tree of frontmatter.
[out]bodyOutput markdown body after frontmatter.
Returns
Empty string on success, error on failure.
Version
1.8.2

Definition at line 58 of file manager.cpp.

◆ parse_prompt_file()

std::string entropic::prompts::parse_prompt_file ( const std::filesystem::path &  path,
PromptType  expected_type,
ParsedPrompt result 
)

Parse a prompt file: validate frontmatter, return body.

File format: YAML frontmatter between — delimiters, followed by markdown body.

Parameters
pathPath to .md prompt file.
expected_typeExpected frontmatter type.
[out]resultOutput: type, version, body.
Returns
Empty string on success, error on failure.
Version
1.8.1
Parameters
pathPath to .md prompt file.
expected_typeExpected frontmatter type.
[out]resultOutput: type, version, body.
Returns
Empty string on success, error on failure.
Version
2.3.7 @utility

Definition at line 134 of file manager.cpp.

◆ prompt_type_from_string()

static PromptType entropic::prompts::prompt_type_from_string ( const std::string &  type_str,
const std::filesystem::path &  path,
std::string &  err 
)
static

Map a frontmatter type string to a PromptType.

Parameters
type_strFrontmatter "type" value.
pathPrompt path (for the error message).
[out]errSet to a diagnostic on an unknown type.
Returns
The PromptType (default-constructed on unknown). @utility
Version
2.3.7

Definition at line 108 of file manager.cpp.

◆ prompt_type_to_string()

const char * entropic::prompts::prompt_type_to_string ( PromptType  type)

Convert PromptType to string.

Parameters
typePrompt type.
Returns
String representation.
Version
1.8.1
Parameters
typePrompt type.
Returns
String representation.
Version
1.8.2 @utility

Definition at line 92 of file manager.cpp.

◆ resolve_tier_identity()

std::string entropic::prompts::resolve_tier_identity ( const entropic::TierConfig tier_config,
const std::string &  tier_name,
const std::filesystem::path &  data_dir 
)

Resolve the system prompt body for a named tier.

Body-only wrapper around resolve_tier_identity_full.

Looks up the tier in config, resolves the identity file path (explicit, bundled convention, or disabled), loads it, and returns the markdown body. Encapsulates the path convention "identity_{tier_name}.md" in one place.

Parameters
tier_configTier configuration.
tier_nameTier name (for default path convention).
data_dirBundled data directory.
Returns
Identity body string (empty if disabled or not found).
Version
2.0.1
Parameters
tier_configTier configuration.
tier_nameTier name (for default path convention).
data_dirBundled data directory.
Returns
Identity body string (empty if disabled or not found). @utility
Version
2.0.6-rc18

Definition at line 494 of file manager.cpp.

◆ resolve_tier_identity_full()

ParsedIdentity entropic::prompts::resolve_tier_identity_full ( const entropic::TierConfig tier_config,
const std::string &  tier_name,
const std::filesystem::path &  data_dir 
)

Resolve full parsed identity (body + frontmatter) for a tier.

Resolve a full parsed identity (body + frontmatter) for a tier.

Same resolution rules as resolve_tier_identity() but returns the full ParsedIdentity so callers can read frontmatter fields (max_iterations, max_tool_calls_per_turn, etc.) that are discarded by the body-only variant. Returns an empty-body ParsedIdentity if no identity file is found. (E6, 2.0.6-rc18)

Parameters
tier_configTier configuration.
tier_nameTier name (for default path convention).
data_dirBundled data directory.
Returns
ParsedIdentity; body is empty if disabled or not found.
Version
2.0.6-rc18

Path convention:

  1. If tier has explicit identity path → use it
  2. If identity not disabled → data_dir/prompts/identity_{tier_name}.md
  3. If disabled or not found → empty ParsedIdentity
Parameters
tier_configTier configuration.
tier_nameTier name (for default path convention).
data_dirBundled data directory.
Returns
ParsedIdentity; body empty when no identity resolved. @utility
Version
2.0.6-rc18

Definition at line 458 of file manager.cpp.

◆ trim()

static std::string entropic::prompts::trim ( const std::string &  s)
static

Trim leading and trailing whitespace from a string.

Parameters
sInput string.
Returns
Trimmed string.
Version
1.8.2 @utility

Definition at line 33 of file manager.cpp.

Variable Documentation

◆ s_log

auto s_log = entropic::log::get("prompts")
static

Definition at line 15 of file manager.cpp.