Commit Graph

3 Commits

Author SHA1 Message Date
sasheenmusic
ec8ddeb5ac fix(session_compact): use direct compaction when called from active run
- Add compactEmbeddedPiSessionDirect for synchronous compaction
- Detect active run and use direct method to avoid self-abort deadlock
- Fixes transcript repair error when session_compact called mid-session
2026-01-29 14:31:56 -08:00
sasheenmusic
30262f9ffc feat(session_compact): add threshold check and auto-save compaction file
Improvements:
1. threshold parameter - skip compaction if context below threshold %
2. Auto-saves compaction file to memory/compactions/ with timestamp
3. Returns file path in response so agent knows where to read

This enables fully autonomous context management without manual steps.
2026-01-29 10:50:02 -08:00
sasheenmusic
efd6209bc8 feat(tools): add session_compact tool for agent-invoked context compaction
Adds a new core tool that allows agents to proactively compact their own session
context without user intervention. This enables agents to self-manage their
context window when nearing limits.

The tool:
- Uses the existing compactEmbeddedPiSession infrastructure
- Supports optional custom instructions for focused compaction
- Returns token usage before/after for transparency
- Integrates with existing compaction count tracking

Use case: Agents can monitor context usage via session_status and invoke
session_compact when approaching thresholds (e.g., 60%+ context), then
read their memory/compactions/ files to restore state.

Closes: Agent self-management of context window
2026-01-29 10:34:27 -08:00