- Added Claude Code integration with full context compaction support - Added OpenClaw integration with deterministic pipeline support - Implemented parallel agent execution (4 projects x 3 roles pattern) - Added workspace isolation with permissions and quotas - Implemented Lobster-compatible YAML workflow parser - Added persistent memory store for cross-session context - Created comprehensive README with hero section This project was 100% autonomously built by Z.AI GLM-5
205 lines
5.1 KiB
TypeScript
205 lines
5.1 KiB
TypeScript
/**
|
|
* Agent System - Complete Implementation
|
|
*
|
|
* A comprehensive agent framework with:
|
|
* - Token counting and management
|
|
* - Conversation summarization
|
|
* - Context compaction
|
|
* - Agent orchestration
|
|
* - Subagent spawning
|
|
* - Persistent storage
|
|
*
|
|
* @module agent-system
|
|
*/
|
|
|
|
// Core modules
|
|
export { TokenCounter, defaultTokenCounter, countTokens, countMessagesTokens } from './core/token-counter';
|
|
export type { TokenCountResult, MessageTokenCount, TokenBudget } from './core/token-counter';
|
|
|
|
export { ConversationSummarizer, defaultSummarizer } from './core/summarizer';
|
|
export type { SummaryResult, SummarizerOptions, ConversationTurn } from './core/summarizer';
|
|
|
|
export { ContextCompactor, ConversationContextManager, defaultCompactor, defaultContextManager } from './core/context-manager';
|
|
export type { CompactionResult, CompactionStrategy, CompactionConfig, MessagePriority } from './core/context-manager';
|
|
|
|
export { AgentOrchestrator, defaultOrchestrator } from './core/orchestrator';
|
|
export type {
|
|
AgentStatus,
|
|
TaskPriority,
|
|
TaskStatus,
|
|
AgentConfig,
|
|
Task,
|
|
AgentState,
|
|
OrchestratorEvent,
|
|
EventHandler
|
|
} from './core/orchestrator';
|
|
|
|
export {
|
|
SubagentSpawner,
|
|
SubagentInstance,
|
|
defaultSpawner,
|
|
spawnAndExecute
|
|
} from './core/subagent-spawner';
|
|
export type {
|
|
SubagentType,
|
|
SubagentDefinition,
|
|
SubagentResult,
|
|
SpawnOptions,
|
|
SubagentPool
|
|
} from './core/subagent-spawner';
|
|
|
|
// Agent classes
|
|
export { BaseAgent, SimpleAgent, createAgent } from './agents/base-agent';
|
|
export type { AgentMemory, AgentTool, AgentConfig, AgentResponse } from './agents/base-agent';
|
|
|
|
export { TaskAgent, createTaskAgent } from './agents/task-agent';
|
|
export type { TaskStep, TaskPlan, TaskResult } from './agents/task-agent';
|
|
|
|
// Storage
|
|
export { AgentStorage, defaultStorage } from './storage/memory-store';
|
|
export type { StoredConversation, StoredTask, StoredAgentState } from './storage/memory-store';
|
|
|
|
// Utilities
|
|
export {
|
|
debounce,
|
|
throttle,
|
|
retry,
|
|
sleep,
|
|
generateId,
|
|
deepClone,
|
|
deepMerge,
|
|
isObject,
|
|
truncate,
|
|
formatBytes,
|
|
formatDuration,
|
|
createRateLimiter,
|
|
createCache,
|
|
compose,
|
|
pipe,
|
|
chunk,
|
|
groupBy
|
|
} from './utils/helpers';
|
|
|
|
/**
|
|
* Quick Start Example:
|
|
*
|
|
* ```typescript
|
|
* import {
|
|
* createAgent,
|
|
* ConversationContextManager,
|
|
* SubagentSpawner
|
|
* } from './agent-system';
|
|
*
|
|
* // Create a simple agent
|
|
* const agent = createAgent(
|
|
* 'MyAgent',
|
|
* 'You are a helpful assistant.',
|
|
* { description: 'A simple helper agent' }
|
|
* );
|
|
*
|
|
* // Initialize and use
|
|
* await agent.initialize();
|
|
* const response = await agent.act('Hello!');
|
|
* console.log(response.content);
|
|
*
|
|
* // Use context management
|
|
* const context = new ConversationContextManager();
|
|
* context.addMessage({ role: 'user', content: 'Hello!' });
|
|
*
|
|
* // Spawn subagents
|
|
* const spawner = new SubagentSpawner();
|
|
* const result = await spawner.executeWithSubagent(
|
|
* 'researcher',
|
|
* 'Research AI agents',
|
|
* 'Focus on autonomous agents'
|
|
* );
|
|
* ```
|
|
*/
|
|
|
|
/**
|
|
* Context Compaction Example:
|
|
*
|
|
* ```typescript
|
|
* import { ContextCompactor, ConversationSummarizer } from './agent-system';
|
|
*
|
|
* // Create compactor with custom config
|
|
* const compactor = new ContextCompactor({
|
|
* maxTokens: 100000,
|
|
* strategy: 'hybrid',
|
|
* preserveRecentCount: 10
|
|
* });
|
|
*
|
|
* // Compact a conversation
|
|
* const messages = [
|
|
* { role: 'user', content: '...' },
|
|
* { role: 'assistant', content: '...' },
|
|
* // ... many more messages
|
|
* ];
|
|
*
|
|
* if (compactor.needsCompaction(messages)) {
|
|
* const result = await compactor.compact(messages);
|
|
* console.log(`Saved ${result.tokensSaved} tokens`);
|
|
* console.log(`Compression ratio: ${result.compressionRatio}`);
|
|
* }
|
|
* ```
|
|
*/
|
|
|
|
/**
|
|
* Agent Orchestration Example:
|
|
*
|
|
* ```typescript
|
|
* import { AgentOrchestrator, SubagentSpawner } from './agent-system';
|
|
*
|
|
* const orchestrator = new AgentOrchestrator();
|
|
*
|
|
* // Register agents
|
|
* orchestrator.registerAgent({
|
|
* id: 'agent-1',
|
|
* name: 'Worker Agent',
|
|
* type: 'worker',
|
|
* capabilities: ['process', 'execute'],
|
|
* maxConcurrentTasks: 3,
|
|
* timeout: 60000
|
|
* });
|
|
*
|
|
* // Create tasks
|
|
* orchestrator.createTask('process', 'Process data', { data: [...] });
|
|
*
|
|
* // Listen for events
|
|
* orchestrator.on('task_completed', (event) => {
|
|
* console.log('Task completed:', event.data);
|
|
* });
|
|
*
|
|
* // Start processing
|
|
* orchestrator.start();
|
|
* ```
|
|
*/
|
|
|
|
// Integrations
|
|
export { ClaudeCodeIntegration, createClaudeCodeIntegration } from './integrations/claude-code';
|
|
export type {
|
|
ClaudeCodeConfig,
|
|
ClaudeMessage,
|
|
ClaudeToolDefinition,
|
|
ClaudeCodeSession,
|
|
CompactionResult,
|
|
SubagentTask,
|
|
SubagentResult
|
|
} from './integrations/claude-code';
|
|
|
|
export { OpenClawIntegration, createOpenClawIntegration, LobsterWorkflowParser } from './integrations/openclaw';
|
|
export type {
|
|
OpenClawConfig,
|
|
OpenClawContext,
|
|
OpenClawMessage,
|
|
OpenClawAgent,
|
|
OpenClawPipeline,
|
|
OpenClawPipelineState,
|
|
OpenClawPipelineTransition,
|
|
OpenClawCompactionResult,
|
|
OpenClawWorkspace
|
|
} from './integrations/openclaw';
|
|
|
|
// Version
|
|
export const VERSION = '1.1.0';
|