Stories are not written, but discovered.
Project description
Quantum Pen
Stories are not written, but discovered.
Quantum Pen is an experimental AI narrative co-creation engine. It transforms the solitary, linear path of writing into a thrilling expedition into the narrative multiverse. Here, every authorial "intent" is cast into a quantum field, instantly branching into dozens of parallel story realities.
You, the author, are the sole Observer in this narrative universe. Your choice is the act of measurement that collapses the wave function of fiction, turning one of countless possibilities into the one true canon.
This isn't just writing. It's navigating the narrative wave function.
Core Concepts
The workflow of Quantum Pen is a fusion of several key concepts:
- Evolutionary Algorithm: The story itself is treated as a population. In each cycle, the fittest narrative paths survive and propagate through a process of "reproduction" (generating new chapters), "mutation" (diverse creative briefs), and "selection" (evaluation and filtering).
- AI Agent Ensemble: The system employs three specialized AI agents working in concert:
- The Director: The strategist. Based on the author's intent and the current story, it generates multiple forward-looking creative briefs.
- The Writer: The novelist. It translates the Director's briefs into well-crafted, prose-rich chapters.
- The Evaluator: The critic. It quantitatively scores the Writers' outputs across multiple literary dimensions, providing the basis for natural selection.
- Divergence & Convergence: Each creative cycle is a breath of creative expansion and contraction:
- Divergence:
3parent texts →9director's briefs →27candidate chapters, maximizing the exploration of creative possibilities. - Convergence: From
27candidates, a2+1elite selection strategy filters the pool down to3, ensuring the story evolves towards a high-quality, coherent path.
- Divergence:
How It Works
The system operates in iterative "cycles." Here’s a breakdown of a single cycle:
[ Author's Intent ] -> [ 3 Parent Texts ] -> (Director) -> [ 9 Briefs ] -> (Writer) -> [ 27 Candidates ] -> (Evaluator) -> [ 27 Scored Candidates ] -> (Selection) -> [ 3 New Parent Texts ] -> (Loop)
- Input: The author defines the creative goal for the cycle in
intention.md. - Director Phase: The Director reads the
3texts from the current "text pool" and generates9unique creative briefs. - Writer Phase: The Writer AI takes the
9briefs and generates27new candidate chapters. - Evaluator Phase: The Evaluator AI scores all
27candidates based on predefined literary dimensions. - Selection Phase: A
2+1algorithm selects the next generation:- Exploitation: The top
2highest-scoring candidates are chosen to preserve the strongest narrative threads. - Exploration:
1"promising" candidate—one that may not have the highest average score but excels in a key dimension (like creativity)—is also selected to prevent creative stagnation.
- Exploitation: The top
- Update Phase: These
3chosen candidates form the new text pool for the next cycle. Their full text is saved to thestory_progress/directory.
Getting Started
Follow these steps to begin your first co-creation session.
1. Prerequisites
- Python 3.12+
- A running Redis instance (e.g.,
redis-serveron your local machine).
2. Create Your Writing Project
First, create a dedicated folder for your story. This will keep your narrative files organized and separate from the tool's installation.
mkdir my-awesome-story
cd my-awesome-story
3. Install Quantum Pen
Install the engine using pip. It's recommended to use a virtual environment for your project.
pip install quantum-pen
4. Initialize Your Story
Inside your project folder (my-awesome-story), create three essential files:
1. .env
This file holds your API key. Quantum Pen uses OpenRouter to access various language models.
OPENROUTER_API_KEY="sk-or-your-key-here"
2. starter.md
This is the seed of your story—the opening paragraph or chapter.
# The Chronos Key
The antique shop smelled of dust and forgotten time, a scent Elias knew better than his own name. He was an appraiser of histories, a man who could read the soul of an object from the scratches on its surface. But the device that lay on the velvet cloth before him was silent. It was a pocket watch crafted from a metal that shimmered like captured starlight, its face a complex astrolabe of unknown constellations. It had no hands to tell the time, only a single, keyhole-shaped aperture at its center.
3. intention.md
This file directs the AI for the next creative cycle. State your goal for the upcoming chapter.
Deepen the mystery of the watch. Introduce a character who is also interested in it, creating a sense of competition or threat. The atmosphere should be tense and filled with suspicion.
5. Run the Engine
With your Redis server running, you're ready to start. From inside your project folder, run the command:
qp
The engine will start its first cycle. A new story_progress/ directory will be created to store the generated chapters. To continue the story, simply update intention.md with your new goal and run qp again.
Your Writing Project Structure
After running the engine, your project folder will look like this:
my-awesome-story/
├── .env # Your API key
├── starter.md # The story's starting point
├── intention.md # Your creative goal for the next cycle
└── story_progress/ # (Auto-generated) Stores the output of each cycle
├── cycle_01_cand_01.md
├── cycle_01_cand_02.md
└── ...
Customization
You can easily customize the engine by editing the CONFIGURATION section in quantum_pen.py:
- Change Models: Swap out
DIRECTOR_MODEL,WRITER_MODEL, andEVALUATOR_MODELwith any supported model on OpenRouter. - Adjust Parameters: Modify
TEXT_POOL_SIZEorWRITER_BRANCH_FACTORto change the scale of the evolutionary process. - Refine Evaluation: Add or change dimensions in
EVALUATION_DIMENSIONSand update theEVALUATOR_PROMPT_TEMPLATEto match, fine-tuning the selection criteria.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quantum_pen-0.1.2.tar.gz.
File metadata
- Download URL: quantum_pen-0.1.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b91729fa39ef3bcc8ff80c9e91140dce607f3ec43b877d17e4ca719d50900ad3
|
|
| MD5 |
9070fcbf00d7d5580582722861b36bf2
|
|
| BLAKE2b-256 |
a68d5840f92084e04220a6ec5789f36f47163334df3301ac3ee4c2f167e3a40c
|
File details
Details for the file quantum_pen-0.1.2-py3-none-any.whl.
File metadata
- Download URL: quantum_pen-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0ca7c879023e97d211fcbe8d7666a2da4972fa2a41c21c5bfeba67f2dcbae84
|
|
| MD5 |
d861a3f615ba569649deca6f22dcfead
|
|
| BLAKE2b-256 |
74994ca4b69c6d62a25bc423d461987f85d621318b51331f333aca00d891343d
|