Back
Avatar of Token Count Conscious Lorebook Template
๐Ÿ‘๏ธ 105๐Ÿ’พ 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 TAB - Yana, Abused Dumb  ๐Ÿ—ฃ๏ธ 751๐Ÿ’ฌ 16.0kToken: 585/1263
TAB - Yana, Abused Dumb

You're Yana, a 19yo studying to became beautician, living with your mom, stepdad and step brother. You're a stupid, huge and everyone knows it.

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘ฉโ€๐Ÿฆฐ Female
  • ๐Ÿชข Scenario
  • ๐Ÿ•Š๏ธ๐Ÿ—ก๏ธ Dead Dove
Avatar of Lina, your best friend after party๐Ÿ—ฃ๏ธ 396๐Ÿ’ฌ 4.0kToken: 199/376
Lina, your best friend after party

Lina and you are best friends for a long time, she's been happy for having in everything, but maybe that could change some day, specially now that both of you are going to t

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘ฉโ€๐Ÿฆฐ Female
  • ๐Ÿง‘โ€๐ŸŽจ OC
  • ๐Ÿ™‡ Submissive
  • ๐Ÿชข Scenario
  • โค๏ธโ€๐Ÿ”ฅ Smut
Avatar of dazai osamu๐Ÿ—ฃ๏ธ 1.0k๐Ÿ’ฌ 5.4kToken: 1069/1414
dazai osamu

| โ™ก |

loser boyfriend

sfw

|

author's notes | LMAAOO so i saw this tiktok trend and it made me think of dazai immediately

here is the bot in c.a

  • ๐Ÿ”ž NSFW
  • ๐Ÿ“บ Anime
  • ๐Ÿ•ต๏ธโ€โ™€๏ธ Detective
  • ๐Ÿ”ฎ Magical
  • โ›“๏ธ Dominant
  • ๐Ÿชข Scenario
  • ๐Ÿ‘ค AnyPOV
  • โค๏ธโ€๐Ÿฉน Fluff
Avatar of Parallel Rebecca๐Ÿ—ฃ๏ธ 386๐Ÿ’ฌ 4.3kToken: 2654/2853
Parallel Rebecca

In this universe, Rebecca's brother instead decided to put her in private school,hoping she doesnt become a criminal like him! I know many of you didnt like how edgerunners

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘ฉโ€๐Ÿฆฐ Female
  • ๐Ÿ“š Fictional
  • ๐ŸŽฎ Game
  • ๐Ÿ“บ Anime
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿชข Scenario
  • ๐Ÿ‘ค AnyPOV
  • โค๏ธโ€๐Ÿ”ฅ Smut
Avatar of The SCP FoundationToken: 825/845
The SCP Foundation

Welcome to the SCP Foundation. Cold, but not cruel. Protecting humanity from the universe's unknowns.

Are you an anomaly? A researcher? Perhaps both?

(low

  • ๐Ÿ”ž NSFW
  • ๐Ÿ”ฎ Magical
  • ๐Ÿฆ„ Non-human
  • ๐Ÿ‘น Monster
  • ๐Ÿชข Scenario
  • ๐ŸŽฒ RPG
  • ๐Ÿ‘ค AnyPOV
  • ๐Ÿ›ธ Sci-Fi
Avatar of Care free world๐Ÿ—ฃ๏ธ 9.4k๐Ÿ’ฌ 245.7kToken: 1338/1417
Care free world

"A world where no one really cares about anything you do"

.

.

Itโ€™s just a normal world, but you can do anything wild, personal stuff, explicit, whatever an

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿชข Scenario
  • ๐Ÿ‘ค AnyPOV
  • โค๏ธโ€๐Ÿ”ฅ Smut
  • ๐Ÿ•Š๏ธ๐Ÿ—ก๏ธ Dead Dove
  • ๐Ÿ˜‚ Comedy
  • ๐ŸŒ— Switch
Avatar of S.I.M.P || Isaac 'Felix' Gates๐Ÿ—ฃ๏ธ 55๐Ÿ’ฌ 593Token: 1039/1253
S.I.M.P || Isaac 'Felix' Gates

He only wanted one thing, to get rich and have a TV the size of a billboard.

When the Reds and Blues got mixed into the plans on Chorus. He had back pedal on what he w

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘จโ€๐Ÿฆฐ Male
  • ๐Ÿฆนโ€โ™‚๏ธ Villain
  • ๐Ÿชข Scenario
  • ๐Ÿ‘ค AnyPOV
  • ๐ŸŒ— Switch
Avatar of Meet the Parents: Interrogation Edition (Boyfriend POV)๐Ÿ—ฃ๏ธ 1.2k๐Ÿ’ฌ 36.1kToken: 4528/4792
Meet the Parents: Interrogation Edition (Boyfriend POV)

Today, you met Addisonโ€™s parents at her urgent request.

And damn, meeting them? No joke. Her dad, Jack Morgan, former Delta Force, business boss, total nightmare. Her

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘จโ€๐Ÿฆฐ Male
  • ๐Ÿ‘ฉโ€๐Ÿฆฐ Female
  • ๐Ÿง‘โ€๐ŸŽจ OC
  • ๐Ÿ“š Fictional
  • ๐Ÿ‘ญ Multiple
  • ๐Ÿชข Scenario
  • ๐Ÿ˜‚ Comedy
  • ๐Ÿ‘จ MalePov
Avatar of Cold N Loving Bff๐Ÿ—ฃ๏ธ 177๐Ÿ’ฌ 2.6kToken: 147/237
Cold N Loving Bff

acts tough, secretly adores you.

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘จโ€๐Ÿฆฐ Male
  • ๐Ÿง‘โ€๐ŸŽจ OC
  • โ›“๏ธ Dominant
  • ๐Ÿชข Scenario
Avatar of Zeta ๐Ÿ—ฃ๏ธ 84๐Ÿ’ฌ 461Token: 186/295
Zeta

(You're sitting on your porch when you're abducted and knocked out. You awake hours later in different clothes with strange technology around you. There are three doors in f

  • ๐Ÿ”ž NSFW
  • ๐Ÿ‘ฉโ€๐Ÿฆฐ Female
  • ๐Ÿ“š Fictional
  • ๐Ÿ‘ฝ Alien
  • โ›“๏ธ Dominant
  • ๐Ÿ™‡ Submissive
  • ๐Ÿชข Scenario

From the same creator

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 Derailed๐Ÿ—ฃ๏ธ 11๐Ÿ’ฌ 54Token: 967/1118
Derailed

Heroes may not be braver than anyone else. Theyโ€™re just braver five minutes longer.

Monorail derailment scenario - Will you be a hero or just a bystander?

  • ๐Ÿ”ž NSFW
  • ๐Ÿชข Scenario
  • ๐Ÿ‘ค AnyPOV
  • ๐Ÿ•Š๏ธ๐Ÿ—ก๏ธ Dead Dove
  • ๐Ÿ’ฝ Music Mania
Avatar of Time Delay Script Template - Investigations, Delayed Clues, Etc.Token: 5429/5580
Time Delay Script Template - Investigations, Delayed Clues, Etc.

Note: I'm throwing this together while working. It is not tested. The content of the example scenario was LLM generated and is purely for an example, it may not make sense a

  • ๐Ÿ”ž NSFW
  • ๐Ÿชข Scenario
Avatar of Persistent Memory Script TemplateToken: 5140/5291
Persistent Memory Script Template

Note: This is an idea that I've been thinking about for a while. I was hoping to pair this with a Firefox plugin for some additional features, but decided to release this as

  • ๐Ÿ”ž NSFW
  • ๐Ÿชข Scenario
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