booths 2.0.0-2 → 2.0.0-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/index.cjs +341 -116
- package/dist/index.d.ts +40 -65
- package/dist/index.js +38070 -37878
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -591,6 +591,68 @@ Plugins implement `BoothPlugin` and can influence request/response flow and tool
|
|
|
591
591
|
* `ToolExecutorPlugin` – executes tool calls with per-call hooks
|
|
592
592
|
* `FinishTurnPlugin` – decides when a turn is complete
|
|
593
593
|
|
|
594
|
+
#### ConversationHistoryPlugin with Compact Hooks
|
|
595
|
+
|
|
596
|
+
The `ConversationHistoryPlugin` manages conversation history and automatically compacts (summarizes) it when token limits are reached or when routing between booths. You can monitor and respond to compaction events using callback hooks:
|
|
597
|
+
|
|
598
|
+
```ts
|
|
599
|
+
import { ConversationHistoryPlugin } from 'booths';
|
|
600
|
+
|
|
601
|
+
// Create plugin with compact event monitoring
|
|
602
|
+
const historyPlugin = new ConversationHistoryPlugin(
|
|
603
|
+
[], // Initial history (optional)
|
|
604
|
+
() => {
|
|
605
|
+
// Called when history compaction starts
|
|
606
|
+
console.log('📦 Compacting conversation history...');
|
|
607
|
+
// Show loading indicator, log metrics, etc.
|
|
608
|
+
},
|
|
609
|
+
() => {
|
|
610
|
+
// Called when history compaction completes
|
|
611
|
+
console.log('✅ History compaction complete');
|
|
612
|
+
// Hide loading indicator, log completion, etc.
|
|
613
|
+
},
|
|
614
|
+
960000 // Token threshold for compaction (optional, default: 960,000)
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
// Register the plugin (done automatically by createCoreBooth)
|
|
618
|
+
coreBooth.pluginRegistry.register(historyPlugin);
|
|
619
|
+
|
|
620
|
+
// Access conversation history at any time
|
|
621
|
+
const currentHistory = historyPlugin.history;
|
|
622
|
+
console.log(`History has ${currentHistory.length} entries`);
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
**Compaction triggers:**
|
|
626
|
+
- Input tokens exceed the threshold (default: 960,000 tokens)
|
|
627
|
+
- Routing between booths via `route_to_booth` tool call
|
|
628
|
+
- Booth change occurs with 25%+ of threshold used
|
|
629
|
+
|
|
630
|
+
**During compaction, the plugin:**
|
|
631
|
+
1. Summarizes the conversation using a specialized summarizer booth
|
|
632
|
+
2. Removes resolved function call pairs (call + output)
|
|
633
|
+
3. Preserves unresolved function calls (waiting for output)
|
|
634
|
+
4. Keeps the last user message
|
|
635
|
+
5. Rebuilds history with the summary as a developer message
|
|
636
|
+
|
|
637
|
+
```ts
|
|
638
|
+
// Example: Lower threshold for more frequent compaction
|
|
639
|
+
const aggressiveHistoryPlugin = new ConversationHistoryPlugin(
|
|
640
|
+
[],
|
|
641
|
+
() => console.log('Compacting...'),
|
|
642
|
+
() => console.log('Done!'),
|
|
643
|
+
500000 // Compact at 500K tokens instead of 960K
|
|
644
|
+
);
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
**Use cases for compact hooks:**
|
|
648
|
+
- Show loading indicators during summarization
|
|
649
|
+
- Log compaction events for monitoring
|
|
650
|
+
- Track token usage metrics
|
|
651
|
+
- Implement custom caching strategies
|
|
652
|
+
- Notify users of long-running conversations
|
|
653
|
+
|
|
654
|
+
For more details on the ConversationHistoryPlugin, see [src/plugins.md](src/plugins.md#conversationhistoryplugin-deep-dive).
|
|
655
|
+
|
|
594
656
|
---
|
|
595
657
|
|
|
596
658
|
## Best Practices
|