babylon.ai.persona
Persona models for AI narrative voice customization (Sprint 4.2).
This module defines immutable Pydantic models for AI personas that customize the NarrativeDirector’s voice and behavior.
Personas are: - Frozen (immutable) for consistency - Validated against JSON Schema at load time - Used by PromptBuilder to generate system prompts
Design follows the SimulationEvent pattern from babylon.models.events.
Example
>>> from babylon.ai.persona import Persona, VoiceConfig
>>> voice = VoiceConfig(
... tone="Clinical, Dialectical",
... style="Marxist analysis",
... address_user_as="Comrade",
... )
>>> persona = Persona(
... id="test_persona",
... name="Test Persona",
... role="Test Role",
... voice=voice,
... obsessions=["Material conditions"],
... directives=["Analyze dialectically"],
... )
>>> print(persona.render_system_prompt())
See also
babylon.ai.persona_loader: Functions to load personas from JSON files.
babylon.ai.prompt_builder.DialecticalPromptBuilder: Uses personas.
Classes
|
AI narrative persona for the NarrativeDirector (immutable). |
|
Voice characteristics for a narrative persona (immutable). |
- class babylon.ai.persona.VoiceConfig(**data)[source]
Bases:
BaseModelVoice characteristics for a narrative persona (immutable).
Defines the tone, style, and user address pattern for an AI persona. This is a nested model within Persona.
- Parameters:
- tone
Emotional and rhetorical tone (e.g., “Clinical, Dialectical”).
- style
Writing style and theoretical framework.
- address_user_as
How the persona addresses the user (e.g., “Architect”).
Example
>>> voice = VoiceConfig( ... tone="Clinical, Dialectical, Revolutionary", ... style="High-theoretical Marxist analysis", ... address_user_as="Architect", ... ) >>> voice.tone 'Clinical, Dialectical, Revolutionary'
- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- tone: str
- style: str
- address_user_as: str
- class babylon.ai.persona.Persona(**data)[source]
Bases:
BaseModelAI narrative persona for the NarrativeDirector (immutable).
Defines the complete identity and behavioral rules for an AI persona. Personas are loaded from JSON files and validated against JSON Schema.
- Parameters:
- id
Unique snake_case identifier.
- name
Full display name of the persona.
- role
Persona’s role or title.
- voice
Voice characteristics (nested VoiceConfig).
- obsessions
Topics the persona is obsessed with analyzing.
- directives
Behavioral directives for the persona.
- restrictions
Topics or behaviors to avoid (default empty).
Example
>>> from babylon.ai.persona import Persona, VoiceConfig >>> voice = VoiceConfig( ... tone="Clinical", ... style="Marxist", ... address_user_as="Architect", ... ) >>> persona = Persona( ... id="test_persona", ... name="Test", ... role="Role", ... voice=voice, ... obsessions=["Material conditions"], ... directives=["Analyze"], ... ) >>> persona.restrictions []
- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- id: str
- name: str
- role: str
- voice: VoiceConfig
- obsessions: list[str]
- directives: list[str]
- restrictions: list[str]
- render_system_prompt()[source]
Render the persona as an LLM system prompt.
Formats all persona attributes into a structured prompt that establishes the AI’s identity and behavioral rules.
- Return type:
- Returns:
Formatted system prompt string for LLM consumption.
Example
>>> persona = Persona(...) >>> prompt = persona.render_system_prompt() >>> assert persona.name in prompt