|
Entropic 2.14.3
Local-first agentic inference engine
|
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>
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_sampler_knobs (ryml::ConstNodeRef root, IdentityFrontmatter &fm) |
| Extract identity-specific fields from a pre-parsed ryml tree. | |
| static void | entropic::prompts::extract_identity_flags (ryml::ConstNodeRef root, IdentityFrontmatter &fm) |
| Extract the scalar loop/flag fields of an identity. | |
| 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. | |
| static std::string | entropic::prompts::load_app_context_file (const std::filesystem::path &app_context_path, const std::filesystem::path &data_dir, std::string &body) |
| Read app_context from a file, resolving bare names as bundled. | |
| ENTROPIC_EXPORT AppContextState | entropic::prompts::classify_app_context (const std::optional< std::filesystem::path > &app_context_path, const std::optional< std::string > &app_context_content, bool disabled) |
| Classify the app_context configuration. | |
| ENTROPIC_EXPORT const char * | entropic::prompts::app_context_state_message (AppContextState state) |
| The log message describing one app_context state. | |
| ENTROPIC_EXPORT std::string | entropic::prompts::load_app_context (const std::optional< std::filesystem::path > &app_context_path, const std::optional< std::string > &app_context_content, bool disabled, const std::filesystem::path &data_dir, std::string &body) |
| Load app_context prompt with tri-state resolution. | |
| ENTROPIC_EXPORT void | entropic::prompts::load_shared_prompt_sources (const entropic::ParsedConfig &config, const std::filesystem::path &data_dir, std::string &constitution, std::string &app_context) |
| Load constitution + app_context, logging any failure. | |
| static std::string | entropic::prompts::check_constitution_source (const entropic::ParsedConfig &config, const std::filesystem::path &data_dir) |
| Check a configured constitution path loads. | |
| static std::string | entropic::prompts::check_app_context_source (const entropic::ParsedConfig &config, const std::filesystem::path &data_dir) |
| Check a configured app_context path loads. | |
| ENTROPIC_EXPORT std::string | entropic::prompts::validate_configured_prompts (const entropic::ParsedConfig &config, const std::filesystem::path &data_dir) |
| Check that every CONFIGURED prompt source can actually be loaded. | |
| 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") |
Prompt manager implementation — frontmatter parsing, identity loading.
Definition in file manager.cpp.
| const char * entropic::prompts::app_context_state_message | ( | AppContextState | state | ) |
The log message describing one app_context state.
For every state but INLINE this is why app_context contributed no body; for FROM_PATH it is the prefix used when the named path was rejected, since a path that loads needs no explanation.
| state | State to describe. |
| state | State to describe. |
Definition at line 513 of file manager.cpp.
| 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.
| config | Parsed engine config. |
| data_dir | Bundled data directory. |
Loads constitution, app_context, and default tier identity, then concatenates. The data_dir is used for bundled fallback paths.
| config | Parsed engine config. |
| data_dir | Bundled data directory. |
Definition at line 761 of file manager.cpp.
|
static |
Check a configured app_context path loads.
Inline content (gh#141) and app_context: false are never checked — neither touches the filesystem, and both must keep working untouched.
| config | Parsed engine config. |
| data_dir | Bundled data directory. |
Definition at line 645 of file manager.cpp.
|
static |
Check a configured constitution path loads.
| config | Parsed engine config. |
| data_dir | Bundled data directory. |
Definition at line 615 of file manager.cpp.
| AppContextState entropic::prompts::classify_app_context | ( | const std::optional< std::filesystem::path > & | app_context_path, |
| const std::optional< std::string > & | app_context_content, | ||
| bool | disabled | ||
| ) |
Classify the app_context configuration.
An explicit opt-out wins over everything, then inline content, then a path — the same precedence load_app_context() applies.
| app_context_path | Configured path (nullopt = none). |
| app_context_content | Inline text (nullopt = none). |
| disabled | true when app_context: false. |
| app_context_path | Configured path (nullopt = none). |
| app_context_content | Inline text (nullopt = none). |
| disabled | true when app_context: false. |
Definition at line 488 of file manager.cpp.
|
static |
Extract benchmark config from identity frontmatter.
| root | ryml root node. | |
| [out] | fm | Output identity frontmatter. |
Definition at line 213 of file manager.cpp.
|
static |
Extract all identity frontmatter fields into the struct.
@dg_internal
Definition at line 305 of file manager.cpp.
|
static |
Extract the scalar loop/flag fields of an identity.
| root | YAML root node. | |
| [out] | fm | Identity frontmatter to populate. @utility |
Definition at line 283 of file manager.cpp.
|
static |
Extract phase configs from identity frontmatter.
| root | ryml root node. | |
| [out] | fm | Output identity frontmatter. |
Definition at line 187 of file manager.cpp.
|
static |
Extract identity-specific fields from a pre-parsed ryml tree.
| root | ryml root node of the frontmatter. | |
| [out] | fm | Output identity frontmatter. |
Extract the per-tier sampler knobs (gh#82/gh#85/gh#86).
Each is optional — set only when the key is present so the orchestrator can distinguish a configured per-tier value from "not set" (and leave the GenerationParams default in place). Split from extract_identity_flags to keep both under the knots ABC gate.
| root | YAML root node. | |
| [out] | fm | Identity frontmatter to populate. @utility |
Definition at line 258 of file manager.cpp.
| std::string entropic::prompts::load_app_context | ( | const std::optional< std::filesystem::path > & | app_context_path, |
| const std::optional< std::string > & | app_context_content, | ||
| bool | disabled, | ||
| const std::filesystem::path & | data_dir, | ||
| std::string & | body | ||
| ) |
Load app_context prompt with tri-state resolution.
Load app_context from inline content or a path, 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.
| app_context_path | Custom path (nullopt = disabled by default). | |
| disabled | true if app_context explicitly disabled. | |
| data_dir | Bundled data directory used to resolve bare filenames. | |
| [out] | body | Output app_context text (empty if disabled or nullopt). |
Resolution order (gh#141): an explicit opt-out wins over everything; then inline content, which is used without touching the filesystem; then a path. The state that produced no body is named in the log (gh#163).
| app_context_path | Custom path (nullopt = none configured). | |
| app_context_content | Inline text (nullopt = none supplied). | |
| disabled | true if app_context explicitly disabled. | |
| data_dir | Bundled data directory. | |
| [out] | body | Output app_context text; cleared whenever no body loads. |
Definition at line 546 of file manager.cpp.
|
static |
Read app_context from a file, resolving bare names as bundled.
Split out of load_app_context in v2.11.0: adding the inline-content branch (gh#141) pushed that function to the top of the complexity report, and the two sources are independent concerns.
| app_context_path | Configured path; a bare filename resolves under data_dir/prompts/, anything with a directory component is used as-is. | |
| data_dir | Bundled data directory. | |
| [out] | body | Receives the parsed prompt body. |
Definition at line 449 of file manager.cpp.
| 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.
| constitution_path | Custom path (nullopt = bundled). | |
| disabled | true if constitution explicitly disabled. | |
| data_dir | Bundled data directory for fallback. | |
| [out] | body | Output constitution text (empty if disabled). |
| constitution_path | Custom path (nullopt = bundled). | |
| disabled | true if constitution explicitly disabled. | |
| data_dir | Bundled data directory. | |
| [out] | body | Output constitution text. |
Definition at line 394 of file manager.cpp.
| 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.
| path | Path to identity .md file. | |
| [out] | identity | Output parsed identity. |
| path | Path to identity .md file. | |
| [out] | identity | Output parsed identity. |
Definition at line 340 of file manager.cpp.
| void entropic::prompts::load_shared_prompt_sources | ( | const entropic::ParsedConfig & | config, |
| const std::filesystem::path & | data_dir, | ||
| std::string & | constitution, | ||
| std::string & | app_context | ||
| ) |
Load constitution + app_context, logging any failure.
Load both shared prompt sources, logging rather than discarding.
gh#156: every one of the three callers that needed both bodies called the two loaders and DISCARDED their error strings, so a prompt file the engine could not parse showed up only as a false in the assembly line. This is the shared entry point those callers use.
gh#163 moved the logging INTO each loader, which is the only layer that knows which state the config was in; a failure is therefore reported whoever calls, and the corresponding body is left empty. The fatal decision belongs to validate_configured_prompts(), which runs at configure time before anything expensive happens.
| config | Parsed engine config. | |
| data_dir | Bundled data directory. | |
| [out] | constitution | Receives the constitution body (empty on failure). |
| [out] | app_context | Receives the app_context body (empty on failure). |
| config | Parsed engine config. | |
| data_dir | Bundled data directory. | |
| [out] | constitution | Constitution body (empty when it failed). |
| [out] | app_context | App context body (empty when it failed). @req REQ-TYPE-005 |
Definition at line 586 of file manager.cpp.
|
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.
| content | Full file content. | |
| path | File path (for error messages). | |
| [out] | tree | Output ryml tree of frontmatter. |
| [out] | body | Output markdown body after frontmatter. |
Definition at line 58 of file manager.cpp.
| 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.
| path | Path to .md prompt file. | |
| expected_type | Expected frontmatter type. | |
| [out] | result | Output: type, version, body. |
| path | Path to .md prompt file. | |
| expected_type | Expected frontmatter type. | |
| [out] | result | Output: type, version, body. |
Definition at line 134 of file manager.cpp.
|
static |
Map a frontmatter type string to a PromptType.
| type_str | Frontmatter "type" value. | |
| path | Prompt path (for the error message). | |
| [out] | err | Set to a diagnostic on an unknown type. |
Definition at line 108 of file manager.cpp.
| const char * entropic::prompts::prompt_type_to_string | ( | PromptType | type | ) |
Convert PromptType to string.
| type | Prompt type. |
| type | Prompt type. |
Definition at line 92 of file manager.cpp.
| 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.
| tier_config | Tier configuration. |
| tier_name | Tier name (for default path convention). |
| data_dir | Bundled data directory. |
| tier_config | Tier configuration. |
| tier_name | Tier name (for default path convention). |
| data_dir | Bundled data directory. |
Definition at line 740 of file manager.cpp.
| 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)
| tier_config | Tier configuration. |
| tier_name | Tier name (for default path convention). |
| data_dir | Bundled data directory. |
Path convention:
| tier_config | Tier configuration. |
| tier_name | Tier name (for default path convention). |
| data_dir | Bundled data directory. |
Definition at line 704 of file manager.cpp.
|
static |
Trim leading and trailing whitespace from a string.
| s | Input string. |
Definition at line 33 of file manager.cpp.
| std::string entropic::prompts::validate_configured_prompts | ( | const entropic::ParsedConfig & | config, |
| const std::filesystem::path & | data_dir | ||
| ) |
Check that every CONFIGURED prompt source can actually be loaded.
Check every configured prompt source can be loaded.
gh#156: a consumer who names a path wanted that document. Silently running with a 17 KB smaller system prompt is not an acceptable outcome, so an unreadable / unparseable constitution or app_context path is a config error. Only explicitly configured sources are checked — the bundled constitution fallback, app_context: false, inline app_context: {content: ...} and an absent key all pass.
| config | Parsed engine config. |
| data_dir | Bundled data directory. |
| config | Parsed engine config. |
| data_dir | Bundled data directory. |
Definition at line 678 of file manager.cpp.
|
static |
Definition at line 15 of file manager.cpp.