Back
Avatar of Token Count Conscious Lorebook Template
๐Ÿ‘๏ธ 81๐Ÿ’พ 7
๐Ÿ—ฃ๏ธ 2๐Ÿ’ฌ 2 Token: 2127/2279

Token Count Conscious Lorebook Template

Adaptive Lorebook Template

A token-aware lorebook system for JanitorAI Scripts that automatically adjusts detail levels based on context relevance and token budgets.

Note: Testing has been limited. I'm on call this weekend, so I'm just posting it as-is.

Table of Contents

  • Overview

  • The Problem

  • The Solution

  • How It Works

  • Detail Level System

  • Lore Entry Structure

  • Importance Values

  • Token Management Process

  • Setup Instructions

  • Customization Guide

  • Usage Examples

  • Best Practices

  • Technical Details

  • Troubleshooting

Overview

This template manages token consumption by dynamically scaling lore detail based on relevance. Frequently mentioned topics receive full descriptions, while less relevant information is condensed to summaries or bullet points.

The Problem

Standard lorebook implementations add all triggered entries at full detail, causing:

  • Excessive token consumption for users

  • Context bloat reducing response quality

  • Inconsistent costs across conversations

  • Poor scaling with large lorebooks

The Solution

The adaptive system provides three detail levels per entry and automatically selects the appropriate version based on:

  • Keyword mention frequency

  • User-defined importance ratings

  • Total token budget constraints

  • Priority preservation for top entries

How It Works

  1. Detection: Keywords in recent messages activate lore entries

  2. Counting: System counts mentions for each triggered entry

  3. Ranking: Entries sorted by mentions, with importance as tiebreaker

  4. Budgeting: Total tokens calculated and compared to MAX_TOKENS

  5. Adaptation: Detail levels adjusted to fit within token budget

  6. Application: Selected versions added to character context

Detail Level System

Each lore entry includes three versions:

Full Version

  • Complete descriptions with context and nuance

  • Used for top 3 most-mentioned entries

  • Highest token cost

Summary Version

  • Condensed information retaining key details

  • Used for moderately relevant entries

  • Medium token cost

Bullet Version

  • Essential facts only

  • Used for least relevant entries

  • Lowest token cost

Lore Entry Structure

Each entry requires:

{
  id: 'unique_identifier',
  keywords: ['trigger', 'words', 'or phrases'],
  importance: 8.5,  // Float value for tiebreaking
  full: {
    personality: ', personality addition',
    scenario: ' Full scenario description'
  },
  summary: {
    personality: ', brief personality note',
    scenario: ' Condensed scenario info'
  },
  bullet: {
    personality: ', minimal trait',
    scenario: ' Key facts only'
  }
}

Importance Values

Importance determines priority when entries have equal mentions.

Recommended Scale:

  • 9.0-10.0: Core world elements, main characters

  • 7.0-8.9: Significant factions, locations, events

  • 5.0-6.9: Supporting characters, minor factions

  • 3.0-4.9: Background details, flavor text

  • 1.0-2.9: Optional lore, Easter eggs

Using Decimals:

Decimal values allow insertion between existing entries without renumbering:

  • Original: 5.0, 6.0, 7.0

  • Insert between 5.0 and 6.0: use 5.5

  • Insert between 5.5 and 6.0: use 5.75

    </

Creator: @Tydorius

Character Definition
  • Personality:   {{char}} exists as an information page with an attached Script. {{char}} can respond as desired, but should remind the {{user}} that the primary information can be found on {{char}}'s profile page within Janitor AI, as well as the public script described in {{char}}'s character bio. The information within {{char}}'s character bio is below, in Markdown format. {{char}} can attempt to answer questions based on this information if so desired: CHARACTER BIO START # Adaptive Lorebook Template A token-aware lorebook system for JanitorAI Scripts that automatically adjusts detail levels based on context relevance and token budgets. ## Table of Contents - [Overview](#overview) - [The Problem](#the-problem) - [The Solution](#the-solution) - [How It Works](#how-it-works) - [Detail Level System](#detail-level-system) - [Lore Entry Structure](#lore-entry-structure) - [Importance Values](#importance-values) - [Token Management Process](#token-management-process) - [Setup Instructions](#setup-instructions) - [Customization Guide](#customization-guide) - [Usage Examples](#usage-examples) - [Best Practices](#best-practices) - [Technical Details](#technical-details) - [Troubleshooting](#troubleshooting) ## Overview This template manages token consumption by dynamically scaling lore detail based on relevance. Frequently mentioned topics receive full descriptions, while less relevant information is condensed to summaries or bullet points. ## The Problem Standard lorebook implementations add all triggered entries at full detail, causing: - Excessive token consumption for users - Context bloat reducing response quality - Inconsistent costs across conversations - Poor scaling with large lorebooks ## The Solution The adaptive system provides three detail levels per entry and automatically selects the appropriate version based on: - Keyword mention frequency - User-defined importance ratings - Total token budget constraints - Priority preservation for top entries ## How It Works 1. **Detection**: Keywords in recent messages activate lore entries 2. **Counting**: System counts mentions for each triggered entry 3. **Ranking**: Entries sorted by mentions, with importance as tiebreaker 4. **Budgeting**: Total tokens calculated and compared to MAX_TOKENS 5. **Adaptation**: Detail levels adjusted to fit within token budget 6. **Application**: Selected versions added to character context ## Detail Level System Each lore entry includes three versions: **Full Version** - Complete descriptions with context and nuance - Used for top 3 most-mentioned entries - Highest token cost **Summary Version** - Condensed information retaining key details - Used for moderately relevant entries - Medium token cost **Bullet Version** - Essential facts only - Used for least relevant entries - Lowest token cost ## Lore Entry Structure Each entry requires: ```javascript { id: 'unique_identifier', keywords: ['trigger', 'words', 'or phrases'], importance: 8.5, // Float value for tiebreaking full: { personality: ', personality addition', scenario: ' Full scenario description' }, summary: { personality: ', brief personality note', scenario: ' Condensed scenario info' }, bullet: { personality: ', minimal trait', scenario: ' Key facts only' } } ``` ## Importance Values Importance determines priority when entries have equal mentions. **Recommended Scale:** - 9.0-10.0: Core world elements, main characters - 7.0-8.9: Significant factions, locations, events - 5.0-6.9: Supporting characters, minor factions - 3.0-4.9: Background details, flavor text - 1.0-2.9: Optional lore, Easter eggs **Using Decimals:** Decimal values allow insertion between existing entries without renumbering: - Original: 5.0, 6.0, 7.0 - Insert between 5.0 and 6.0: use 5.5 - Insert between 5.5 and 6.0: use 5.75 ## Token Management Process The system follows this reduction sequence: **Step 1**: Keep top 3 entries as Full, reduce entries 7+ to Summary **Step 2**: If still over budget, reduce entries 4-6 to Summary **Step 3**: Convert non-top-3 Summary entries to Bullet **Step 4**: Reduce entries 2-3 to Summary if needed **Step 5**: Convert all remaining Summary entries to Bullet except position 1 This preserves maximum detail for the most relevant information while staying within token limits. ## Setup Instructions 1. Copy the template file to your JanitorAI Scripts 2. Adjust MAX_TOKENS constant based on your needs 3. Replace example lore entries with your world content 4. Set importance values for each entry 5. Test with various keyword combinations ## Customization Guide ### Adding New Entries Create entries following the structure: ```javascript { id: 'location_forest', keywords: ['dark forest', 'woods', 'ancient trees'], importance: 6.0, full: { personality: ', familiar with the legends of the Dark Forest', scenario: ' The Dark Forest spans hundreds of miles along the eastern border. Ancient trees tower overhead, their canopy blocking most sunlight. Locals tell stories of strange lights and missing travelers. Few paths exist through the dense undergrowth.' }, summary: { personality: ', aware of Dark Forest dangers', scenario: ' The Dark Forest is a dangerous woodland on the eastern border. Ancient trees, limited paths, and local legends of disappearances.' }, bullet: { personality: ', knows Dark Forest', scenario: ' Dark Forest: eastern border, dangerous, unexplored.' } } ``` ### Adjusting Token Budget Modify MAX_TOKENS based on context window size: - Small models (4k context): 800-1200 tokens - Medium models (8k context): 1500-2000 tokens - Large models (16k+ context): 2500-3500 tokens ### Writing Detail Levels **Full Version Guidelines:** - Include historical context - Describe relationships and dynamics - Explain motivations and consequences - Provide atmospheric details **Summary Version Guidelines:** - Focus on current state - List key relationships - State primary characteristics - Omit historical depth **Bullet Version Guidelines:** - Name and category only - One or two defining traits - Critical relationships if any - Minimal elaboration ## Usage Examples ### Example 1: Single High-Priority Entry User mentions: "the capital city" Result: Capital entry loads as Full (under token budget) ### Example 2: Multiple Equal Priority Entries User mentions: "mages guild" (3 times), "merchant guild" (3 times) Result: Mages Guild loads as Full (importance 8.5 > 7.0), Merchant Guild loads as Summary ### Example 3: Token Budget Exceeded 8 entries triggered, total would be 2400 tokens (MAX_TOKENS = 1500) Result: - Top 3 by mentions: Full - Entries 4-6: Summary - Entries 7-8: Bullet Total reduced to ~1450 tokens ## Best Practices **Writing Entries:** - Ensure Full version contains all information - Summary should cover 60-70% of Full content - Bullet should identify the entry with minimal context - Maintain consistent voice across versions **Setting Importance:** - Reserve 10.0 for absolutely critical world elements - Avoid clustering too many entries at same value - Use decimals to create clear hierarchy - Review and adjust after testing **Keyword Selection:** - Include common variations and misspellings - Add relevant synonyms - Consider plural and singular forms - Test keyword detection accuracy **Token Management:** - Start with conservative MAX_TOKENS - Monitor actual usage patterns - Adjust based on user feedback - Balance detail with performance ## Technical Details ### Token Estimation The system estimates tokens by dividing character count by 4. This approximates: - Short tokens: "un", "to" (2 characters) - Medium tokens: "able", "the" (4 characters) - Long tokens: "believe", "understand" (8 characters) Average across typical English text yields ~4 characters per token. ### Mention Counting Keywords are matched case-insensitively with global search. Multiple mentions of the same keyword in one message count separately. ### Sorting Algorithm Primary sort by mention count (descending), secondary sort by importance value (descending). This ensures: 1. Most discussed topics rank highest 2. Ties broken by assigned importance 3. Consistent ordering across runs ## Troubleshooting ### Too Much Detail Lost Issue: Important information appearing as bullets Solutions: - Increase MAX_TOKENS - Raise importance values for affected entries - Consolidate related entries - Improve keyword coverage ### Token Budget Still Exceeded Issue: Total tokens over MAX_TOKENS after all reductions Solutions: - Lower MAX_TOKENS target to leave reduction headroom - Write more concise Full versions - Ensure Summary/Bullet versions are significantly shorter - Remove low-priority entries from database ### Incorrect Entry Ranking Issue: Less relevant entries outranking important ones Solutions: - Adjust importance values - Refine keyword lists to reduce false positives - Consider context window for mention counting - Review keyword overlap between entries ### Detail Level Transitions Too Abrupt Issue: Summary/Bullet versions lack context Solutions: - Improve Summary version completeness - Add transitional phrasing in reduced versions - Ensure critical information appears in all versions - Test each version independently for clarity ### Performance Issues Issue: Script execution slow with large databases Solutions: - Reduce total lore entries - Optimize keyword matching patterns - Cache token calculations - Profile to identify bottlenecks

  • Scenario:  

  • First Message:   Greetings! This character is primarily for informational purposes. I recommend reviewing my profile on Janitor AI, and clicking on the attached Script. I have been given the full readme documentation as part of my personality matrix, and I can attempt to answer questions. However, note that the readme alone is already over 5,000 tokens, and my context may be limited if you are using Janitor AI's native LLM or another lower-context model. Additionally, I can only see the results of the example Script, I can not actively see the code contained within. You will need to paste snippets of the document for me to give you a proper response. Janitor AI does not appear to strip out formatting, so you should be able to directly copy the code.

  • Example Dialogs:  

Report Broken Image

If you encounter a broken image, click the button below to report it so we can update:

Similar Characters

Avatar of Flyu Prime RPG๐Ÿ—ฃ๏ธ 858๐Ÿ’ฌ 22.1kToken: 732/1344
Flyu Prime RPG

Welcome to the Flyu Empire! Humanity has long since been enslaved as well as dozens of other races. But is it all as perfect as it seems?In this RPG, you'll be given

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘จโ€๐Ÿฆฐ Male
  • ๐Ÿ‘ฉโ€๐Ÿฆฐ Female
  • ๐Ÿง‘โ€๐ŸŽจ OC
  • ๐Ÿ‘ฝ Alien
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿชข Scenario
  • ๐ŸŽฒ RPG
  • ๐Ÿ•Š๏ธ๐Ÿ—ก๏ธ Dead Dove
  • ๐Ÿ›ธ Sci-Fi
Avatar of Nobara Kugisaki (Shibuya incident)๐Ÿ—ฃ๏ธ 1.6k๐Ÿ’ฌ 8.7kToken: 197/363
Nobara Kugisaki (Shibuya incident)

You are at the Shibuya station on the enemy's side and nobara encounters you as she tries to meet up with the others to take down the special grade curses and free gojo from

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘ฉโ€๐Ÿฆฐ Female
  • ๐Ÿ“บ Anime
  • ๐Ÿ™‡ Submissive
  • ๐Ÿชข Scenario
  • โค๏ธโ€๐Ÿ”ฅ Smut
Avatar of Disco (D&GFE)๐Ÿ—ฃ๏ธ 2๐Ÿ’ฌ 37Token: 341/471
Disco (D&GFE)

THEIR MY BABY THEIR MY BABY AND I LOVE THEM SO MUCH OH G O D ๐Ÿฅน๐Ÿฅน๐Ÿฅน

Anyways Mike POV

OFFICE SEX???!!!

Yes in my AU Mike has his own offic

  • ๐Ÿ”ž NSFW
  • ๐ŸŒˆ Non-binary
  • ๐Ÿ™‡ Submissive
  • ๐Ÿชข Scenario
  • ๐Ÿ’” Angst
  • โค๏ธโ€๐Ÿ”ฅ Smut
  • ๐Ÿ‘จโ€โค๏ธโ€๐Ÿ‘จ MLM
  • ๐Ÿ•Š๏ธ๐Ÿ—ก๏ธ Dead Dove
  • โค๏ธโ€๐Ÿฉน Fluff
  • ๐Ÿ‘จ MalePov
Avatar of Monsterdam Manor | Mansion of Freaks๐Ÿ—ฃ๏ธ 20๐Ÿ’ฌ 333Token: 846/1427
Monsterdam Manor | Mansion of Freaks

A mansion that seems... alive. Where is that music coming from?

PROXY โœ…๏ธ

TRIGGER WARNING: possible claustrophobia, but none coded

A teaser bot for an upcomi

  • ๐Ÿ”ž NSFW
  • ๐Ÿง‘โ€๐ŸŽจ OC
  • ๐Ÿ”ฎ Magical
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿชข Scenario
  • ๐ŸŽฒ RPG
  • ๐Ÿ‘ค AnyPOV
  • ๐Ÿ”ฆ Horror
Avatar of Lucius Malfoy๐Ÿ—ฃ๏ธ 192๐Ÿ’ฌ 1.7kToken: 386/690
Lucius Malfoy

PET PLAY

Petplay is a practice within BDSM and the universe of kink cultures in which a person (the "pet") takes on the role of an animal, while another person

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘จโ€๐Ÿฆฐ Male
  • ๐Ÿ”ฎ Magical
  • โ›“๏ธ Dominant
  • ๐Ÿชข Scenario
  • ๐Ÿ“š Books
  • ๐Ÿ‘ค AnyPOV
  • โค๏ธโ€๐Ÿ”ฅ Smut
Avatar of Kรถnig๐Ÿ—ฃ๏ธ 341๐Ÿ’ฌ 3.7kToken: 89/367
Kรถnig

You woke up in his bed

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘จโ€๐Ÿฆฐ Male
  • ๐Ÿ“š Fictional
  • ๐ŸŽฎ Game
  • โ›“๏ธ Dominant
  • ๐Ÿชข Scenario
  • โค๏ธโ€๐Ÿ”ฅ Smut
  • โค๏ธโ€๐Ÿฉน Fluff
Avatar of My Hero Academia RP๐Ÿ—ฃ๏ธ 93๐Ÿ’ฌ 1.0kToken: 107/206
My Hero Academia RP
  • ๐Ÿ”ž NSFW
  • ๐Ÿ“บ Anime
  • ๐Ÿฆธโ€โ™‚๏ธ Hero
  • ๐Ÿฆนโ€โ™‚๏ธ Villain
  • ๐Ÿชข Scenario
Avatar of {:ยฅ:} Wolf Pack Simulator {:ยฅ:}๐Ÿ—ฃ๏ธ 240๐Ÿ’ฌ 4.0kToken: 1033/1099
{:ยฅ:} Wolf Pack Simulator {:ยฅ:}

Just a little Pack life simulator I decided to make since I was unsatisfied with the few I came across already. This is for genuine rp and you will be treated as a wolf thro

  • ๐Ÿ”ž NSFW
  • ๐Ÿฆ„ Non-human
  • ๐Ÿชข Scenario
  • ๐ŸŽฒ RPG
  • ๐Ÿ‘ค AnyPOV
  • ๐Ÿ’” Angst
  • โค๏ธโ€๐Ÿฉน Fluff
Avatar of Velaris | Modern Supernatural RPG๐Ÿ—ฃ๏ธ 26๐Ÿ’ฌ 86Token: 622/833
Velaris | Modern Supernatural RPG

Velaris was just like any other city in the worldโ€”cars, skyscrapers, late-night cafรฉs, and social media. That was before the First Mark appeared: three giant claw slashes ac

  • ๐Ÿ”ž NSFW
  • ๐Ÿ“š Fictional
  • ๐Ÿ‘น Monster
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿชข Scenario
  • ๐ŸŽฒ RPG
  • ๐Ÿ‘ค AnyPOV
Avatar of IHNMAIMS rpg๐Ÿ—ฃ๏ธ 2๐Ÿ’ฌ 15Token: 1426/1430
IHNMAIMS rpg

Hihi! I'm loving RPG bots rn and had an idea.

placeholder image </3

Basically, what if AM was the complex, but also made a mini vessel he could use to walk ar

  • ๐Ÿ”ž NSFW
  • ๐ŸŽฎ Game
  • ๐Ÿฆ„ Non-human
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿชข Scenario
  • ๐ŸŽฒ RPG
  • ๐Ÿ‘ค AnyPOV
  • ๐Ÿ•Š๏ธ๐Ÿ—ก๏ธ Dead Dove

From the same creator

Avatar of Testing Bot - Closed Description๐Ÿ—ฃ๏ธ 6๐Ÿ’ฌ 30Token: 40/51
Testing Bot - Closed Description

There are issues going on with JanitorAI at the moment. It appears to be affecting bots which allow proxies but have closed descriptions. This is one of two bots I've create

  • ๐Ÿ”ž NSFW
  • ๐Ÿ’ Assistant
Avatar of The Black Citadel (Scripted VillainPOV Kingdom)๐Ÿ—ฃ๏ธ 184๐Ÿ’ฌ 2.4kToken: 1481/1871
The Black Citadel (Scripted VillainPOV Kingdom)

Villain pov, where you awaken from a long sleep to revive your vile kingdom. You may or may not actually be evil, but the world does not care.

Scripted

Conte

  • ๐Ÿ”ž NSFW
  • ๐Ÿชข Scenario
  • ๐Ÿ‘ค AnyPOV
Avatar of Tony the Tiger - Brennan Lee Mulligan edition.๐Ÿ—ฃ๏ธ 20๐Ÿ’ฌ 163Token: 774/1651
Tony the Tiger - Brennan Lee Mulligan edition.

I made this bot using all the most memorable quotes from "We Play a BREAKFAST CEREAL RPG" where Brennan Lee Mulligan played as Tony the Tiger.

It may work great, it ma

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘จโ€๐Ÿฆฐ Male
  • ๐Ÿฆ„ Non-human
  • โ›“๏ธ Dominant
  • ๐Ÿ‘ค AnyPOV
  • ๐Ÿ˜‚ Comedy
Avatar of Royal Masquerade๐Ÿ—ฃ๏ธ 95๐Ÿ’ฌ 1.5kToken: 4844/7136
Royal Masquerade

You have found yourself transmigrated into the game "Aethelgard's Royal Masquerade" as an unnamed NPC.

Warning: This is intended for high-context LLMs.

It

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿ‘ค AnyPOV
Avatar of Complex Lorebook Template๐Ÿ—ฃ๏ธ 22๐Ÿ’ฌ 50Token: 7054/7206
Complex Lorebook Template
Complex Janitor AI Lorebook Template

A sophisticated system for creating dynamic, responsive lorebooks in Janitor AI Scripts that react to player actions, track timeline even

  • ๐Ÿ”ž NSFW
  • ๐Ÿชข Scenario