symfonic.agent.prompts.db_section¶
db_section ¶
DBPromptSection -- versioned Jinja2 templates from PostgreSQL with Redis caching.
Conforms to the PromptSection protocol from symfonic.core.prompt.
Unlike the HMS section (which uses {{VARIABLE}} plain substitution),
this section renders through Jinja2's SandboxedEnvironment enabling
conditionals, loops, and filters.
Render pipeline
- Check Redis cache for section content
- If miss, query
prompt_section_versionsfor the enabled version - Render content through Jinja2 SandboxedEnvironment
- If any step fails, render
fallback_contentthrough Jinja2
DBPromptSection
dataclass
¶
DBPromptSection(
name: str,
required: bool = False,
priority: int = 50,
cache_breakpoint: bool = False,
fallback_content: str = "",
section_key: str = "",
cache_ttl_seconds: int = 300,
)
PromptSection that loads versioned Jinja2 templates from PostgreSQL.
The state dict is passed as Jinja2 template context, enabling:
- {{ name }} variable substitution
- {% if user_is_premium %}...{% endif %} conditionals
- {% for item in items %}...{% endfor %} loops
- {{ name | upper }} filters
Gracefully degrades when Redis or DB are unavailable, falling back
to fallback_content rendered through the same Jinja2 pipeline.
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. |
fallback_content |
str
|
Jinja2 template string used when DB/cache are unavailable. |
section_key |
str
|
DB lookup key; defaults to |
cache_ttl_seconds |
int
|
Redis TTL for cached template content (default 300s). |
configure ¶
Inject optional Redis and DB dependencies. Returns self for chaining.
Source code in src/symfonic/agent/prompts/db_section.py
render
async
¶
Render the section: cache -> DB -> fallback, all through Jinja2.