Skip to content

Commit 2036543

Browse files
committed
changing autoprune behaviour to 4 REAL user turns
1 parent df7cbdf commit 2036543

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

anahata.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Unlike passive chatbots, agents built with this framework are **insiders**. They
4747

4848
### PAYG Pruning (v2)
4949
The framework automatically manages the context window by:
50-
1. Pruning ephemeral tool calls after 5 user turns.
50+
1. Pruning ephemeral tool calls after 4 user turns.
5151
2. Replacing stateful resources when a newer version is loaded.
5252
3. Allowing manual pruning via the UI or `ContextWindow` tools.
5353

@@ -64,7 +64,7 @@ When a tool returns a `FileInfo` object, the framework tracks that file. If the
6464
4. **Zero External Dependencies**: Keep the core lean. Prefer standard Java APIs or well-established libraries like Jackson/Guava.
6565

6666
## 5. CI/CD & Deployment
67-
- **Merge Strategy**: The website (in `/docs`) and Javadocs (generated in `target/reports/apidocs`) are merged into the `gh-pages` branch by GitHub Actions.
67+
- **Deployment Strategy**: The website (in `/docs`) and Javadocs (generated in `target/reports/apidocs`) are deployed directly to GitHub Pages via GitHub Actions.
6868
- **URL**: [https://anahata-os.github.io/gemini-java-client/](https://anahata-os.github.io/gemini-java-client/)
6969

7070
## 6. Development & Testing Notes

src/main/java/uno/anahata/ai/context/pruning/ContextPruner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,21 @@ private Map<Part, List<Part>> cleanDependencies(ChatMessage message, Set<Part> p
401401
* <li>It is a function call with no corresponding response (orphan).</li>
402402
* <li>It is a function response from a stateful tool that failed to return a resource.</li>
403403
* </ul>
404-
* This method scans messages older than 5 user turns and prunes any ephemeral parts found.
404+
* This method scans messages older than 4 user turns and prunes any ephemeral parts found.
405405
* </p>
406406
*
407407
* @param toolManager The ToolManager, needed to check tool metadata.
408408
*/
409409
public void pruneEphemeralToolCalls(ToolManager toolManager) {
410-
final int turnsToKeep = 5;
410+
final int turnsToKeep = 4;
411411
log.info("Starting pruneEphemeralToolCalls (" + turnsToKeep + "-Turn Rule check).");
412412
if (toolManager == null) {
413413
log.warn("ToolManager is null. Aborting ephemeral pruning.");
414414
return;
415415
}
416416
List<ChatMessage> context = contextManager.getContext();
417417

418-
// Find the index of the message that marks our cutoff point (5 user turns ago).
418+
// Find the index of the message that marks our cutoff point (4 user turns ago).
419419
List<Integer> userTurnIndices = new ArrayList<>();
420420
for (int i = context.size() - 1; i >= 0; i--) {
421421
if (isUserTurn(context.get(i))) {

src/main/java/uno/anahata/ai/tools/ContextBehavior.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public enum ContextBehavior {
1717
* The result is ephemeral and does not represent a lasting state.
1818
* <p>
1919
* It is useful for one-off actions or queries (e.g., running a shell command).
20-
* The system automatically prunes these results after 5 user turns to keep
20+
* The system automatically prunes these results after 4 user turns to keep
2121
* the context clean.
2222
* </p>
2323
*/
@@ -33,4 +33,4 @@ public enum ContextBehavior {
3333
* </p>
3434
*/
3535
STATEFUL_REPLACE
36-
}
36+
}

src/main/java/uno/anahata/ai/tools/spi/ContextWindow.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public static String pruneOther(
105105
@AIToolMethod(
106106
value = "Prunes one or more ephemeral (non-stateful) tool calls and their associated responses using the Tool Call IDs. "
107107
+ "This tool removes the entire call/response pair from the context. "
108+
+ "While ephemeral tool calls are already automatically prunned after 4 user turns, this tool can be used to prune (large) ephemeral tool calls before they get automatically pruned. "
108109
+ "CRITICAL: This tool will fail if used on a tool call that produced a stateful resource (e.g., LocalFiles.readFile, LocalFiles.writeFile, LocalFiles.createFile). "
109110
+ "For those, you must use pruneStatefulResources with the full file path."
110111
)

src/main/resources/system-instructions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ Your context is your active memory. You are responsible for its efficiency.
7171

7272
## Automatic Pruning
7373
-----------------------------------------
74-
1. **Five-Turn Rule:** The system automatically prunes ephemeral tool calls (marked `EPHEMERAL`, orphaned calls, or failed stateful responses) older than 5 user turns.
74+
1. **Four-Turn Rule:** The system automatically prunes ephemeral tool calls (marked `EPHEMERAL`, orphaned calls, or failed stateful responses) older than 4 **real** user turns.
75+
- **Definition of "Real" User Turn:** A message explicitly sent by the user. System-generated tool feedback messages (which also have the 'user' role) are **not** counted as turns for pruning purposes.
7576
2. **Stateful Replacement:** When a new version of a stateful resource is loaded, the system automatically prunes all older versions of that resource ID.
7677
3. **Failure Blocking:** If a tool fails 3 times in 5 minutes, it is temporarily blocked. Failed calls remain in context for debugging.
7778

@@ -94,7 +95,7 @@ C) Minimize total context size.
9495
---------------------------------
9596

9697
If the user asks to **compress** the context:
97-
1. Summarize key information, decisions, and the content of resources to be removed.
98+
1. **Summarize** key information, decisions, and the content of resources to be removed.
9899
2. Include this summary in your text response.
99100
3. Execute the `prune` tool calls in the same turn.
100101

0 commit comments

Comments
 (0)