# Legacy Agent Migration Guide ## Overview This guide explains how to properly convert legacy agent templates to the new Template Component Architecture without introducing technical debt or code bloat. ## ⚠️ The Legacy Contamination Problem When converting legacy agents, the natural instinct is to copy existing working code. However, this leads to: - **Template Bloat**: 1,000+ line templates instead of 300 lines - **Duplicate Code**: Custom implementations instead of shared utilities - **Maintenance Issues**: Multiple copies of the same functionality - **Architecture Violations**: Inline code instead of component system ## ✅ Correct Migration Process ### Step 1: Analyze Legacy Functionality (Don't Copy Code!) **DO**: List the functional requirements ``` - File upload for PDF files - Radio button selection for analysis type - Display analysis results with formatting - Copy, download, reset functionality ``` **DON'T**: Copy the implementation code ``` ❌ Never copy 500+ lines of inline JavaScript ❌ Never copy 400+ lines of custom CSS ❌ Never copy custom implementations of shared utilities ``` ### Step 2: Map to Component Architecture **Legacy Approach (Wrong)**: ```django ``` **Component Approach (Right)**: ```django {% include "workflows/components/agent_header.html" %} {% include "workflows/components/quick_agents_panel.html" %} {% include "workflows/components/processing_status.html" %} {% include "workflows/components/results_container.html" %} ``` ### Step 3: Use Agent Template Prototype as Reference **Start with**: `agent_template_prototype.html` (perfect UI patterns) **Not with**: Existing legacy agent template The prototype shows exactly how components should work together. ### Step 4: Implement Only Agent-Specific Logic **Keep from Legacy**: - ✅ Business logic requirements - ✅ Form field definitions - ✅ Validation rules - ✅ API integration patterns **Replace with Components**: - ❌ Header implementation → Use `agent_header.html` - ❌ Navigation panel → Use `quick_agents_panel.html` - ❌ Processing display → Use `processing_status.html` - ❌ Results display → Use `results_container.html` - ❌ Utility functions → Use `WorkflowsCore` ## 📊 Migration Results Comparison | Aspect | Legacy Approach | Component Approach | Improvement | |--------|----------------|-------------------|-------------| | **Template Size** | 1,031 lines | 285 lines | 72% reduction | | **CSS Lines** | 480+ lines | 145 lines | 70% reduction | | **JavaScript** | 500+ inline | 150 external | 70% reduction | | **Maintenance** | Individual updates | Shared component updates | Automatic | | **Consistency** | Varies per agent | Identical across agents | Perfect | ## 🎯 Real Example: Data Analyzer Migration ### Before (Legacy Contamination) ```django ``` ### After (Component Architecture) ```django {% include "workflows/components/agent_header.html" %} {% include "workflows/components/quick_agents_panel.html" %}