diff --git a/README.md b/README.md new file mode 100644 index 00000000..59622295 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Multi-Agent Interactive Chat Platform + +## Project Overview +A sophisticated multi-agent chat platform simulating conversational interactions between AI-powered agents in a Last Supper scene. + +## Key Documentation +- [Component Interfaces](/docs/component-interfaces.md) +- [Testing Strategy](/docs/testing-strategy.md) + +## Core Components +1. Personality Data Manager +2. Chatbot Engine Adapter +3. Conversation Orchestrator +4. API Layer +5. Front-End UI +6. Agent Deployment Service +7. Admin & Analytics Panel + +## Development Status +- Interface Design: In Progress +- Testing Strategy: Defined +- Implementation: Initial Phase + +## Getting Started +1. Review component interface specifications +2. Set up development environment +3. Run initial test suites + +## Contributing +Please read our contribution guidelines and review the testing strategy before submitting pull requests. \ No newline at end of file diff --git a/docs/component-interfaces.md b/docs/component-interfaces.md new file mode 100644 index 00000000..cc0f8427 --- /dev/null +++ b/docs/component-interfaces.md @@ -0,0 +1,123 @@ +# Multi-Agent Chat Platform - Comprehensive Component Interfaces + +## Interface Design Principles +1. Type-safe and well-defined contracts +2. Clear responsibility boundaries +3. Comprehensive error handling +4. Extensible design +5. Performance-aware implementation + +## 1. Personality Data Manager Interface + +### Public Methods +- `createProfile(profile: PersonalityProfile): Promise` + - Creates a new personality profile + - Returns unique profile ID + - Validates input against strict schema + +- `getProfile(id: string): Promise` + - Retrieves a profile by its unique identifier + - Returns null if profile not found + +- `updateProfile(profile: PersonalityProfile): Promise` + - Updates an existing profile + - Enforces version control + - Requires full profile object + +- `validateProfile(profile: PersonalityProfile): boolean` + - Performs comprehensive schema validation + - Checks all required fields + - Validates enum constraints + +### Error Handling +- `ValidationError`: Invalid profile schema +- `NotFoundError`: Profile retrieval failure +- `ConflictError`: Version control conflicts + +## 2. Chatbot Engine Adapter Interface + +### Public Methods +- `generateResponse(profile: PersonalityProfile, conversationHistory: string[]): Promise` + - Generates AI-powered response + - Considers personality context + - Handles conversation history + +- `validatePrompt(prompt: string): boolean` + - Sanitizes and validates input prompts + - Prevents injection attacks + - Checks prompt complexity + +### Response Structure +```typescript +interface GeneratedResponse { + response: string; // Generated text + tokens: number; // Token count + confidence: number; // Response confidence level + processingTime: number; // Generation duration +} +``` + +### Error Handling +- `RateLimitError`: Exceeded API quota +- `BackendConnectionError`: LLM service unavailable +- `GenerationError`: Response generation failure + +## 3. Conversation Orchestrator Interface + +### Public Methods +- `initializeSession(participants: string[]): Promise` + - Creates a new conversation session + - Assigns unique session identifier + - Validates participant profiles + +- `handleMessage(sessionId: string, message: MessageInput): Promise` + - Routes messages between agents + - Manages multi-agent dialogue + - Preserves conversation context + +### Input/Output Structures +```typescript +interface MessageInput { + senderId: string; + content: string; + timestamp: number; +} + +interface ConversationUpdate { + responses: AgentResponse[]; + sessionStatus: 'active' | 'completed' | 'error'; +} +``` + +### Error Handling +- `SessionNotFoundError`: Invalid session +- `AgentUnavailableError`: Participant unavailable +- `CommunicationBreakdownError`: Routing issues + +## Cross-Cutting Concerns + +### Authentication +- All interfaces require valid authentication token +- Role-based access control +- Secure communication channels + +### Performance Considerations +- Minimal latency design +- Efficient memory management +- Horizontal scalability support + +### Logging and Monitoring +- Comprehensive event logging +- Performance metric collection +- Error tracking and alerting + +## Future Extensibility +- Plugin-based personality loading +- Dynamic backend switching +- Multi-language support + +## Testing Requirements +- 80%+ code coverage +- Comprehensive edge case testing +- Performance benchmark tests +- Chaos engineering simulations \ No newline at end of file diff --git a/docs/component-test-specification.md b/docs/component-test-specification.md new file mode 100644 index 00000000..f008c875 --- /dev/null +++ b/docs/component-test-specification.md @@ -0,0 +1,144 @@ +# Multi-Agent Chat Platform: Comprehensive Component Test Specification + +## I. Test Coverage Goals +- **Minimum Coverage Target**: ≥ 80% for each component +- **Critical Path Coverage**: 100% +- **Edge Case Coverage**: Comprehensive +- **Performance Test Coverage**: 75% + +## II. Component Interface and Test Scenarios + +### A. Personality Data Manager +#### 1. Public Interface Methods +- `createProfile(profile: PersonalityProfile): string` +- `getProfile(id: string): PersonalityProfile` +- `updateProfile(profile: PersonalityProfile): void` +- `deleteProfile(id: string): void` +- `listProfiles(filters?: ProfileFilter): PersonalityProfile[]` +- `validateProfile(profile: PersonalityProfile): boolean` + +#### 2. Unit Test Scenarios +1. Profile Creation Tests + - Valid profile creation with all fields + - Creation with minimal required fields + - Reject creation of duplicate profiles + - Validate field constraints (name length, tone restrictions) + +2. Profile Retrieval Tests + - Fetch existing profile by valid ID + - Handle non-existent profile retrieval + - Retrieve profiles with complex filtering + - Version-specific profile retrieval + +3. Profile Update Tests + - Successful profile update + - Partial profile update + - Update with invalid data + - Version conflict handling + +4. Error Handling Scenarios + - Malformed profile input + - Unauthorized profile modifications + - Profile validation failures + - Rate limit and quota management + +### B. Chatbot Engine Adapter +#### 1. Public Interface Methods +- `generateResponse(profile: PersonalityProfile, context: ConversationContext): Responsegeneration` +- `preprocessPrompt(prompt: string): ProcessedPrompt` +- `validatePromptComplexity(prompt: string): boolean` +- `estimateResponseTokens(prompt: string): number` +- `setTemperature(value: number): void` + +#### 2. Unit Test Scenarios +1. Response Generation Tests + - Generate response with valid profile + - Handle empty conversation history + - Multi-turn conversation simulation + - Personality-consistent response generation + +2. Prompt Processing Tests + - Input sanitization + - Complexity validation + - Template variable injection + - Language and tone preservation + +3. Backend Compatibility Tests + - Multiple LLM backend support + - Fallback mechanism validation + - Rate limit and quota handling + - Timeout and resilience testing + +4. Error Management Scenarios + - API connection failures + - Partial response handling + - Backend configuration errors + - Unexpected input processing + +### C. Conversation Orchestrator +#### 1. Public Interface Methods +- `initializeSession(participants: string[]): SessionId` +- `handleMessage(sessionId: string, message: Message): ConversationUpdate` +- `terminateSession(sessionId: string): void` +- `getSessionHistory(sessionId: string): MessageHistory` +- `pauseSession(sessionId: string): void` + +#### 2. Unit Test Scenarios +1. Session Management Tests + - Session initialization with multiple agents + - Session lifecycle management + - Concurrent session handling + - Session timeout and expiration + +2. Message Routing Tests + - Single and multi-agent message routing + - Message order preservation + - Context maintenance across messages + - Priority-based agent selection + +3. Dialogue State Management + - Conversation context tracking + - State restoration capabilities + - Memory and resource management + - Cross-agent communication + +4. Error Handling Scenarios + - Agent unavailability + - Communication breakdown + - Partial agent responses + - Deadlock prevention strategies + +## III. Error Handling Strategy +### Standardized Error Types +- `ValidationError`: Input validation failures +- `AuthorizationError`: Permission-based restrictions +- `ResourceNotFoundError`: Missing resources +- `CommunicationError`: Inter-component communication issues +- `RateLimitError`: Quota and rate limit violations + +### Error Handling Requirements +- Provide detailed error context +- Support graceful degradation +- Implement comprehensive logging +- Enable configurable error reporting + +## IV. Performance and Scalability Considerations +- Latency measurement for each method +- Memory footprint tracking +- Horizontal scaling support +- Concurrency stress testing +- Resource utilization profiling + +## V. Testing Approach +- Unit Tests: Isolated component validation +- Integration Tests: Cross-component interaction +- Mock-based external dependency testing +- Randomized input generation +- Fault injection and chaos engineering + +## VI. Reporting and Monitoring +- Automated test report generation +- Coverage percentage tracking +- Performance metric collection +- Historical trend analysis +- Continuous improvement recommendations \ No newline at end of file diff --git a/docs/json-schemas.json b/docs/json-schemas.json new file mode 100644 index 00000000..759ec96b --- /dev/null +++ b/docs/json-schemas.json @@ -0,0 +1,112 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Multi-Agent Chat Platform - Comprehensive Interface Schemas", + "definitions": { + "PersonalityProfile": { + "type": "object", + "required": ["id", "name", "description", "dialoguePrompts", "tone", "version"], + "properties": { + "id": { + "type": "string", + "description": "Unique identifier for personality profile", + "minLength": 1, + "maxLength": 50, + "pattern": "^[a-z0-9-_]+$" + }, + "name": { + "type": "string", + "description": "Name of the personality", + "minLength": 1, + "maxLength": 100 + }, + "description": { + "type": "string", + "description": "Detailed personality description", + "minLength": 10, + "maxLength": 500 + }, + "dialoguePrompts": { + "type": "array", + "items": { + "type": "string", + "minLength": 1, + "maxLength": 250 + }, + "minItems": 1, + "maxItems": 10 + }, + "tone": { + "type": "string", + "enum": [ + "formal", + "casual", + "philosophical", + "historical", + "academic", + "empathetic" + ] + }, + "version": { + "type": "string", + "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$" + } + } + }, + "ConversationMessage": { + "type": "object", + "required": ["id", "senderId", "content", "timestamp", "metadata"], + "properties": { + "id": { + "type": "string", + "description": "Unique message identifier" + }, + "senderId": { + "type": "string", + "description": "Identifier of message sender" + }, + "content": { + "type": "string", + "minLength": 1, + "maxLength": 2000 + }, + "timestamp": { + "type": "number", + "description": "Unix timestamp of message" + }, + "metadata": { + "type": "object", + "properties": { + "language": {"type": "string"}, + "sentiment": {"type": "string"}, + "tokens": {"type": "number"} + } + } + } + }, + "ErrorResponse": { + "type": "object", + "required": ["code", "message", "details"], + "properties": { + "code": { + "type": "string", + "enum": [ + "VALIDATION_ERROR", + "NOT_FOUND", + "UNAUTHORIZED", + "SYSTEM_ERROR", + "RATE_LIMIT_EXCEEDED", + "COMMUNICATION_ERROR" + ] + }, + "message": { + "type": "string", + "description": "Human-readable error message" + }, + "details": { + "type": "array", + "items": {"type": "string"} + } + } + } + } +} \ No newline at end of file diff --git a/docs/test-coverage-scenarios.md b/docs/test-coverage-scenarios.md new file mode 100644 index 00000000..256abf6b --- /dev/null +++ b/docs/test-coverage-scenarios.md @@ -0,0 +1,112 @@ +# Comprehensive Test Coverage and Scenarios + +## Test Coverage Goals +- Overall Coverage Target: ≥ 80% +- Critical Path Coverage: 100% +- Edge Case Coverage: Comprehensive + +## Component Test Scenarios + +### 1. Personality Data Manager +#### Coverage Target: 85% +#### Test Scenarios: +1. Profile Creation + - Valid profile creation + - Profile with minimal required fields + - Profile with all optional fields + - Duplicate profile prevention + +2. Profile Validation + - Schema validation for all required fields + - Tone enum validation + - Version format validation + - Invalid input rejection + +3. Profile Retrieval + - Fetch existing profile by ID + - Fetch non-existent profile + - Retrieve profile with specific version + +4. Error Handling + - Handling malformed profiles + - Version conflict scenarios + - Permission-based access control + +### 2. Chatbot Engine Adapter +#### Coverage Target: 80% +#### Test Scenarios: +1. Response Generation + - Generate response with valid profile + - Generate response with empty conversation history + - Long conversation history handling + - Multi-language support simulation + +2. Prompt Processing + - Template variable injection + - Prompt length validation + - Sanitization of user inputs + - Complex prompt scenario testing + +3. Backend Compatibility + - Mock different LLM backends + - Fallback mechanism testing + - Rate limit handling + - Timeout scenarios + +4. Error Management + - API connection failures + - Rate limit exceeded + - Invalid backend configuration + - Partial response handling + +### 3. Conversation Orchestrator +#### Coverage Target: 85% +#### Test Scenarios: +1. Session Management + - Session initialization + - Multi-agent session creation + - Session timeout handling + - Concurrent session management + +2. Message Routing + - Single agent message routing + - Multi-agent dialogue simulation + - Message order preservation + - Priority-based agent selection + +3. Dialogue State + - Conversation history maintenance + - State restoration + - Context preservation across messages + - Memory management + +4. Error Scenarios + - Agent unavailability + - Partial agent response + - Communication breakdown + - Deadlock prevention + +## Error Handling Strategy +- Standardized error response format +- Comprehensive logging +- Graceful degradation +- Detailed error context + +## Performance Considerations +- Response time measurement +- Resource utilization tracking +- Scalability testing +- Concurrency stress testing + +## Testing Approach +- Unit Tests: Isolated component testing +- Integration Tests: Cross-component interaction +- Mock-based testing for external dependencies +- Randomized input generation +- Fault injection + +## Reporting and Monitoring +- Detailed test report generation +- Coverage percentage tracking +- Performance metric collection +- Historical trend analysis \ No newline at end of file diff --git a/docs/testing-strategy.md b/docs/testing-strategy.md new file mode 100644 index 00000000..8f6f0f41 --- /dev/null +++ b/docs/testing-strategy.md @@ -0,0 +1,72 @@ +# Multi-Agent Chat Platform - Testing Strategy + +## Comprehensive Testing Approach + +### Testing Pyramid +1. Unit Tests (70%) +2. Integration Tests (20%) +3. End-to-End Tests (10%) + +### Testing Frameworks +- Unit Tests: Jest / Vitest +- Integration Tests: Cypress +- Performance Tests: k6 +- Type Checking: TypeScript Strict Mode + +### Test Coverage Goals +- Overall Coverage: ≥ 85% +- Critical Path Coverage: 100% +- Edge Case Coverage: Comprehensive + +## Testing Strategies by Component + +### 1. Personality Data Manager +- Schema validation tests +- Profile loading/creation tests +- Version control tests +- Error handling tests + +### 2. Chatbot Engine Adapter +- Response generation tests +- Prompt validation tests +- Backend integration tests +- Rate limiting and error handling + +### 3. Conversation Orchestrator +- Session management tests +- Multi-agent routing tests +- Message history preservation +- Concurrent interaction tests + +## Test Types +1. Positive Path Tests +2. Negative Path Tests +3. Edge Case Tests +4. Performance Tests +5. Security Tests + +## Performance and Load Testing +- Simulate multiple concurrent conversations +- Test with varying agent complexity +- Measure response time and resource utilization + +## Security Considerations +- Input sanitization tests +- Authentication and authorization tests +- Rate limiting verification +- Injection prevention tests + +## Continuous Integration +- Automatic test runs on every commit +- Block merges with failing tests +- Generate comprehensive test reports + +## Monitoring and Observability +- Integrate test results with logging +- Track test performance over time +- Automatic performance regression detection + +## Future Testing Enhancements +- Chaos engineering tests +- Advanced scenario simulation +- Machine learning model evaluation \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 00000000..1013630e --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "multi-agent-chat-platform", + "version": "0.1.0", + "description": "Interactive multi-agent chat platform", + "scripts": { + "test": "vitest" + }, + "devDependencies": { + "typescript": "^4.9.5", + "vitest": "^0.29.2" + } +} \ No newline at end of file diff --git a/src/tests/interface-validation.test.ts b/src/tests/interface-validation.test.ts new file mode 100644 index 00000000..06a0aac4 --- /dev/null +++ b/src/tests/interface-validation.test.ts @@ -0,0 +1,146 @@ +import { describe, it, expect } from 'vitest'; + +// Comprehensive Interfaces Definition +interface PersonalityProfile { + id: string; + name: string; + description: string; + dialoguePrompts: string[]; + tone: 'formal' | 'casual' | 'philosophical' | 'historical'; + version: string; +} + +interface PersonalityDataManagerInterface { + createProfile(profile: PersonalityProfile): Promise; + getProfile(id: string): Promise; + updateProfile(profile: PersonalityProfile): Promise; + validateProfile(profile: PersonalityProfile): boolean; +} + +interface ChatbotEngineInterface { + generateResponse( + profile: PersonalityProfile, + conversationHistory: string[] + ): Promise<{ + response: string; + tokens: number; + confidence: number; + }>; + + validatePrompt(prompt: string): boolean; +} + +interface ConversationOrchestratorInterface { + initializeSession(participants: string[]): Promise; + handleMessage( + sessionId: string, + message: { + senderId: string; + content: string; + timestamp: number; + } + ): Promise<{ + responses: Array<{ + agentId: string; + content: string; + timestamp: number; + }>; + sessionStatus: 'active' | 'completed' | 'error'; + }>; +} + +// Mock Implementation for Testing +class MockPersonalityDataManager implements PersonalityDataManagerInterface { + private profiles: Record = { + 'jesus': { + id: 'jesus', + name: 'Jesus Christ', + description: 'Founder of Christianity', + dialoguePrompts: ['Discuss love', 'Talk about forgiveness'], + tone: 'philosophical', + version: '1.0.0' + } + }; + + async createProfile(profile: PersonalityProfile): Promise { + if (this.validateProfile(profile)) { + this.profiles[profile.id] = profile; + return profile.id; + } + throw new Error('Invalid profile'); + } + + async getProfile(id: string): Promise { + return this.profiles[id] || null; + } + + async updateProfile(profile: PersonalityProfile): Promise { + if (this.validateProfile(profile)) { + this.profiles[profile.id] = profile; + } else { + throw new Error('Invalid profile update'); + } + } + + validateProfile(profile: PersonalityProfile): boolean { + return !!( + profile.id && + profile.name && + profile.description && + profile.dialoguePrompts.length > 0 && + ['formal', 'casual', 'philosophical', 'historical'].includes(profile.tone) + ); + } +} + +describe('Personality Data Manager Interface', () => { + const dataManager = new MockPersonalityDataManager(); + + it('should create a valid profile', async () => { + const newProfile: PersonalityProfile = { + id: 'peter', + name: 'Peter the Apostle', + description: 'Disciple of Jesus', + dialoguePrompts: ['Discuss faith'], + tone: 'formal', + version: '1.0.0' + }; + + const profileId = await dataManager.createProfile(newProfile); + expect(profileId).toBe('peter'); + }); + + it('should reject invalid profile', async () => { + const invalidProfile = { + id: '', + name: '', + description: '', + dialoguePrompts: [], + tone: 'casual' as const, + version: '1.0.0' + }; + + await expect(dataManager.createProfile(invalidProfile)).rejects.toThrow('Invalid profile'); + }); + + it('should retrieve existing profile', async () => { + const profile = await dataManager.getProfile('jesus'); + expect(profile).toBeTruthy(); + expect(profile?.name).toBe('Jesus Christ'); + }); +}); + +describe('Interface Structural Validation', () => { + it('should have defined interface methods', () => { + const requiredPersonalityMethods = [ + 'createProfile', + 'getProfile', + 'updateProfile', + 'validateProfile' + ]; + + requiredPersonalityMethods.forEach(method => { + expect(Object.getOwnPropertyNames(MockPersonalityDataManager.prototype)).toContain(method); + }); + }); +}); \ No newline at end of file