Expert knowledge for performing major version refactoring in the Agent Operating System, including removing backward compatibility code, consolidating duplicate implementations, and updating all references to use the latest patterns.
Installation
Details
Usage
After installing, this skill will be available to your AI coding assistant.
Verify installation:
npx agent-skills-cli listSkill Instructions
name: code-refactoring description: Expert knowledge for performing major version refactoring in the Agent Operating System, including removing backward compatibility code, consolidating duplicate implementations, and updating all references to use the latest patterns.
Code Refactoring for Major Version Bumps
Description
Expert knowledge for performing major version refactoring in the Agent Operating System, including removing backward compatibility code, consolidating duplicate implementations, and updating all references to use the latest patterns.
When to Use This Skill
- Performing major version bumps (v1.x → v2.0.0, v2.x → v3.0.0)
- Removing deprecated code and backward compatibility layers
- Consolidating duplicate class implementations
- Updating imports across the entire codebase
- Cleaning up technical debt from gradual migrations
Core Concepts
Understanding Backward Compatibility Layers
AOS has maintained backward compatibility during refactoring by:
- Keeping original classes (v1.x) alongside new ones (v2.0.0)
- Exporting both versions with different names
- Documenting the migration path
Example from agents/__init__.py:
# Original v1.x classes
from .base import BaseAgent, Agent, StatefulAgent
from .leadership import LeadershipAgent
# New v2.0.0 classes (exported with "New" suffix)
from .base_agent import BaseAgent as BaseAgentNew
from .leadership_agent import LeadershipAgent as LeadershipAgentNew
Major Version Refactoring Strategy
When removing backward compatibility:
- Identify duplicate implementations (documented in CODE_ORGANIZATION.md)
- Choose the target version (usually v2.0.0 classes)
- Update all imports to use target version
- Remove deprecated classes
- Update exports to use canonical names
- Test thoroughly
Refactoring Steps
Step 1: Identify Duplicates
Check docs/CODE_ORGANIZATION.md for documented duplicates:
Agent Classes:
agents/base.py(v1.x) → Removeagents/base_agent.py(v2.0.0) → Keepagents/leadership.py(v1.x) → Removeagents/leadership_agent.py(v2.0.0) → Keep
Service Interfaces:
services/interfaces.py(legacy) → Removeservices/service_interfaces.py(primary) → Keep
Monitoring:
monitoring/audit_trail.py(original) → Evaluate usagemonitoring/audit_trail_generic.py(generic) → Evaluate usage
Step 2: Find All Imports
Use grep to find all imports of deprecated classes:
# Find base.py imports
grep -r "from.*agents.base import\|from.*agents\.base import" src/ --include="*.py"
# Find leadership.py imports
grep -r "from.*agents.leadership import\|from.*agents\.leadership import" src/ --include="*.py"
# Find interfaces.py imports
grep -r "from.*services.interfaces import\|from.*services\.interfaces import" src/ --include="*.py"
Step 3: Update Imports
Replace old imports with new ones:
Before:
from AgentOperatingSystem.agents.base import BaseAgent
from AgentOperatingSystem.agents.leadership import LeadershipAgent
After:
from AgentOperatingSystem.agents.base_agent import BaseAgent
from AgentOperatingSystem.agents.leadership_agent import LeadershipAgent
Step 4: Update init.py Exports
Simplify exports to use only v2.0.0 classes:
Before (agents/init.py):
from .base import BaseAgent, Agent, StatefulAgent
from .leadership import LeadershipAgent
from .base_agent import BaseAgent as BaseAgentNew
from .leadership_agent import LeadershipAgent as LeadershipAgentNew
After:
# v2.0.0 - Canonical implementations
from .base_agent import BaseAgent
from .leadership_agent import LeadershipAgent
from .perpetual import PerpetualAgent
from .purpose_driven import PurposeDrivenAgent
# ... other exports
Step 5: Remove Deprecated Files
After all imports are updated:
git rm src/AgentOperatingSystem/agents/base.py
git rm src/AgentOperatingSystem/agents/leadership.py
git rm src/AgentOperatingSystem/services/interfaces.py
Step 6: Update Documentation
Update all documentation references:
- REFACTORING.md
- CODE_ORGANIZATION.md
- MIGRATION.md
- README.md
- Any example code
Step 7: Test
Run comprehensive tests:
# Unit tests
pytest tests/
# Integration tests
pytest tests/ -m integration
# Specific component tests
pytest tests/test_agents.py
pytest tests/test_services.py
File Locations
Duplicate Classes (to be removed):
src/AgentOperatingSystem/agents/base.pysrc/AgentOperatingSystem/agents/leadership.pysrc/AgentOperatingSystem/services/interfaces.py
Target Classes (to be kept):
src/AgentOperatingSystem/agents/base_agent.pysrc/AgentOperatingSystem/agents/leadership_agent.pysrc/AgentOperatingSystem/services/service_interfaces.py
Files to Update:
src/AgentOperatingSystem/agents/__init__.pysrc/AgentOperatingSystem/services/__init__.pysrc/AgentOperatingSystem/__init__.pydocs/CODE_ORGANIZATION.mdREFACTORING.mdMIGRATION.md
Common Issues
Issue 1: Missing Features in v2.0.0
Problem: v1.x class has methods not in v2.0.0 Solution: Port missing methods to v2.0.0 before removing v1.x
Issue 2: Different Method Signatures
Problem: v2.0.0 has different method signatures Solution: Create adapter methods or update callers
Issue 3: Test Failures After Migration
Problem: Tests expect v1.x behavior Solution: Update tests to match v2.0.0 behavior
Issue 4: External Dependencies
Problem: Other repos depend on v1.x classes Solution: Coordinate migration, update external repos first
Issue 5: Import Circular Dependencies
Problem: Refactoring creates circular imports Solution: Restructure imports, use TYPE_CHECKING
Best Practices
- Create a Migration Branch: Don't do this on main
- Update Incrementally: One component at a time
- Test After Each Change: Ensure nothing breaks
- Document Changes: Update docs/releases/CHANGELOG.md
- Communicate: Notify external consumers
- Backup: Tag before major refactoring
- Review Thoroughly: Code review all changes
- Monitor Production: Watch for issues after deployment
Validation Checklist
- All v1.x imports updated to v2.0.0
- Deprecated files removed
- init.py exports updated
- Tests pass
- Documentation updated
- Examples updated
- docs/releases/CHANGELOG.md updated
- No grep matches for old imports
- External consumers notified
- Code review completed
Related Skills
aos-architecture- Understanding system architectureasync-python-testing- Testing refactored codeperpetual-agents- Understanding agent implementations
Additional Resources
docs/CODE_ORGANIZATION.md- Current duplication documentationdocs/development/REFACTORING.md- Refactoring historydocs/development/MIGRATION.md- Migration guidesdocs/releases/CHANGELOG.md- Version history
More by ASISaga
View allExpert knowledge for developing, deploying, and debugging Azure Functions in the Agent Operating System (AOS). Covers the serverless deployment model used by AOS for production workloads, including integration with Microsoft Foundry Agent Service (Azure AI Agents runtime).
Expert knowledge of the Agent Operating System (AOS) architecture, components, and design patterns. Provides deep understanding of how AOS works as a complete operating system for AI agents.
Master Pylint usage for maintaining high code quality in the Agent Operating System (AOS) repository. Includes static code analysis, error detection, PEP 8 enforcement, and code quality metrics.
Bootstrap GitHub Copilot agent intelligence system in new repositories with complete setup
