You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Progressive Compression Strategies**: Uses 6 progressive compression strategies, from lightweight to heavyweight
41
41
-**Intelligent Summarization**: Uses LLM models for intelligent conversation summarization
42
42
-**Content Offloading**: Offloads large content to external storage, reducing memory usage
43
-
-**Tool Call Preservation**: Preserves tool call interface information (names, parameters) during compression
44
43
-**Dual Storage Mechanism**: Working storage (compressed) and original storage (complete history)
45
44
-**PlanNotebook Awareness**: Automatically integrates with PlanNotebook to adjust compression strategies based on current plan state, ensuring critical plan-related information is preserved during compression
45
+
-**Prompt Customization**: Supports customizing compression strategy prompts for specific scenarios and domains, enabling targeted compression optimization
46
46
47
47
## Architecture Design
48
48
@@ -115,6 +115,7 @@ All configuration parameters can be set through `AutoContextConfig`:
115
115
|`offloadSinglePreview`| int | 200 | Preview length for offloaded messages (character count) |
116
116
|`minConsecutiveToolMessages`| int | 6 | Minimum consecutive tool messages required for compression |
117
117
|`currentRoundCompressionRatio`| double | 0.3 | Compression ratio for current round messages (0.0-1.0), default 30% |
118
+
|`customPrompt`| PromptConfig | null | Custom prompt configuration (optional, uses default prompts if not set) |
**Important**: When using `AutoContextMemory` with `ReActAgent`, you **must**use `AutoContextHook` to ensure proper integration. The hook automatically handles all necessary setup.
139
+
When using `AutoContextMemory` with `ReActAgent`, it's recommended to use `AutoContextHook` to automatically handle integration setup. The hook takes care of all necessary configuration.
// Create Agent with AutoContextHook for automatic integration
158
159
ReActAgent agent =ReActAgent.builder()
159
160
.name("Assistant")
160
161
.model(model)
161
162
.memory(memory)
162
163
.toolkit(newToolkit())
163
164
.enablePlan() // Enable PlanNotebook support (optional, but recommended)
164
-
.hook(newAutoContextHook()) //REQUIRED: Automatically registers ContextOffloadTool and attaches PlanNotebook
165
+
.hook(newAutoContextHook()) // Automatically registers ContextOffloadTool and attaches PlanNotebook
165
166
.build();
166
167
```
167
168
168
-
The `AutoContextHook`is **required** and automatically:
169
+
The `AutoContextHook` automatically:
169
170
- Registers `ContextOffloadTool` to the agent's toolkit (enables context reload functionality)
170
171
- Attaches the agent's `PlanNotebook` to `AutoContextMemory` for plan-aware compression (if PlanNotebook is enabled)
171
172
- Ensures proper integration between `AutoContextMemory` and `ReActAgent`
172
173
174
+
### Custom Context Compression Prompts
175
+
176
+
AutoContextMemory uses default general-purpose compression prompts internally, which are carefully designed to meet most business needs. However, customizing compression prompts based on actual scenarios and business characteristics may achieve better compression results. For example, for specific domain tool invocation interfaces, you can explicitly guide the system to preserve which key information and appropriately discard which redundant content, thereby achieving higher compression rates while ensuring information integrity.
177
+
178
+
AutoContextMemory supports customizing compression strategy prompts, allowing optimization for specific domains and scenarios.
179
+
180
+
#### PromptConfig
181
+
182
+
The `PromptConfig` class is used to configure custom prompts. All prompts are optional. If not specified, default prompts from the `Prompts` class will be used.
@@ -379,7 +476,7 @@ This enables saving and restoring memory state between sessions. Combined with `
379
476
380
477
## Best Practices
381
478
382
-
1.**Always Use AutoContextHook**: **Required** - Always use `AutoContextHook` when using `AutoContextMemory` with `ReActAgent`. It ensures proper integration and automatic setup.
479
+
1.**Use AutoContextHook**: When using `AutoContextMemory` with `ReActAgent`, it's recommended to use `AutoContextHook` to automatically handle integration setup, ensuring `ContextOffloadTool`and `PlanNotebook` are properly configured.
383
480
2.**Set Thresholds Appropriately**: Adjust `maxToken` and `tokenRatio` based on model context window size and actual usage scenarios
384
481
3.**Protect Important Messages**: Use `lastKeep` to ensure recent conversations are not compressed
385
482
4.**Enable PlanNotebook Integration**: When using `ReActAgent` with plans, enable `PlanNotebook` support (`.enablePlan()`) to benefit from plan-aware compression
0 commit comments