Skip to content

About

Entity Cards: An extension of LewdLeah's Auto-Cards adding Named Entity Recognition (NER), typed cards, and containerization for AI Dungeon.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

 
 

Repository files navigation

Entity Cards

Entity Cards Hero Banner

LewdLeah's Auto-Cards with Named Entity Recognition (NER)

Engine: Auto-Cards Specification: CSCP v1.2.0 License: MIT

An extension of Auto-Cards by LewdLeah ❤️


Attribution & Acknowledgments

Original Creator: LewdLeah (LewdLeah/Auto-Cards)
All core background automation, turn monitoring, memory summarization and compression, title detection algorithms, and scenario script architecture were designed and built by LewdLeah. Please check out and star the original Auto-Cards repository! ❤️

Entity Cards Fork: Developed by Randy Viosca (@Random_Variable) to extend Auto-Cards with structured Named Entity Recognition (NER), story card containerization, typed card auto-detection, and flexible prompt/response controls.


Overview

Entity Cards is a scenario script for AI Dungeon that builds upon LewdLeah's Auto-Cards engine. While Auto-Cards automatically generates living background lore and summarizes long-term memories, Entity Cards extends this by structuring lore entries into typed Named Entities (Person, Organization, Location, Event, or Thing) using high-density character archetypes, MBTI profiles, and container wrappers.

You can switch between Entity Cards mode and Classic Auto-Cards mode at any time with a single setting or command.


What Entity Cards Adds to Auto-Cards

  • Clean SysConfig & SysTask Categories (v3.0.0): Isolates all system cards out of narrative lore tabs (Person, Location, Organization, Thing, Event):
    • Auto-Cards [OFF|ON] (SysConfig): Persistent master engine controls, cooldowns, manual/auto trigger mode, memory limits, and Entity/Classic mode switcher. Never deleted when disabled; [ON]/[OFF]/[Disabled] badges show status directly in the card list, and deleting the card mid-adventure auto-respawns it from saved state.
    • Entity Cards [OFF|ON] (SysConfig): Persistent companion card for entity presets, container sentinels, and live editable template blocks (Status: Active / Inactive).
    • Auto-Cards Task — do not edit (SysTask): Transient Optimized Context / generation task card, kept separate from lore and automatically deduplicated.
  • Manual Card Trigger Mode (--manual / --scan / --next): Optionally keep passive candidate scanning and memory updates running while disabling automatic mid-story generation (Card Creation Trigger: manual), then inspect ranked candidates via /ec --scan and trigger the top pick on demand with /ec --next.
  • Named Entity Recognition (NER) Schemas: Calibrated YAML schemas for 5 entity categories (Person, Location, Organization, Thing, and Event), designed to fit neatly under AI Dungeon's default 100-token slider in a single turn. Person schemas include 4-letter MBTI profiles for dense psychological grounding in minimal tokens.
  • Model Awareness & Presets: Automatically detects your active AI Dungeon model (info.storyModel.name) and selects the optimal schema tier:
    • Standard (Default): Balanced 5-type YAML schemas for mid-to-large models (DeepSeek, GLM, Gemma, Hearthfire, Equinox).
    • Lite: Ultra-compact schemas (~380 chars) for lightweight models (Fable, Muse, Wayfarer Small).
    • Authoring: Narrative-driven keys (Role:, Secrets:, Scene_Dynamics:, Motives:) for scenario writers.
    • Custom: Automatically activated if you edit any template block inside Configure Entity Cards.
  • Resilient Parsing & Code Fence Stripping: Automatically strips markdown code fences (```yaml, ```, '''yaml, ''') and sentinel markers, normalizing em-dash bullets (— / –) into clean, readable story cards.
  • Automatic Story Card Typing: Automatically extracts the entity category and assigns AI Dungeon's native story card type property (e.g., categorizing as "Person" instead of a generic tag).
  • Story Card Encapsulation / Containers: Optional { Entity: ... } boundary wrappers with ENTITY_BEGIN and ENTITY_END sentinels to keep story card formatting clean and contained.
  • Dynamic Context Header: Automatically replaces "World Lore:" with a customizable header (default "Named Entities (NER):") during context building, without needing manual edits to your Context script tab.
  • Dual Script & Command Aliases: Call either EntityCards(...) or AutoCards(...) in your scenario scripts, and use either /ec or /ac in-game commands.

🧭 Multi-Slot Architecture: Running multiple scripts in your adventure? See the Dynamic Slot Management & Graceful Degradation Guide for how slots coordinate, self-heal, and gracefully handle being toggled on or off.


In-Game Commands

You can use either /ec or /ac in the AI Dungeon action input bar:

Command Description
/ec Triggers immediate card generation if valid titles exist in recent turns
/ec <Title> Manually directs card generation for a specific title
/ec <Title> -<type> Generates a card with an explicit entity type flag (e.g. /ec Smith -p or /ec -loc Tokyo). Optimizes prompt to only that branch (~80% token savings)!
/ec <Title> / {Details} Generates a card for a title with additional guidance details
/ec -r, --redo <Title> [ -<type> ] Regenerates an existing story card, optionally overriding its type (legacy alias: /ec redo <Title>)
/ec -R, --redo-all Regenerates all automatic story cards (legacy alias: /ec redo all)
/ec -a, --abort, cancel Terminates active card generation or memory compression in progress, resetting cooldowns and clearing task cards
/ec -m, --mode <mode> Switches engine mode: -m entity (NER, YAML schemas) or -m classic (prose prompt, bulleted lists)
/ec -P, --preset <name> Switches YAML schema preset: -P standard, -P lite, -P authoring, or -P custom
/ec --trigger <auto|manual>, --manual, --auto Controls whether new entity cards generate automatically when cooldown hits 0 or only on demand
/ec -s, --scan, --check Lists ranked NER entity candidates detected in recent story history without generating a card
/ec -n, --next Immediately generates a card for the highest-ranked detected candidate (bypasses cooldown)
/ec --header <text> Sets a custom context header (e.g., /ec --header "Codex Entities:")
/ec -i, --info, --diag Displays comprehensive system diagnostics (model, cache, scripts, cooldowns, card counts)
/ec -v, --version Displays active script build version, git commit hash, and build timestamp
/ec -h, --help Displays command help listing and type flag shorthands

(Classic /ac commands remain 100% compatible and functional. Because all options use standard POSIX - and -- flags, character names like "Info", "Mode", "Preset", or "Help" never collide with command flags. Any token enclosed in quotes is strictly protected as a title.)

Explicit Entity Type Flags (-<type>)

When manually generating or redoing a card, you can specify the entity type using -<type> (or --<type>), either before or after the title:

  • Person: -p, -person, -char, -character, -npc, -who
  • Location: -l, -loc, -location, -place, -where
  • Organization: -o, -org, -organization, -faction, -group, -guild
  • Thing: -t, -thing, -item, -object, -what
  • Event: -e, -event, -incident, -when

Examples:

  • /ec Jack -p (or /ec -p Jack)
  • /ec Tokyo City -loc / {A sprawling cyberpunk metropolis}
  • /ec -org Phantom Thieves
  • /ec Holy Grail -item
  • /ec The Great Calamity -e
  • /ec redo Jack -person

Token Optimization: When an entity flag is provided, Entity-Cards dynamically isolates only the single matching JellyFish template branch, discarding the other 4 branches. This reduces the AI prompt from ~2,713 characters (~550 tokens) down to ~640 characters (~130 tokens)—an ~75–80% prompt token reduction while eliminating schema hallucination! Hyphenated names (e.g., Spider-Man or Top-Secret Facility) are safely preserved.

Dialogue & Flame Menu Support: Commands can be typed directly into Story or Do mode, or spoken naturally in Say mode dialogue (e.g. > You say, "/ec -p Molly." or Joe says, "/ec -loc Citadel!"). Punctuation, smart quotes, and dialogue wrappers are automatically stripped.

Specific Card Rejection Diagnostics

When a manual /ec <Title> or /ec -r <Title> command cannot generate a card, Entity Cards explains the exact reason rather than giving a generic error:

  • Trigger Key Collision: If the requested name is already claimed as a trigger keyword on another card (e.g., /ec -p brenner when "Dr. Martin Brenner" uses brenner as a trigger), it reports:
    "brenner" is already used as a trigger key in Story Card "Dr. Martin Brenner"
  • Existing Card Match: If an exact title match or embedded {title: ...} already exists:
    Story Card "Brenner" already exists
  • Active Workpiece: If the card is currently in progress:
    Card generation for "Brenner" is already in progress
  • Pending Queue: If the title is already waiting in the generation queue:
    "Brenner" is already queued in pending generation
  • Reserved System Keywords: System names like entity, inner, or agent are protected:
    "entity" is a reserved system keyword
  • Length & Formatting: Enforces a minimum of 2 characters for manual commands (3 for automatic detection).

Sample Generated Entity Card

Here is an example of a generated Person entity card using the default Standard preset:

{ Entity:
entity: Molly Millions
type: Person
category: Street Samurai
mbti: ISTP - Virtuoso
appearance: Mirrored cybernetic lens implants, black leather jacket, retractable razor blades beneath burgundy nails.
personality: Cynical, calculating, and dryly sarcastic; hypervigilant in social settings.
drive: Survive freelance gigs and settle an old debt with the Chiba syndicate.
connections: Former bodyguard for Tessier-Ashpool; uneasy mercenary partner to the protagonist.
description: A legendary street samurai with cybernetic enhancements who navigates the criminal underworld with razor precision.
}

Persistent Configuration Architecture (SysConfig)

Configuration is cleanly partitioned between two persistent SysConfig story cards (System Modules [ON]/SysTask handle bus/task state separately):

1. "Auto-Cards [OFF|ON]" (type: "SysConfig")

  • > Enable Auto-Cards: Master enable/disable toggle (true/false) without deleting settings
  • > Operating Mode: Toggle between Entity Cards and Classic Auto-Cards
  • > Card Creation Trigger: Toggle between auto (generate when cooldown reaches 0) and manual (score candidates passively; use /ec --scan & /ec --next)
  • > Minimum turns cooldown for new cards: Story progression turns between generations (default 28)
  • > Maximum entry length for new cards: Max character length (700 in Entity mode, 600 in Classic mode)
  • > Pin this config card near the top: Keeps configuration cards accessible
  • > Generate memories for new cards: Memory update monitoring (true/false)
  • > Exclude all-caps from title detection: Prevents false positives from capitalized UI text
  • > Manual commands bypass title filters: Allows explicit /ec and /ac commands to generate common entities, real-world locations, and short character names (true/false, default true)
  • > Filter common entities from auto-detection: Controls whether passive background auto-detection ignores common real-world cities, countries, and planets (true/false, default true)

2. "Entity Cards [OFF|ON]" (type: "SysConfig")

Dedicated to Named Entity Recognition and prompt customization:

  • > Status: Active (when enabled in Entity Cards mode) or Inactive (preserved cleanly when disabled or in Classic mode)
  • > Active Preset: Standard, Lite, Authoring, or Custom
  • > Auto-select preset by model: Automatically adapts schema complexity based on your active AI Dungeon model
  • > Context Header: Custom header replacing "World Lore:" in context (default: "Named Entities (NER):")
  • > Clean prompt on card generation: Strips manual /ec command lines from story text upon submission (true/false, default true)
  • > Progress display: Selects progress display mode: story (inline >>> please select "continue" (50%) <<< banners) or toast (transient state.message toasts)
  • > Live Editable Template Blocks: Edit the card's description to customize prompt schemas directly in-game; editing automatically switches the preset to Custom!

Tip

Multi-Turn Continuation & Response Length:
Setting your in-game Response Length slider to 250+ tokens in AI Dungeon's gameplay settings allows complete Entity Cards to generate in a single turn. With shorter response length settings (e.g. 50–100 tokens), the script seamlessly pauses and prompts you with >>> please select "continue" (X%) <<< to construct the entity template across multiple turns.

During multi-turn generation:

  1. Incomplete YAML fields are cleanly merged across turns while stripping narrative hallucination.
  2. Story prose and NPC monologue scripts (such as Inner-Entity) are automatically paused across VMs, preventing narrative bleed into Continue clicks until the card reaches 100% completion.
  3. Once complete, Entity Cards announces the addition and leaves story narration ready for your next normal player action.

Script Manager Setup (Solo or Multi-Slot — No AID-Getopt Needed)

  • Solo (Entity Cards only): Load Entity Cards (05_w3s9zrrvt) by itself. aid-getopt (v1.2.0) and loadCSCP() are bundled directly inside src/library.js, so zero companion slots are required.
  • Multi-Slot Stack (with Inner Entity or other CSCP scripts):
    • Slot 1: AID-Modules (jHwEbn7_bYGC, v1.2.0)
    • Slots 2 & 3 (either order): Entity Cards (05_w3s9zrrvt, v3.0.0) + Inner Entity (Minds) (bL_qS9DsI5wI, v3.0.0)
  • No AID-Getopt slot required: AID-Getopt is now a developer library only and does not need to be added to your adventure or scenario Script Manager.

Scenario Script Installation Guide

  1. Open the AI Dungeon website on PC (or view as desktop if mobile-only).
  2. Create a new scenario or edit one of your existing scenarios.
  3. Open the DETAILS tab at the top while editing your scenario.
  4. Scroll down to Scripting and toggle ON → Scripts Enabled.
  5. Select EDIT SCRIPTS.

1. Input Tab

Select the Input tab on the left, delete any existing code, and paste:

// Your "Input" tab
const modifier = (text) => {
  // Your other input modifier scripts go here (preferred)
  text = EntityCards("input", text);
  // Your other input modifier scripts go here (alternative)
  return {text};
};
modifier(text);

2. Context Tab

Select the Context tab on the left, delete any existing code, and paste:

// Your "Context" tab
const modifier = (text) => {
  // Your other context modifier scripts go here (preferred)
  [text, stop] = EntityCards("context", text, stop);
  // Your other context modifier scripts go here (alternative)
  return {text, stop};
};
modifier(text);

3. Output Tab

Select the Output tab on the left, delete any existing code, and paste:

// Your "Output" tab
const modifier = (text) => {
  // Your other output modifier scripts go here (preferred)
  text = EntityCards("output", text);
  // Your other output modifier scripts go here (alternative)
  return {text};
};
modifier(text);

4. Library Tab

  1. Select the Library tab on the left and delete all existing code.
  2. Open the full Library code in a new browser tab.
  3. Copy the full code and paste it into your empty Library tab.
  4. Click the yellow SAVE button in the top right corner.

(Note: AutoCards(...) also works identically if your scenario already has Auto-Cards installed—you only need to update the Library tab!)


Permission & License

Entity Cards is open-source and free to use in your own scenarios or scripts. General-purpose usefulness, interoperability, and compatibility are top priorities. You have full permission to use, copy, or modify Entity Cards. Please be respectful of the fact that not everyone wants to use automated cards, and never harass creators about installing scripts. Please enjoy! ❤️


Useful Links

Original Auto-Cards by LewdLeah

Entity Cards by Randy Viosca

About

Entity Cards: An extension of LewdLeah's Auto-Cards adding Named Entity Recognition (NER), typed cards, and containerization for AI Dungeon.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages