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
165 lines
4.8 KiB
TypeScript
Executable File
165 lines
4.8 KiB
TypeScript
Executable File
/**
|
||
* Example: OpenClaw Integration
|
||
*
|
||
* Demonstrates how to use OpenClaw integration for
|
||
* deterministic multi-agent pipeline orchestration.
|
||
*/
|
||
|
||
import { OpenClawIntegration } from '../agent-system/integrations/openclaw';
|
||
|
||
async function openclawExample() {
|
||
// Initialize OpenClaw integration
|
||
const openclaw = new OpenClawIntegration({
|
||
maxContextTokens: 200000,
|
||
compactionStrategy: 'hybrid',
|
||
workspaceIsolation: true,
|
||
enableLobsterWorkflows: true,
|
||
enableParallelExecution: true,
|
||
maxParallelAgents: 12, // 4 projects × 3 roles
|
||
hooks: {
|
||
onCompactionStart: (ctx) => {
|
||
console.log(`[Hook] Compaction started for context ${ctx.id}`);
|
||
},
|
||
onCompactionEnd: (result) => {
|
||
console.log(`[Hook] Compaction complete: saved ${result.tokensSaved} tokens`);
|
||
},
|
||
onStateTransition: (from, to, ctx) => {
|
||
console.log(`[Hook] State transition: ${from} → ${to}`);
|
||
}
|
||
}
|
||
});
|
||
|
||
console.log('Context ID:', openclaw.getContext().id);
|
||
|
||
// Add message with OpenClaw context
|
||
openclaw.addMessage({
|
||
role: 'user',
|
||
content: 'Implement user authentication with JWT tokens',
|
||
tags: ['feature', 'auth', 'security'],
|
||
references: {
|
||
files: ['src/auth.ts', 'src/middleware.ts'],
|
||
functions: ['login', 'verifyToken', 'refreshToken']
|
||
}
|
||
});
|
||
|
||
// Create a deterministic pipeline
|
||
console.log('\n--- Creating Pipeline ---');
|
||
const pipeline = openclaw.createPipeline({
|
||
name: 'feature-development',
|
||
description: 'Complete feature development workflow with deterministic state machine',
|
||
states: [
|
||
{
|
||
name: 'analyze',
|
||
type: 'parallel',
|
||
agents: ['explorer', 'researcher'],
|
||
transitions: [
|
||
{ target: 'design', event: 'analysis_complete' }
|
||
]
|
||
},
|
||
{
|
||
name: 'design',
|
||
type: 'sequential',
|
||
agents: ['planner'],
|
||
onEnter: 'agent:planner',
|
||
transitions: [
|
||
{ target: 'implement', event: 'design_approved' }
|
||
]
|
||
},
|
||
{
|
||
name: 'implement',
|
||
type: 'parallel',
|
||
agents: ['coder'],
|
||
transitions: [
|
||
{ target: 'review', event: 'implementation_complete' }
|
||
]
|
||
},
|
||
{
|
||
name: 'review',
|
||
type: 'sequential',
|
||
agents: ['reviewer'],
|
||
timeout: 3600000, // 1 hour
|
||
transitions: [
|
||
{ target: 'complete', event: 'approved' },
|
||
{ target: 'implement', event: 'rejected' }
|
||
]
|
||
},
|
||
{
|
||
name: 'complete',
|
||
type: 'sequential',
|
||
transitions: []
|
||
}
|
||
]
|
||
});
|
||
|
||
console.log('Pipeline created:', pipeline.id);
|
||
console.log('Initial state:', pipeline.currentState);
|
||
|
||
// Start the pipeline
|
||
await openclaw.startPipeline(pipeline.id);
|
||
console.log('Pipeline started');
|
||
|
||
// Execute parallel agents (4 projects × 3 roles pattern)
|
||
console.log('\n--- Parallel Agent Execution (4×3 Pattern) ---');
|
||
const projects = ['frontend', 'backend', 'database', 'tests'];
|
||
const roles = ['security', 'performance', 'quality'] as const;
|
||
|
||
const tasks = projects.flatMap(project =>
|
||
roles.map(role => ({
|
||
type: 'explorer' as const,
|
||
prompt: `Analyze ${project} for ${role} considerations`,
|
||
context: { project, role }
|
||
}))
|
||
);
|
||
|
||
console.log(`Executing ${tasks.length} agents in parallel...`);
|
||
const results = await openclaw.executeParallelAgents(tasks);
|
||
|
||
for (const [agentId, result] of results) {
|
||
console.log(`Agent ${agentId}: ${result.success ? '✓' : '✗'}`);
|
||
}
|
||
|
||
// Transition pipeline states
|
||
console.log('\n--- Pipeline State Transitions ---');
|
||
await openclaw.transitionPipeline(pipeline.id, 'analysis_complete');
|
||
console.log('Current state:', openclaw.getPipelineStatus(pipeline.id)?.currentState);
|
||
|
||
await openclaw.transitionPipeline(pipeline.id, 'design_approved');
|
||
console.log('Current state:', openclaw.getPipelineStatus(pipeline.id)?.currentState);
|
||
|
||
// Create isolated workspace
|
||
console.log('\n--- Workspace Isolation ---');
|
||
const workspace = await openclaw.createWorkspace({
|
||
permissions: ['read', 'write'],
|
||
quota: {
|
||
maxFiles: 1000,
|
||
maxSize: 100 * 1024 * 1024 // 100MB
|
||
}
|
||
});
|
||
console.log('Workspace created:', workspace.id);
|
||
|
||
// Use persistent memory
|
||
await openclaw.remember('pipelineState', {
|
||
pipelineId: pipeline.id,
|
||
currentState: openclaw.getPipelineStatus(pipeline.id)?.currentState
|
||
});
|
||
|
||
// Save context
|
||
await openclaw.saveContext('feature-auth');
|
||
console.log('Context saved');
|
||
|
||
// Get token stats
|
||
const tokenStats = openclaw.getTokenStats();
|
||
console.log('\nToken Stats:', tokenStats);
|
||
|
||
// Export full state
|
||
const state = openclaw.exportState();
|
||
console.log('\nExported state:', {
|
||
messages: state.context.messages.length,
|
||
agents: state.agents.length,
|
||
pipelines: state.pipelines.length
|
||
});
|
||
}
|
||
|
||
// Run the example
|
||
openclawExample().catch(console.error);
|