Files
Agentic-Compaction-and-Pipl…/examples/01-basic-compaction.ts
admin 8329636696 Add Delegation System with 3rd Party AI Tool Integration
NEW: Delegation System (v1.2.0)
- Request Classifier for fast request analysis (<50ms)
- Agent Pool Manager with auto-scaling (8 agent types)
- Delegation Engine with 4 strategies (full, parallel, hierarchical, hybrid)
- Progress Streamer for real-time updates
- Context Handoff Protocol for inter-agent communication
- Quality Gate with confidence thresholds and auto-escalation

NEW: 3rd Party Integration Adapters
- OpenClaw adapter with parallel execution support
- Claude Code CLI adapter with tool registration
- Generic adapter for custom integrations
- Standardized IntegrationAdapter interface

Agent Types Added:
- fast-responder (quick answers < 2s)
- explorer (code navigation)
- researcher (deep analysis)
- coder (implementation)
- reviewer (quality checks)
- planner (architecture)
- executor (commands)
- analyzer (debugging)

Tests: All 6 tests passing

This project was 100% autonomously built by Z.AI GLM-5
2026-03-04 10:06:17 +00:00

70 lines
2.4 KiB
TypeScript
Executable File

/**
* Example: Basic Context Compaction
*
* Demonstrates how to use context compaction to manage
* conversation history within token limits.
*/
import {
ContextManager,
TokenCounter,
Summarizer
} from '../agent-system';
async function basicCompaction() {
// Initialize components with a 128k token budget
const tokenCounter = new TokenCounter(128000);
const summarizer = new Summarizer();
const contextManager = new ContextManager(tokenCounter, summarizer, {
maxTokens: 100000, // Max tokens before compaction triggers
compactionStrategy: 'hybrid', // Use all strategies combined
slidingWindowSize: 50, // Keep last 50 messages
preserveRecentCount: 10, // Keep last 10 messages verbatim
priorityKeywords: [ // Always retain messages with these keywords
'error', 'important', 'decision', 'critical', 'remember'
],
reserveTokens: 20000 // Reserve for response generation
});
// Simulate a long conversation
const messages = [
{ role: 'user' as const, content: 'I need to build a REST API for my application.' },
{ role: 'assistant' as const, content: 'I can help you design and implement a REST API. What features do you need?' },
{ role: 'user' as const, content: 'I need CRUD operations for users, products, and orders.' },
{ role: 'assistant' as const, content: 'Great! Let\'s design the API endpoints...' },
// ... many more messages ...
];
// Add messages to context
for (const msg of messages) {
contextManager.addMessage(msg);
}
// Check if compaction is needed
if (contextManager.needsCompaction()) {
console.log('Context is full, compacting...');
const result = await contextManager.compact();
console.log('Compaction result:');
console.log(` - Tokens saved: ${result.tokensSaved}`);
console.log(` - Messages removed: ${result.messagesRemoved}`);
if (result.summary) {
console.log(` - Summary: ${result.summary.substring(0, 100)}...`);
}
}
// Get active context for API call
const activeContext = contextManager.getActiveContext();
console.log(`Active context: ${activeContext.messages.length} messages`);
console.log(`Token usage: ${tokenCounter.getUsagePercentage() * 100}%`);
// Get token stats
const stats = tokenCounter.getStats();
console.log(`Token stats: ${stats.used}/${stats.total} (${stats.percentage}%)`);
}
// Run the example
basicCompaction().catch(console.error);