babylon.ai.prompt_builder
Builder for Dialectical Prompts and Context Hierarchy.
Implements the context structure from docs/AI_COMMS.md: 1. Material Conditions (from WorldState) 2. Historical/Theoretical Context (from RAG) 3. Recent Events (from tick delta)
The builder creates structured prompts that ground AI responses in material conditions and class analysis, following Marxist dialectical materialism principles.
Sprint 4.1: Updated to consume typed SimulationEvent objects instead of string-based event_log.
Sprint 4.2: Added Persona support for customizable narrative voices.
Classes
|
Builds prompts following Marxist dialectical materialism. |
- class babylon.ai.prompt_builder.DialecticalPromptBuilder(persona=None)[source]
Bases:
objectBuilds prompts following Marxist dialectical materialism.
The builder creates structured prompts that ground AI responses in material conditions and class analysis. It follows the context hierarchy defined in AI_COMMS.md.
Sprint 4.2: Added persona support for customizable narrative voices. When a persona is provided, build_system_prompt() returns the persona’s rendered prompt instead of the default.
- Parameters:
persona (Persona | None)
- persona
Optional Persona to use for system prompt generation.
Example
>>> builder = DialecticalPromptBuilder() >>> system_prompt = builder.build_system_prompt() >>> context = builder.build_context_block(state, rag_docs, events) >>> >>> # With persona (Sprint 4.2) >>> from babylon.ai.persona_loader import load_default_persona >>> percy = load_default_persona() >>> builder = DialecticalPromptBuilder(persona=percy) >>> system_prompt = builder.build_system_prompt()
- property persona: Persona | None
Return the persona if configured.
- Returns:
The Persona instance or None if not configured.
- build_system_prompt()[source]
Return the immutable core identity of the Director.
If a persona is configured (Sprint 4.2), returns the persona’s rendered system prompt. Otherwise, returns the default Marxist game master prompt.
- Return type:
- Returns:
System prompt establishing the AI’s identity and role.
- build_context_block(state, rag_context, events)[source]
Assemble the Context Hierarchy.
Builds context following AI_COMMS.md hierarchy: 1. Material Conditions (from WorldState) 2. Historical/Theoretical Context (from RAG) 3. Recent Events (from tick delta)
Sprint 4.1: Now accepts typed SimulationEvent objects instead of strings.
- Parameters:
state (
WorldState) – Current WorldState for material conditions.rag_context (
list[str]) – Retrieved documents from RAG pipeline.events (
list[SimulationEvent]) – New typed events from this tick (SimulationEvent objects).
- Return type:
- Returns:
Formatted context block string.