@just-every/task
Version:
Task - A Thoughtful Task Loop
80 lines (64 loc) • 2.52 kB
Markdown
# Metamemory System Summary
The metamemory system for @just-every/task has been successfully implemented. Here's how it works:
## Key Features
### 1. **Automatic Thread Detection**
- Messages are analyzed every N messages (configurable, default: 5)
- Uses LLM to identify conversation threads and assign messages to them
- Tracks thread status (active, complete, paused)
### 2. **Thread Classification**
- **Core**: System/developer messages - always preserved
- **Active**: Currently being worked on - partially compacted
- **Complete**: Finished topics - replaced with summaries
- **Ephemeral**: Social chat - heavily summarized
### 3. **Smart Compaction**
Based on thread class and priority:
- Core threads: 100% preserved
- Active threads: Recent messages kept, middle summarized
- Complete threads: Full thread summary with key points
- Ephemeral threads: Brief one-line mention
## Example Output
From the demo above, a conversation about hash tables, cookies, and CSS was:
- **Original**: 8 messages
- **Compacted**: 7 messages (13% reduction)
- **Result**: Each topic summarized while preserving context
### Before Compaction:
```
1. User: Hi! What is recursion?
2. Assistant: Recursion is when a function calls itself...
3. User: Thanks! What are closures?
4. Assistant: Closures are functions that retain access...
5. User: What is a REST API?
6. Assistant: REST API is an architectural style...
```
### After Compaction:
```
1. [SUMMARY] Thread: Programming Concepts
Summary: Discussed recursion (self-calling functions), closures (scope retention),
and REST APIs (architectural style for web services).
Key Points:
- Recursion requires base case
- Closures capture outer scope
- REST uses HTTP methods
```
## Usage
```javascript
// Enable globally
setMetamemoryEnabled(true);
configureMetamemory({
processInterval: 3,
windowSize: 10
});
// Or per-task
const task = runTask(agent, 'Help me learn', {
metamemoryEnabled: true
});
// Get compacted history
const compacted = await getCompactedHistory(finalState);
```
## Benefits
1. **Context Preservation**: Important information is retained
2. **Token Efficiency**: Reduces message count by 30-70%
3. **Intelligent Grouping**: Related messages stay together
4. **Flexible Configuration**: Adjust thresholds per use case
5. **Exportable**: Can be used in other projects
The system seamlessly integrates with Task's existing architecture and provides automatic conversation management for long-running AI interactions.