symfonic.core.prompt.builder¶
builder ¶
PromptBuilder -- ordered section pipeline for system prompt construction.
PromptBuilder ¶
Ordered pipeline that assembles system prompt from sections.
Source code in src/symfonic/core/prompt/builder.py
add_section ¶
build
async
¶
Render all sections in priority order, collecting warnings.
Source code in src/symfonic/core/prompt/builder.py
build_cached
async
¶
Build prompt with Anthropic cache_control annotations.
Sections with cache_breakpoint=True get {"type": "ephemeral"}
cache_control. The first rendered section is always marked for
caching. By default the last rendered section is also marked for
caching, matching the v6.x behaviour callers depend on.
Pass force_last_cache=False when the trailing section is
per-turn user content (e.g. the L2 task layer in the v7.x
stratigraphic stack: hydrated memory, prospective tasks, query
context). Marking that block cached every turn forces a
cache_creation write on every request, which is priced at
1.25x input cost on Anthropic — strictly worse than not caching
when the content has cardinality of one per turn. With
force_last_cache=False only the FIRST section and any
section that explicitly declares cache_breakpoint=True carry
a cache_control annotation; the last block is left bare so
Anthropic stops the cache prefix at the previous breakpoint.
v7.24.0 cache_ttl interaction (load-bearing for adopters):
force_last_cache=True auto-promotes the trailing block to
a cache breakpoint. When the trailing section ALSO carries
cache_ttl="1h" (via the v7.24.0 §2 plugin knob or §5
stratigraphic propagation), the cold-write premium on every
uncached suffix is 2x input rate -- vs the 1.25x premium at
the 5m default. Adopters who flip force_last_cache=True
on a per-turn-mutating section while opting into 1h pay the
2x premium on every turn for content that doesn't survive
the cache anyway. Usually unintended -- prefer
force_last_cache=False for per-turn content, OR keep
cache_ttl=None (5m default) on sections that mutate
frequently. See docs/concepts/cache-tier-tradeoffs.md
for the full trade-off analysis.
The BuildResult content field contains a JSON-encoded list of Anthropic content blocks so downstream callers can forward it directly to the API.
Existing build() behaviour is completely unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
PromptState
|
Render-state mapping forwarded to each section. |
required |
force_last_cache
|
bool
|
When True (default) the last rendered
section is annotated cached regardless of its
|
True
|
Source code in src/symfonic/core/prompt/builder.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
PromptSection ¶
Bases: Protocol
A named section that renders content from state.