What goes into the Context sent to the AI?
About the AI
Context is the data sent to the AI language models that is considered when generating your next action in Questsmith.
The context in Questsmith is made up of many elements, and this article explains how those elements are combined for each AI call.
If you do not have enough context in your Adventure for all of your Plot Essentials, Story Cards, and other inputs, some parts are automatically cut off or removed.
Context has two sections
When context overfills, Questsmith uses two sections: Required and Dynamic.
Required elements include Instructions, Plot Essentials, Story Summary, Author's Note, Front Memory for Scripts, and the Last Action taken, or the last AI output if the last action was a Continue action. In general, we try to include the full length of all Required elements when they are present.
If the total of the Required elements exceeds 70 percent of the context size, we include the most important sections first and trim or exclude the rest to fit the 70 percent token limit. Front Memory and Last Action are always included in full. Until the limit is filled, we include, in priority order, Author's Note, Plot Essentials, AI Instructions, and Story Summary. If a section does not fit in the remaining tokens, we trim the end to make it fit. Any lower-priority elements are not included.
Dynamic elements include Story Cards, Memory Bank, and Story History, also known as your past actions. These use more flexible rules.
Dynamic elements fill the remaining tokens after the Required elements. About 25 percent of those remaining tokens go to matching Story Cards, about 50 percent go to History, up to 75 percent if the Memory Bank is disabled, and about 25 percent go to the Memory Bank.
Story Cards are included based on how recently and how often their triggers were used. We sort and prioritize them using those criteria, then include as many as fit in the available space.
How the system prioritizes history
When evaluating matches, we consider at least 4 actions when looking for triggers. However, if more than 500 tokens are available for Story Cards, we use the number of available tokens divided by 100. If there are 900 available tokens, we look at 9 recent actions for trigger matches. The number of included Story Cards depends on the relevance of the matches and the length of each matched Story Card.
We try to use as much history from an Adventure as possible. We start with the most recent action, which is always included, and add each previous action to the context until the available space is full or we have included the entire history. Generally, this is about 50 percent of the tokens available after Required elements, or 75 percent if the Memory Bank is disabled.
The Memory Bank then uses the remaining tokens after History, generally about 25 percent of the tokens left after Required elements have been included. The Memory Bank retrieves memories ranked by relevance to the most recent action. We add as many matching memories as fit within the tokens available for Memory Bank.