Narra is a Python command-line tool that transforms LLM narrative generation from a linear process into a structured, schema-driven approach that simulates the planning and forethought that real writers employ. Instead of generating stories sequentially, Narra breaks complex narratives into interconnected schema chunks that build upon each other, creating a "diffusion model" approach to storytelling.
- Schema-Driven Generation: Break narratives into logical, interdependent components
- Cross-Schema References: Later schemas can reference and build upon earlier generated content
- Built-in Evaluation: Three-step critique process ensures content quality and revision
- Markdown Output: Human-readable .md files instead of JSON for better accessibility
- Configurable Pipeline: Per-schema control of temperature, tokens, and model selection
- Domain Agnostic: Extensible to any narrative domain requiring non-linear planning
- Leverage-First Approach: Establish high-impact details first, then build complexity
-
Clone the repository
git clone https://github.com/yourusername/narra.git cd narra -
Set up Python environment
python -m venv narra-env source narra-env/bin/activate # On Windows: narra-env\Scripts\activate pip install openai python-dotenv
-
Configure API key
cp .env.example .env # Edit .env and add your OpenAI API key: # OPENAI_API_KEY=sk-your-actual-key-here
Preferred method:
python Narra.pyThis runs the complete schema pipeline starting from the first schema in the execution order.
Starting from a specific schema:
To begin processing from a particular point in your pipeline, modify the last line in Narra.py:
# Instead of:
tool.run_from_schema('setting_schema')
# Use any schema from your execution order:
tool.run_from_schema('characters_schema') # Starts from characters onward
tool.run_from_schema('relationships_schema') # Starts from relationships onward
tool.run_from_schema('escalation_schema') # Starts from escalation onwardAlternative programmatic usage:
from Narra import ContentGenerationTool
tool = ContentGenerationTool('.')
tool.run_from_schema('setting_schema') # Run complete pipelineLLMs generate content linearly, making it difficult to create complex narratives with hidden plans, foreshadowing, and interconnected plot elements that real writers develop through careful planning.
Narra addresses this by:
- Schema Decomposition: Breaking narratives into logical components (setting, characters, plot points)
- Sequential Dependencies: Each schema builds upon previous outputs using
@includedirectives - Leverage-First Generation: High-impact details are established first, then refined through subsequent schemas
- Cross-Referencing: Later schemas can reference and expand upon earlier generated content
setting_schema β core_incident_schema β characters_schema β relationships_schema
β β β β
Workplace Tension Triggering Event Psychological Depth Hidden Alliances
β β β β
secrets_schema β escalation_schema β clues_schema β confrontations_schema
β β β β
Personal Stakes Building Paranoia Evidence Trails Breaking Points
β β β β
revelation_schema β aftermath_schema
β β
Truth Unveiled Consequences
- SchemaManager: Loads and parses schema templates with metadata
- SchemaExecutor: Processes include directives and executes LLM calls
- DriveStorageManager: Handles content persistence and cross-referencing
- ContentGenerationTool: Orchestrates the complete pipeline
schemas/ # Schema template definitions
βββ setting_schema.txt
βββ core_incident_schema.txt
βββ characters_schema.txt
βββ relationships_schema.txt
βββ secrets_schema.txt
βββ escalation_schema.txt
βββ clues_schema.txt
βββ confrontations_schema.txt
βββ revelation_schema.txt
βββ aftermath_schema.txt
content/ # Generated markdown outputs (included for demo)
βββ setting_content.md
βββ core_incident_content.md
βββ characters_content.md
βββ relationships_content.md
βββ secrets_content.md
βββ escalation_content.md
βββ clues_content.md
βββ confrontations_content.md
βββ revelation_content.md
βββ aftermath_content.md
docs/ # Documentation
βββ app_overview.md # Detailed architecture guide
The included schemas demonstrate Narra's approach with a complete workplace psychological thriller generation system:
- Setting: Establishes workplace environment and inherent tensions
- Core Incident: The triggering event that sets paranoia in motion
- Characters: Deep psychological profiles with hidden motives
- Relationships: Complex workplace dynamics and secret alliances
- Secrets: Personal vulnerabilities that raise stakes
- Escalation: Building paranoia and suspicious behavior
- Clues: Ambiguous evidence and digital breadcrumbs
- Confrontations: Key conflicts and character breakdowns
- Revelation: The truth behind the psychological manipulation
- Aftermath: Character consequences and emotional fallout
Important: You must create your own schemas before using Narra. The framework does not generate content without properly defined schema files.
Every schema file follows this structure:
# Metadata
Max tokens: 1024 # Token limit for this generation
Temperature: 0.8 # Creativity level (0.0-1.0)
Model: gpt-4o # OpenAI model to use
# Your generation instructions
Generate compelling character backgrounds that establish...
@include {setting_content} # Reference previous schema output
## Use this schema:
~~~
## Character Profile:
Name: {character_name}
Role: {character_role}
...
~~~
---
### Example:
~~~
## Character Profile:
Name: Dr. Sarah Chen
Role: Marine biologist
~~~
Narra's power comes from starting with highly leveraged details that scaffold future content generation:
-
Start with Foundation Elements: Begin with schemas that establish the most influential aspects of your narrative
- Setting: Creates atmosphere and constraints for all future content
- Core Characters: Psychological profiles that drive plot decisions
- Central Conflict: The engine that powers narrative tension
-
Build Increasing Definition: Use subsequent schemas to flesh out details
- Character Relationships: How foundation characters interact
- Plot Complications: Events that test established character motivations
- Resolution Elements: Outcomes that feel inevitable given the foundation
-
Cross-Reference Strategically: Later schemas should
@includeearlier content to:- Maintain consistency with established facts
- Build upon character motivations and relationships
- Create callbacks and foreshadowing
1. setting_schema β Establishes workplace atmosphere and constraints
2. core_incident_schema β Creates triggering event that drives all paranoia
3. characters_schema β Psychological foundation for all character actions
4. relationships_schema β Complex dynamics that amplify tensions
5. secrets_schema β Personal stakes that make characters vulnerable
6. escalation_schema β Building paranoia leverages established secrets
7. clues_schema β Evidence trails that reflect character psychology
8. confrontations_schema β Conflicts inevitable given established dynamics
9. revelation_schema β Truth that explains all previous suspicious behavior
10. aftermath_schema β Consequences that feel earned from foundation
Narra can be extended to any narrative domain:
- World-building β Character origins β Political tensions β Quest catalysts
- Market context β Stakeholder analysis β Problem progression β Solution development
- Concept introduction β Complexity building β Real-world applications
- Design Schema Sequence: Map logical progression from highest to lowest leverage
- Create Schema Files: Place
.txtfiles inschemas/directory with proper metadata - Define Dependencies: Set up
@includedirectives to reference previous content - Configure Execution Order:
β οΈ Currently requires manual code editing
For now, you must manually edit the execution_order array in Narra.py:
class ContentGenerationTool:
def __init__(self, base_drive_path):
# ... other code ...
# Edit this array to match your schema sequence:
self.execution_order = [
"your_foundation_schema",
"your_character_schema",
"your_conflict_schema",
"your_resolution_schema"
]Future Enhancement: A user-friendly GUI for managing execution order is planned for future releases.
Each schema file contains:
# Metadata
Max tokens: 1024
Temperature: 0.8
Model: gpt-4o
# Content Template
Your generation instructions here...
@include {previous_schema_content}
## Use this schema:
~~~
## Your Content Section:
{your_content_fields}
## Evaluation:
1. Identify the single biggest flaw or weak point in the above content.
2. Pinpoint any inconsistency or clichΓ© that undermines tension.
3. Rewrite the content above, incorporating fixes for the identified flaws:
## Revised Content:
{revised_content}
~~~
---
### Example:
~~~
## Setup - Workplace Setting:
The setting is: A high-pressure tech startup with glass-walled offices...
## Evaluation:
1. Identify the single biggest flaw or weak point in the above content.
- The concept feels generic and lacks specific tension-building details.
2. Pinpoint any inconsistency or clichΓ© that undermines tension.
- Glass-walled offices are overused in workplace thrillers.
3. Rewrite the content above, incorporating fixes for the identified flaws:
## Revised Content:
The setting is: A boutique consulting firm where employees work in cramped cubicles under flickering fluorescent lights, while senior partners monitor productivity through mandatory screen-sharing software that tracks every keystroke and website visit.
~~~
Key Innovation: The evaluation system forces the AI to critique and actually rewrite content, ensuring subsequent schemas receive polished, final material rather than rough drafts.
- App Overview: Comprehensive technical documentation
- Schema Examples: See
schemas/directory for templates - Generated Content: Examples in
content/(create by running the tool)
- Fork the repository
- Create a feature branch
- Add new schemas or enhance the framework
- Submit a pull request
MIT License - see LICENSE file for details