Files
Agentic-Compaction-and-Pipl…/examples/02-claude-code-integration.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

101 lines
3.2 KiB
TypeScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Example: Claude Code Integration
*
* Demonstrates how to use the Claude Code integration
* for context-aware AI applications.
*/
import { ClaudeCodeIntegration } from '../agent-system/integrations/claude-code';
async function claudeCodeExample() {
// Initialize Claude Code integration
const claude = new ClaudeCodeIntegration({
maxContextTokens: 200000, // Claude's 200k context window
reserveTokens: 40000, // Reserve for response
compactionStrategy: 'hybrid',
autoCompact: true, // Auto-compact when threshold reached
compactionThreshold: 0.75, // Compact at 75% capacity
enableSubagents: true, // Enable subagent spawning
maxSubagents: 6,
persistentMemory: true,
memoryStorePath: '.claude-code/memory'
});
console.log('Session ID:', claude.getSessionId());
// Add user message
claude.addMessage({
role: 'user',
content: 'Analyze this codebase and identify potential security issues.',
metadata: {
priority: 1,
fileReferences: ['src/auth.ts', 'src/middleware.ts']
}
});
// Check token stats
const stats = claude.getTokenStats();
console.log(`Token usage: ${stats.percentage}% (${stats.used}/${stats.total})`);
// Get context for Claude API
const { messages, systemPrompt } = claude.getContextForAPI();
console.log(`Prepared ${messages.length} messages for API`);
if (systemPrompt) {
console.log('System prompt includes context summary');
}
// Spawn a researcher subagent
console.log('\n--- Spawning Researcher Subagent ---');
const researcherResult = await claude.spawnSubagent({
type: 'researcher',
prompt: 'Research best practices for JWT authentication in TypeScript',
priority: 'high'
});
console.log('Researcher result:', {
success: researcherResult.success,
tokens: researcherResult.tokens,
duration: `${researcherResult.duration}ms`
});
// Spawn multiple subagents in parallel (OpenClaw pattern: 4×3)
console.log('\n--- Parallel Subagent Execution ---');
const parallelResults = await claude.executeParallelSubagents([
{ type: 'explorer', prompt: 'Find all authentication endpoints' },
{ type: 'explorer', prompt: 'Find all database queries' },
{ type: 'reviewer', prompt: 'Review input validation logic' }
]);
console.log(`Completed ${parallelResults.length} subagent tasks`);
// Use persistent memory
await claude.remember('projectContext', {
name: 'MyApp',
type: 'REST API',
securityScan: 'in-progress'
});
const savedContext = await claude.recall('projectContext');
console.log('Recalled context:', savedContext);
// Save context for later restoration
await claude.saveContext('security-audit-milestone');
console.log('Context saved for future sessions');
// Get session info
const session = claude.getSessionInfo();
console.log('\nSession Info:', {
id: session.id,
messageCount: session.messageCount,
tokenUsage: session.tokenUsage,
status: session.status
});
// Get registered tools
const tools = claude.getTools();
console.log(`\nRegistered tools: ${tools.map(t => t.name).join(', ')}`);
}
// Run the example
claudeCodeExample().catch(console.error);