Activate VENV source venv/bin/activate
The codebase has been refactored into a clean, modular architecture following best practices:
asi-agent/
βββ main.py # Application entry point
βββ api.py # FastAPI routes and endpoints
βββ agents.py # uAgents multi-agent system
βββ models.py # Pydantic data models
βββ database.py # Database models and configuration
βββ metta_engine.py # MeTTa reasoning engine
βββ asi_one_client.py # ASI:One API client
βββ scoring_engine.py # Content scoring and recommendations
βββ requirements.txt # Python dependencies
βββ agent.yaml # Agentverse deployment manifest
βββ README_REFACTORED.md # This file
- Purpose: Application bootstrap and server startup
- Responsibilities:
- Start uAgents Bureau
- Launch FastAPI server
- Handle graceful shutdown
- Purpose: REST API endpoints and HTTP handling
- Responsibilities:
- Define API routes (
/analyze/bias,/score/overall, etc.) - Request/response validation
- Error handling and HTTP status codes
- Database integration for persistence
- Define API routes (
- Purpose: uAgents coordination and communication
- Responsibilities:
- Define individual agents (BiasAgent, ReadabilityAgent, etc.)
- Implement agent protocols and message handlers
- Coordinate agent-to-agent communication
- Chat Protocol for conversational interface
- Purpose: Pydantic models for type safety and validation
- Responsibilities:
- API request/response models
- Agent message models
- Data validation and serialization
- Purpose: Database models and connection management
- Responsibilities:
- SQLAlchemy ORM models
- Database connection configuration
- Session management utilities
- Purpose: MeTTa-based bias detection and reasoning
- Responsibilities:
- Initialize MeTTa knowledge base
- Define bias detection rules
- Analyze content for bias, manipulation, and profanity
- Sophisticated reasoning logic
- Purpose: ASI:One API integration
- Responsibilities:
- Sentiment analysis via ASI:One
- Topic extraction and classification
- Similarity analysis
- Fallback mechanisms when API is unavailable
- Purpose: Content quality assessment and recommendations
- Responsibilities:
- Readability calculations (Flesch-Kincaid, Gunning Fog)
- Overall score computation
- Recommendation generation
- Score normalization and weighting
- Single Responsibility: Each file has one clear purpose
- Easy to Modify: Changes to one component don't affect others
- Clear Dependencies: Easy to see what depends on what
- Unit Testing: Each module can be tested independently
- Mocking: Easy to mock dependencies for testing
- Isolation: Components can be tested in isolation
- Modular Deployment: Components can be deployed separately
- Easy Extension: New features can be added as new modules
- Performance: Can optimize individual components
- Type Safety: Pydantic models provide runtime type checking
- Documentation: Each module is self-documenting
- Standards: Follows Python and FastAPI best practices
pip install -r requirements.txtexport ASI_API_KEY="your_asi_one_api_key"
export DATABASE_URL="postgresql://user:pass@localhost:5432/db"python main.py# Just the API server
python -c "from api import app; import uvicorn; uvicorn.run(app, host='0.0.0.0', port=8001)"
# Just the agents
python -c "from agents import bureau; bureau.run()"from metta_engine import analyze_bias_metta
result = await analyze_bias_metta("This is fucking amazing!")
print(result)from asi_one_client import get_sentiment_analysis
sentiment = await get_sentiment_analysis("I love this!")
print(sentiment)from scoring_engine import calculate_overall_score
score, breakdown, recs = calculate_overall_score(0.8, 0.2, 65.0, 0.7, 0.3)
print(f"Score: {score}, Recommendations: {recs}")GET /- Health checkGET /health- Detailed health statusPOST /analyze/bias- Bias analysis onlyPOST /analyze/readability- Readability analysis onlyPOST /analyze/post- Complete post analysisPOST /score/overall- Overall score with breakdown
The multi-agent system uses real uAgents communication:
# Agent-to-agent communication
bias_result = await agg_agent.send("BiasAgent", "BiasCheck", TextMessage(text=content))
read_result = await agg_agent.send("ReadabilityAgent", "ReadabilityCheck", TextMessage(text=content))
sentiment_result = await agg_agent.send("SentimentAgent", "SentimentCheck", TextMessage(text=content))- Modular Design: Each component has a single responsibility
- Type Safety: Pydantic models ensure data integrity
- Testability: Components can be tested independently
- Maintainability: Easy to modify and extend
- Documentation: Self-documenting code structure
- Best Practices: Follows Python and FastAPI conventions
This refactored architecture makes the codebase much more professional, maintainable, and ready for production deployment! π