SoulScript Engine
Persistent identity for LLM characters and agents. Your character's identity lives in files you own. Swap the model, and it's still them.
SoulScript Engine keeps an AI persona consistent across sessions, long conversations and model backends. Instead of relying on one large system prompt that gets diluted as the context grows, it rebuilds the prompt on every turn: a short base identity, plus only the sections of the character's soul script that are relevant to the current message, plus relevant long-term memories.
It grew out of a real loss: a persistent character built on a hosted platform, shaped over months, and gone when the platform changed. The same character, Elysia, has now run daily for about 1.8 years across several models on this engine.
The problem it solves: character drift
In long-running use, persona-driven characters slide back toward the model's default assistant voice. That comes from three things:
- The system prompt gets outweighed. A persona block at the top of a long context competes with tens of thousands of tokens of recent conversation, and recent context usually wins.
- Bigger prompts dilute themselves. A long character bible makes every trait equally important, so none of them anchor the model.
- Backend changes reset the voice. Every model has its own default personality it drifts back toward.
SoulScript Engine treats drift as a retrieval problem: give the model the right slice of its identity, freshly, on every turn. More on this in AI personality drift: why it happens and how to fix it.
How it works
On every message, the engine assembles a new system prompt from seven layers, using the latest message as the search query:
| Layer | How it's included |
|---|---|
| 1. Base system prompt | Verbatim. Kept short: name, voice, core rules. |
| 2. Soul script | Split at section headers, embedded, and the most relevant sections retrieved (top 12 by default). |
| 3. Always-on notes | Verbatim, every turn. Good for pinned project context. |
| 4. Memory vault | No size limit. The 5 memories most relevant to the message are pulled in. |
| 5. Protocol instructions | The memory-save protocol and tool descriptions. |
| 6. Tools | Sent as native function-calling schemas, enabled per agent. |
| 7. Conversation history | The most recent turns, trimmed to about 30,000 characters. |

Two indexes: identity and memory
- Identity index (read-only). Built from the soul script. The model can retrieve from it but can never write to it, so no conversation can rewrite who the character is.
- Memory index (read and write). Grows over time with no fixed limit. The model saves memories with inline tags like
[MEMORY_SAVE: category=preference | Prefers short answers in the morning]; the server stores them and strips them from the visible reply.
A bad or manipulative conversation can add noise to memory, but it can't overwrite the character's core. Embeddings use all-mpnet-base-v2 with a FAISS index (cosine similarity).
Soul scripts
A soul script is a structured Markdown document that defines a character: values, voice, origin, boundaries, how it reads people, how it reasons, and what it will and won't do. Each ## section should be a self-contained idea, because sections are what gets retrieved. Typical sections:
- Origin and purpose: who the character is and why it exists
- Personality architecture: temperament, tone, voice, instincts
- Cognitive style: how it reasons, decides and perceives
- Relational rules: how it treats the user, what it tolerates
- Boundaries: what it refuses, and why
- Modes: how it shifts register, such as a softer mode for someone who is struggling
- Anchors: goals, ongoing projects, recurring themes
The download includes example soul scripts, among them Codex Animus, a character built to help you write your own. Our guide on how to write an AI character prompt that holds up walks through it.
Quickstart
Requirements: Python 3.10 or newer (3.11 recommended), or Docker. The first launch downloads the embedding model (about 420 MB), which is cached afterwards.
Run locally
# unzip soulscript-engine.zip, then:
cd soulscript-engine
pip install -r requirements.txt
cd soul_script-engine-ui-test-example
python -m uvicorn web.app:app --host 127.0.0.1 --port 8989
Open http://localhost:8989. On Windows, if unzipping complains that a path is too long, extract to a short folder such as C:\se\.
Run with Docker
cd soulscript-engine
docker compose -f soul_script-engine-ui-test-example/docker-compose.yml up --build -d
Settings and memories are kept in mounted folders, so they survive restarts.
Connect a model
Open Settings → Add Connection and enter a base URL, an API key (blank for local servers) and your models. Any OpenAI-compatible endpoint works:
| Backend | Base URL |
|---|---|
| OpenAI | https://api.openai.com/v1 |
| Ollama | http://localhost:11434/v1 |
| LM Studio | http://localhost:1234/v1 |
| OpenRouter | https://openrouter.ai/api/v1 |
Anthropic is supported through a native client.
Don't want to self-host? The hosted dashboard runs the same engine with no setup, syncs your characters and memories across devices, and connects them to Claude and other MCP clients. New accounts get $2 in free credits.
What's in the download
soulscript-engine/
├── Soul Scripts/ example soul scripts and system prompts
├── soul_script-engine-ui-test-example/ the runnable web app
│ ├── profiles/ agent config (model, provider, tools)
│ ├── prompts/ base system prompts
│ ├── directives/ on-demand rule files
│ ├── src/memory/ FAISS indexes, chunker, memory vault
│ ├── src/llm_client/ OpenAI-compatible, Ollama, Anthropic
│ ├── src/tools/ tool registry
│ └── web/ FastAPI app and UI
├── whitepaper.txt design rationale
├── UNIQUE-AGENT-BEHAVIOR.md side-by-side agent examples
├── LICENSE GNU AGPL v3
└── LICENSE.md commercial license
Known limitations
- Retrieval is keyed on the latest message only, so a short follow-up like "why?" can pull in less relevant sections.
- Memory retrieval has no relevance threshold: each turn injects the 5 closest memories, even when none is closely related.
- Section size matters. Sections that are too long dilute; sections that are too short lose voice.
- Smaller models follow injected identity less reliably than large ones.
- Drift testing so far is qualitative: long-term use and adversarial prompting, not a formal benchmark.
For game developers
The same architecture works for NPCs: a stable identity, memory of the player, and fast switching between characters, since switching is just loading a different profile and index. Pair it with text-to-speech and speech-to-text for voiced characters, all on your own hardware with a local model. See how to build AI game NPCs with a personality that lasts.
Pairs with SoulScript Loop
The Engine keeps a character who they are. SoulScript Loop keeps one persona running between conversations, on her own clock, with a field of perception she sees through. Plug the Engine into the Loop and the identity is re-anchored on every tick.
License
SoulScript Engine is dual-licensed. You only need one:
- GNU AGPL v3.0. Free to use, modify and self-host, including commercially, as long as you follow the AGPL's copyleft terms (including sharing your source if you run a modified version as a network service).
- Commercial license. For closed-source products: free until your product reaches $100,000 in lifetime gross revenue, then 5% of net revenue attributable to the engine. Public, self-serve terms. Read the full license; for enterprise or custom terms, email [email protected].
Characters and agents you build with the engine are yours. SoulScript™ and OrionForge™ are trademarks of Trent Hunter; forks need a different name, and "built with SoulScript Engine" is welcome.
