symfonic.agent.prompts.ports¶
ports ¶
The declared port of the prompt-assembly capability.
This module exists because the matrix is silent here, not because it is
permissive. symfonic.agent.prompts is ruled capability (T1.2.4
archcheck.toml) and so is symfonic.capabilities.prompting, and
check_boundaries returns nothing for a same-layer edge — "same-layer
structure is governed by package-level rules, not the matrix"
(:mod:symfonic.devtools.archcheck.boundaries). So the one cross-package
import, symfonic.capabilities.prompting.hms reaching
:class:~symfonic.agent.prompts.system_prompt.HMSSystemPromptSection, is not
licensed by a cell; it is out of the checker's reach entirely.
T1.2.1's dependency-matrix.md says what the self cell does not mean:
"capability → capability cross-talk is not an import edge at all: collaboration
goes through ports declared to the compiler and wired via the plan (LAY-ADR
§3.4). The self cell does not license importing another capability
package's internals." system_prompt is an internal module of a different
capability package, so that note excludes exactly the edge above.
The package-level rule the matrix defers to is therefore written here and
enforced by test_the_prompting_capability_reaches_agent_prompts_only_through_a_port:
importers outside symfonic.agent name this module and nothing else under
symfonic.agent.prompts. Nothing is defined locally; the single name is
re-exported from its owning module, so there is still one implementation.
HMSSystemPromptSection
dataclass
¶
HMSSystemPromptSection(name: str = 'HMS System Prompt', required: bool = False, priority: int = 5, cache_breakpoint: bool = True, template_path: Path | None = None)
PromptSection that renders the HMS-aware system prompt template.
Substitutes all {{VARIABLE}} placeholders from the PromptState
context. Raises ValueError if any placeholder remains unresolved
after rendering.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Section display name used by PromptBuilder. |
required |
bool
|
Whether a render failure should abort the build. |
priority |
int
|
Lower numbers appear earlier in the assembled prompt. |
template_path |
Path | None
|
Optional override path (file or directory) for the hms_system.txt template. Defaults to the bundled template. |
estimate_tokens
staticmethod
¶
Estimate token count using a conservative 3-chars-per-token heuristic.
The len // 4 heuristic undercounts by 20-30 % on structured /
markdown text. len // 3 is closer to observed tokeniser output
for prompts that contain headings, bullet lists, and JSON blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to estimate token count for. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated number of tokens (conservative upper bound). |
Source code in src/symfonic/agent/prompts/system_prompt.py
render
async
¶
Render the HMS system prompt by substituting placeholders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
PromptState
|
Mapping that must contain values for every
|
required |
Returns:
| Type | Description |
|---|---|
str
|
The fully substituted prompt text. |
Raises:
| Type | Description |
|---|---|
SecurityScopeError
|
If |
ValueError
|
If any |
Source code in src/symfonic/agent/prompts/system_prompt.py
render_sync ¶
The whole of :meth:render, without the coroutine.
Extracted for #21: a prompting source's read is synchronous by
contract, and rendering never awaited anything -- render is a
coroutine only because PromptSection is. Splitting it keeps one
implementation of the placeholder rules, which is the point of porting
rather than rewriting: the upper/lower key fallback is invisible until
an adopter's state happens to use the other case.
Source code in src/symfonic/agent/prompts/system_prompt.py
validate_budget ¶
Check whether rendered fits within the token budget.
Does NOT raise — callers decide how to handle over-budget results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rendered
|
str
|
The already-rendered prompt text. |
required |
max_tokens
|
int
|
Maximum allowed token count. |
1000
|
Returns:
| Type | Description |
|---|---|
tuple[bool, int]
|
Tuple of |