Skip to content

Commit 7d8c8a2

Browse files
author
prima
committed
feat: Added experimental running memory support (autogen memory) and tweaked WI generation for agent
1 parent b67ffa2 commit 7d8c8a2

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

klite.embd

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25908,13 +25908,13 @@ else
2590825908
"description": "Overwrites an entry describing an entity. The information is stored under a unique identifier. This information is included when certain keywords are mentioned. This does not show the information to the user.",
2590925909
"args": {
2591025910
"uniqueIdentifier": "<unique identifier (such as a characters name, location etc)>",
25911-
"text": "<descriptive text which by itself provides all needed information to define the entity>",
2591225911
"keywords": {
25913-
description: "<keywords to help with searching>",
25912+
description: "<keywords to help with searching - at least one must be provided>",
2591425913
type: "array",
2591525914
itemType: "string",
2591625915
minItems: 1,
25917-
}
25916+
},
25917+
"text": "<descriptive text which by itself provides all needed information to define the entity>"
2591825918
},
2591925919
"enabled": true,
2592025920
"executor": (action) => {
@@ -25976,7 +25976,7 @@ else
2597625976
}
2597725977
},
2597825978
{
25979-
"name": "overwrite_current_state_response",
25979+
"name": "overwrite_current_state_response",
2598025980
"description": "The current state can be overwritten by the overwrite_current_state command. Providing a JSON object to this function will enforce a particular response format when overriding the state.",
2598125981
"args": {
2598225982
"json": "<format which should be used when overwriting the current state>"
@@ -27208,6 +27208,7 @@ let checkFinalThoughtsPrompt = `Action: {"command":{"name":"thought","args":{"me
2720827208
document.getElementById("agentCOTRepeatsMax").value = localsettings.agentCOTRepeatsMax;
2720927209
document.getElementById("agentCOTRepeatsMaxnumeric").value = localsettings.agentCOTRepeatsMax;
2721027210
document.getElementById("disableSaveCompressionLocally").checked = localsettings.disableSaveCompressionLocally;
27211+
document.getElementById("enableRunningMemory").checked = localsettings.enableRunningMemory;
2721127212
}
2721227213

2721327214
confirm_settings = () => {
@@ -27216,6 +27217,7 @@ let checkFinalThoughtsPrompt = `Action: {"command":{"name":"thought","args":{"me
2721627217
localsettings.agentCOTMax = document.getElementById("agentCOTMax").value;
2721727218
localsettings.agentCOTRepeatsMax = document.getElementById("agentCOTRepeatsMax").value;
2721827219
localsettings.disableSaveCompressionLocally = (document.getElementById("disableSaveCompressionLocally").checked ? true : false);
27220+
localsettings.enableRunningMemory = (document.getElementById("enableRunningMemory").checked ? true : false);
2721927221
originalConfirmSettings()
2722027222
}
2722127223

@@ -27421,6 +27423,10 @@ let checkFinalThoughtsPrompt = `Action: {"command":{"name":"thought","args":{"me
2742127423
{
2742227424
localsettings.disableSaveCompressionLocally = true
2742327425
}
27426+
if (localsettings?.enableRunningMemory == undefined)
27427+
{
27428+
localsettings.enableRunningMemory = false
27429+
}
2742427430

2742527431
let createSettingElemBool = (inputElemId, labelTitle, labelText) => {
2742627432
let settingLabelElem = document.createElement("div")
@@ -27525,6 +27531,9 @@ let checkFinalThoughtsPrompt = `Action: {"command":{"name":"thought","args":{"me
2752527531
settingLabelElem = createSettingElemBool("disableSaveCompressionLocally", "Disables save compression locally", "Disables save compression locally - Improves load / autosave performance with larger saves. The save compression is left enabled for sharing saves or uploading to the main server)")
2752627532
lastSettingContainer.append(settingLabelElem)
2752727533

27534+
settingLabelElem = createSettingElemBool("enableRunningMemory", "Enable running memory", "Enables running memory, an experimental version of autogenerating memory which triggers every time the context length changes by half its maximum. The summaries it generates can be found under world info.")
27535+
lastSettingContainer.append(settingLabelElem)
27536+
2752827537
createStopThinkingButton()
2752927538
})
2753027539

@@ -28157,4 +28166,73 @@ let checkFinalThoughtsPrompt = `Action: {"command":{"name":"thought","args":{"me
2815728166
}
2815828167
}
2815928168
</script>
28169+
<script>
28170+
// Autogenerate running memory mod
28171+
let maxMemories = 5, lastContextLength = concat_gametext(true, "").length, autosummaryInterval = 60 * 1000;
28172+
let updateRunningMemory = async () => {
28173+
if (!localsettings?.enableRunningMemory || gametext_arr.length == 0 || (gametext_arr.length == 1 && gametext_arr[0].trim() == "")) {
28174+
return null
28175+
} else {
28176+
let truncated_context = concat_gametext(true, "");
28177+
if (truncated_context.length > (lastContextLength + (0.5 * localsettings.max_context_length * 3.0))) {
28178+
lastContextLength = truncated_context.length
28179+
let max_allowed_characters = Math.floor(localsettings.max_context_length * 3.0) - 100;
28180+
let max_mem_len = Math.floor(max_allowed_characters * 0.8);
28181+
let truncated_memory = current_memory.substring(current_memory.length - max_mem_len);
28182+
if (truncated_memory != null && truncated_memory != "") {
28183+
truncated_memory += "\n";
28184+
}
28185+
28186+
truncated_context = end_trim_to_sentence(truncated_context, true);
28187+
truncated_context = truncated_context.substring(truncated_context.length - max_allowed_characters);
28188+
let augmented_len = truncated_memory.length + truncated_context.length;
28189+
let excess_len = augmented_len - max_allowed_characters; //if > 0, then we exceeded context window
28190+
truncated_context = truncated_memory + truncated_context.substring(excess_len);
28191+
28192+
let long_story = (truncated_context.length > 1800 ? true : false);
28193+
truncated_context += "\n{{[INPUT]}}:Summarize the above text in a single paragraph of up to " + (long_story ? "ten" : "five") + " detailed sentences.{{[OUTPUT]}}";
28194+
truncated_context = replace_placeholders(truncated_context);
28195+
28196+
let summary = await generateAndGetTextFromPrompt(truncated_context)
28197+
if (!!summary) {
28198+
let overwriteWIFromAgent = (uniqueIdentifier, content) => {
28199+
let baseWI = {
28200+
"key": "",
28201+
"keysecondary": "",
28202+
"keyanti": "",
28203+
"content": content,
28204+
"comment": uniqueIdentifier,
28205+
"folder": null,
28206+
"selective": false,
28207+
"constant": true,
28208+
"probability": "100",
28209+
"wigroup": "Autogenerated history",
28210+
"widisabled": false
28211+
}
28212+
current_wi = current_wi.filter(wi => wi?.comment !== uniqueIdentifier)
28213+
current_wi.push(baseWI)
28214+
}
28215+
let runningMemory = current_wi.filter(wi => wi?.wigroup === "Autogenerated history")
28216+
if (runningMemory.length >= maxMemories) {
28217+
current_wi = current_wi.filter(wi => wi?.comment !== runningMemory[0].comment)
28218+
}
28219+
overwriteWIFromAgent(`AutoHist${Math.floor(Math.random() * 1000)}`, `[Autogenerated history:\n\n${summary}]`)
28220+
return summary
28221+
}
28222+
}
28223+
}
28224+
}
28225+
setInterval(updateRunningMemory, autosummaryInterval)
28226+
28227+
let previousRestartNewGame = restart_new_game, previousLoadSelectedFile = load_selected_file
28228+
restart_new_game = () => {
28229+
previousRestartNewGame()
28230+
lastContextLength = concat_gametext(true, "").length
28231+
}
28232+
28233+
load_selected_file = (file) => {
28234+
previousLoadSelectedFile(file)
28235+
lastContextLength = concat_gametext(true, "").length
28236+
}
28237+
</script>
2816028238
</html>

0 commit comments

Comments
 (0)