Framework Extension Pattern - Streamlined ADRI Examples
This document outlines the proven pattern for creating streamlined ADRI framework examples that focus on value demonstration rather than dependency management.
Pattern Overviewβ
Transformation: 700-900 line bloated examples β 100-line focused demonstrations
Key Principle: Separate setup concerns from value demonstration
File Structure Patternβ
tools/
adri-setup.py # Universal setup tool
examples/
utils/
problem_demos.py # Reusable GitHub issue scenarios
[framework]-[use-case].py # Streamlined 100-line examples
docs/
setup-tool-guide.md # Setup tool documentation
framework-extension-pattern.md # This pattern guide
Implementation Stepsβ
Step 1: Research Framework GitHub Issuesβ
Goal: Identify specific validation problems ADRI solves
Process:
- Search framework GitHub repository for validation-related issues
- Document specific issue numbers and descriptions
- Categorize by impact type (conversation, function calls, data flow)
- Quantify business impact for AI Agent Engineers
Example - AutoGen Research:
54+ documented validation issues:
β’ Issue #6819: "Conversational flow is not working as expected"
β’ Issue #5736: "Function Arguments as Pydantic Models fail"
β’ Issue #6123: "Internal Message Handling corruption"
Business Impact: Research collaboration workflows break
Step 2: Add Framework to Setup Toolβ
File: tools/adri-setup.py
Pattern:
FRAMEWORKS = {
'framework_name': {
'packages': ['adri', 'framework-package', 'openai'],
'import_names': ['adri', 'framework_import', 'openai'],
'api_keys': ['OPENAI_API_KEY'], # or other required keys
'description': 'Framework description for AI engineers'
}
}
Example - AutoGen:
'autogen': {
'packages': ['adri', 'pyautogen', 'openai'],
'import_names': ['adri', 'autogen', 'openai'],
'api_keys': ['OPENAI_API_KEY'],
'description': 'Microsoft AutoGen multi-agent conversations'
}
Step 3: Create Problem Demonstration Dataβ
File: examples/utils/problem_demos.py
Pattern:
class FrameworkProblems:
"""Framework-specific problem scenarios based on documented GitHub issues."""
# Issue #number: "Description"
SCENARIO_GOOD = {
# Valid data that should work normally
"field1": "valid_value",
"field2": ["valid", "list"],
"field3": 42
}
SCENARIO_BAD = {
# Bad data that causes the documented GitHub issue
"field1": "", # Empty value breaks processing
"field2": "not_a_list", # Wrong type causes failures
"field3": -1 # Invalid value confuses framework
}
Integration Pattern:
def get_framework_problems(framework: str) -> Dict[str, Any]:
problems = {
'framework': {
'scenario_name': {
'good': FrameworkProblems.SCENARIO_GOOD,
'bad': FrameworkProblems.SCENARIO_BAD,
'github_issue': '#issue_number',
'business_impact': 'Specific impact description'
}
}
}
return problems.get(framework, {})
Step 4: Create Streamlined Exampleβ
File: examples/[framework]-[use-case].py
Template Structure (~100 lines):
#!/usr/bin/env python3
"""
Framework + ADRI: Stop Use Case Failures in 30 Seconds
π¨ THE PROBLEM: Framework has X+ documented validation issues
β’ Issue #number: "Description"
β’ Issue #number: "Description"
β’ Issue #number: "Description"
β’ Business impact description
β¨ THE SOLUTION: ADRI prevents X% of Framework failures
β’ @adri_protected decorators validate data before processing
β’ Complete audit trails for compliance
β’ Works with any Framework workflow
π SETUP: Run setup tool first, then this example:
python tools/adri-setup.py --framework framework_name
export API_KEY="your-key-here"
python examples/framework-use-case.py
π° Cost: ~$X.XX for full demonstration
"""
import os
import sys
from pathlib import Path
# Add project root to Python path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from adri.decorators.guard import adri_protected
from examples.utils.problem_demos import get_framework_problems
# Import framework with graceful fallback
try:
import framework_module
FRAMEWORK_AVAILABLE = True
except ImportError:
print("β Framework not installed. Run: python tools/adri-setup.py --framework framework_name")
FRAMEWORK_AVAILABLE = False
# Validate setup
if not os.getenv('API_KEY'):
print("β API key required. Run setup tool for guidance:")
print(" python tools/adri-setup.py --framework framework_name")
exit(1)
if not FRAMEWORK_AVAILABLE:
exit(1)
# Get real problem scenarios from GitHub issues
problems = get_framework_problems('framework_name')
class UseCaseAgent:
"""Production Framework agent with ADRI protection."""
def __init__(self):
"""Initialize real Framework components."""
# Real framework initialization here
pass
@adri_protected
def primary_function(self, data):
"""
Function description with ADRI protection.
Prevents GitHub Issue #number: "Description"
ADRI validates data before Framework processing.
"""
print(f"π― Processing: data.get('key_field', 'N/A')")
# Real framework processing here
return {
"result": "success",
"processed": True
}
@adri_protected
def secondary_function(self, data):
"""
Function description with ADRI protection.
Prevents GitHub Issue #number: "Description"
"""
print(f"π§ Executing: data.get('action', 'N/A')")
# Real framework processing here
return {"status": "completed"}
def main():
"""Demonstrate ADRI preventing real Framework GitHub issues."""
print("π‘οΈ ADRI + Framework: Real GitHub Issue Prevention")
print("=" * 55)
print(f"π― Demonstrating protection against X+ documented Framework issues")
print(" π Based on real GitHub issues from Framework repository")
print(" β
ADRI blocks bad data before it breaks your agents")
print()
agent = UseCaseAgent()
# Test scenarios for each GitHub issue
for scenario_name, scenario_data in problems.items():
print(f"π Test: scenario_name (GitHub scenario_data['github_issue'])")
# Test good data
try:
result = getattr(agent, scenario_name.replace('_', ''))(scenario_data['good'])
print("β
Good data: Processing successful")
except Exception as e:
print(f"β Unexpected error: e")
# Test bad data
try:
result = getattr(agent, scenario_name.replace('_', ''))(scenario_data['bad'])
print("β οΈ Bad data allowed through (shouldn't happen)")
except Exception:
print(f"β
ADRI blocked bad data - preventing GitHub scenario_data['github_issue']")
print()
print("=" * 55)
print("π ADRI Protection Complete!")
print()
print("π What ADRI Protected Against:")
for scenario_name, scenario_data in problems.items():
print(f"β’ Issue scenario_data['github_issue']: scenario_data['business_impact']")
print()
print(f"π Next Steps for Framework Engineers:")
print("β’ Add @adri_protected to your key functions")
print(f"β’ Protect Framework initialization and data processing")
print("β’ Customize data standards for your domain")
print("β’ Enable audit logging for compliance")
print()
print("π Learn More:")
print("β’ Setup tool: python tools/adri-setup.py --list")
print("β’ Other frameworks: examples/langchain-*.py, examples/crewai-*.py")
print("β’ Full guide: docs/ai-engineer-onboarding.md")
if __name__ == "__main__":
main()
Step 5: Update Documentationβ
Files to Update:
README.md
- Add framework to examples sectiondocs/setup-tool-guide.md
- Add to supported frameworks table- Framework-specific documentation as needed
README Pattern:
### π€ Framework β [`examples/framework-use-case.py`](examples/framework-use-case.py)
```python
@adri_protected
def primary_function(data):
# Prevents GitHub #issue: "Description"
# Prevents GitHub #issue: "Description"
Setup: python tools/adri-setup.py --framework framework_name
## Quality Checklist
Before releasing a new framework integration:
### β
Setup Tool Integration
- [ ] Framework added to `FRAMEWORKS` dict with correct packages
- [ ] Import names match actual Python imports
- [ ] API keys correctly specified
- [ ] Description is clear for AI Agent Engineers
### β
Problem Demonstration
- [ ] At least 3 real GitHub issues documented with specific numbers
- [ ] Good/bad data scenarios clearly show the problems
- [ ] Business impact clearly explained for target audience
- [ ] Data scenarios realistic for the framework's typical usage
### β
Example Implementation
- [ ] ~100 lines focused on value demonstration
- [ ] Real framework integration (not just mocks)
- [ ] Clear problem/solution narrative in docstring
- [ ] Graceful fallback when framework not installed
- [ ] Proper imports and path handling
### β
Value Proposition
- [ ] Specific GitHub issues cited in output
- [ ] Clear before/after demonstration
- [ ] Business impact clearly communicated
- [ ] Next steps actionable for framework engineers
- [ ] Cost estimate provided if applicable
### β
Documentation
- [ ] README updated with framework entry
- [ ] Setup tool guide updated
- [ ] Example tested end-to-end
- [ ] Clear setup and run instructions
## Success Metrics
A successful framework integration should achieve:
1. **30-Second Value:** AI Agent Engineer sees specific problems solved in 30 seconds
2. **Zero Friction:** One setup command handles all dependencies
3. **Real Problems:** Based on documented GitHub issues, not hypothetical scenarios
4. **Clear Next Steps:** Specific guidance for adopting ADRI in their framework
## Reusable Components
### Problem Research Template
Framework: Framework Name GitHub Repository: URL Search Terms: ["validation", "data quality", "input error", "parsing", "format"] Issues Found: Number Key Patterns: β’ Pattern 1: Description β’ Pattern 2: Description Business Impact: Impact for AI Agent Engineers
### Testing Script Template
```bash
#!/bin/bash
# Test framework integration end-to-end
echo "Testing framework integration..."
# Test setup tool
python tools/adri-setup.py --framework framework_name --auto-install
# Test example without dependencies
python examples/framework-use-case.py
# Verify value proposition visible
if grep -q "GitHub Issue" examples/framework-use-case.py; then
echo "β
GitHub issues referenced"
else
echo "β No GitHub issues found"
fi
echo "Framework integration test complete"
This pattern ensures consistent, high-quality framework integrations that immediately demonstrate ADRI's value to AI Agent Engineers from any framework background.