Download docs/ARCHITECTURE.md from Mjrhino/agent-x: direct link, hf CLI and curl.
- Browser
- Download file 16.7 kB
-
https://huggingface.co/spaces/Mjrhino/agent-x/resolve/main/docs/ARCHITECTURE.md
- Command line
-
hf download hf://spaces/Mjrhino/agent-x/docs/ARCHITECTURE.md
-
curl -L -o ARCHITECTURE.md https://huggingface.co/spaces/Mjrhino/agent-x/resolve/main/docs/ARCHITECTURE.md
A newer version of the Streamlit SDK is available: 1.68.0
Architecture Documentation
Agentic AI Based Task Automation System
System Overview
The Agentic AI Task Automation System is designed as a modular, extensible platform that enables autonomous task execution through intelligent agent orchestration.
High-Level Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PRESENTATION LAYER β
β (Streamlit Web Interface) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Task Input β β Result β β Logs β β
β β Widget β β Display β β View β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ORCHESTRATION LAYER β
β (AgentOrchestrator Class) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Intent β Agent β Task β Result β β
β β Classification Selection Execution Aggregation β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AGENT LAYER β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β Email β β File β β Report β β Multi-Stepβ β
β β Agent β βProcessing β β Agent β β Agent β β
β β β β Agent β β β β β β
β βββββββ¬ββββββ βββββββ¬ββββββ βββββββ¬ββββββ βββββββ¬ββββββ β
β β β β β β
β βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ β
β β Flight β β Bus β β Intelligentβ β File β β
β β Agent β β Agent β β Email β β Manager β β
β β β β β β Agent β β Agent β β
β βββββββ¬ββββββ βββββββ΄ββββββ βββββββ¬ββββββ βββββββ¬ββββββ β
β β β β β
β β βββββββββββββββββ΄ββββββββββββββ β
β β β β
β βββββββ΄ββββββββββββ΄ββββββ β
β β Data Analyzer β β
β β Agent β β
β βββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TOOLS LAYER β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β LLM β β Email β β File β β PDF β β Data β β
β β Tool β β Tool β β Tool β β Tool β β Tool β β
β ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ β
β β β β β β β
β βββββββββββ βββββββββββ β
β β Flight β β Bus β β
β β API β β API β β
β ββββββ¬βββββ ββββββ¬βββββ β
β β β β
βββββββββ΄βββββββββββ΄ββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EXTERNAL SERVICES β
β βββββββββββ βββββββββββ βββββββββββ β
β β Gemini β β SMTP β β File β β
β β API β β Server β β System β β
β βββββββββββ βββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LOGGING LAYER β
β (ActionLogger - JSON-based) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Timestamp | Agent | Task | Status | Details | Error β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Component Details
1. Presentation Layer (app.py)
Purpose: Provides user interface for interaction
Components:
- Task Input Widget: Text area for natural language commands
- Result Display: Shows execution results with formatting
- Agent Selector: Direct agent selection mode
- Logs View: Historical execution viewing
Technologies: Streamlit, Custom CSS
2. Orchestration Layer (orchestrator.py)
Purpose: Central controller for request routing
Responsibilities:
- Parse user input
- Classify intent using keywords + LLM
- Extract entities (emails, dates, file paths)
- Select appropriate agent
- Manage execution context
- Aggregate results
Key Methods:
process_request(user_input) β AgentResult
_classify_intent(text) β Dict
_select_agent(intent) β str
_extract_entities(text, intent) β Dict
3. Agent Layer
Base Class: BaseAgent (Abstract)
class BaseAgent(ABC):
name: str
description: str
status: AgentStatus
@abstractmethod
def execute(task, **kwargs) β AgentResult
@abstractmethod
def get_capabilities() β List[str]
Agents:
| Agent | Tools Used | Primary Function |
|---|---|---|
| EmailAgent | LLMTool, EmailTool | Email composition and sending |
| FileProcessingAgent | FileTool, LLMTool | File reading and summarization |
| ReportAgent | LLMTool, FileTool, PDFTool | Report generation |
| MultiStepAgent | All agents via orchestrator | Sequential task execution |
| FlightAgent | FlightAPI | Flight search |
| BusAgent | BusAPI | Bus route search |
| IntelligentEmailAgent | LLMTool, FileTool, EmailTool | Smart email handling |
| FileOrganizerAgent | FileTool | File organization |
| DataAnalyzerAgent | DataTool, LLMTool | Data analysis |
4. Tools Layer
LLMTool (llm_tool.py)
- Unified interface for Gemini and OpenAI
- Text generation, summarization, email composition
- Intent classification
EmailTool (email_tool.py)
- SMTP connection management
- Email composition with MIME
- Attachment handling
- Draft creation
FileTool (file_tool.py)
- Read/write operations
- File organization by type
- Batch rename
- Search functionality
PDFTool (pdf_tool.py)
- ReportLab-based PDF creation
- Paragraph and table support
- Multi-section reports
DataTool (data_tool.py)
- Pandas-based CSV analysis
- Statistical summaries
- Correlation analysis
- Data filtering
FlightAPI / BusAPI (flight_api.py, bus_api.py)
- Mock APIs for demonstration
- Realistic data generation
- Search and itinerary creation
5. Logging Layer (logger.py)
Features:
- Singleton pattern for single log file
- Thread-safe operations
- JSON format storage
- Query by agent, status, time
- Export to TXT
Log Entry Structure:
{
"id": "20260315120000123456",
"timestamp": "2026-03-15T12:00:00.000000",
"agent": "Email Agent",
"task": "Send email to user@example.com",
"status": "completed",
"details": {...},
"error": null
}
Data Flow
Request Processing Flow
User Input
β
βΌ
βββββββββββββββββββββ
β Streamlit UI β
β (app.py) β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Orchestrator ββββ
β process_request β β
βββββββββββ¬ββββββββββ β
β β
βΌ β
βββββββββββββββββββββ β Logs each
β Intent Classifier β β action
β (keyword + LLM) β β
βββββββββββ¬ββββββββββ β
β β
βΌ β
βββββββββββββββββββββ β
β Agent Selector β β
βββββββββββ¬ββββββββββ β
β β
βΌ βΌ
βββββββββββββββββββββ¬ββββββββββββ
β Selected Agent β Logger β
β .execute() β β
βββββββββββ¬ββββββββββ΄ββββββββββββ
β
βΌ
βββββββββββββββββββββ
β Tool(s) β
β execution β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β AgentResult β
β object β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β UI Display β
βββββββββββββββββββββ
Key Design Patterns
1. Strategy Pattern
- Different agents encapsulate different algorithms
- Orchestrator selects strategy at runtime
2. Factory Pattern
- LLMTool creates appropriate LLM provider
- Tool instantiation based on configuration
3. Singleton Pattern
- ActionLogger ensures single log file
- Thread-safe logging
4. Template Method Pattern
- BaseAgent defines execution template
- Subclasses implement specific steps
5. Command Pattern
- Tasks encapsulated as objects (AgentResult)
- Can be logged, undone, stored
Security Considerations
Credential Management
- Environment variables for API keys
- Never logged or displayed
- .env file excluded from version control
Input Validation
- Email format validation
- File path sanitization
- Parameter type checking
Encryption
- TLS for SMTP connections
- HTTPS for API calls
Access Control
- Local deployment only
- No remote execution capabilities
Scalability Considerations
Current Limitations
- Single-user design
- File-based logging
- Synchronous execution
Future Improvements
- Database for logs (PostgreSQL/MongoDB)
- Queue-based processing (Celery/RabbitMQ)
- Async agent execution
- Microservices architecture
- Container deployment (Docker/Kubernetes)
Error Handling Strategy
Layer Error Type Handling
βββββββββββββββββββββββββββββββββββββββββββββββββ
UI User input errors Validation messages
Orchestrator Routing failures Fallback to default
Agent Execution errors Result with error flag
Tool External failures Retry + graceful failure
Logging IO errors Silent failure, console log
Configuration Management
config.py centralizes:
- API endpoints and keys
- Directory paths
- Default settings
- Agent configurations
Environment Variables (.env):
- GOOGLE_API_KEY
- OPENAI_API_KEY
- SMTP_SERVER, PORT
- EMAIL credentials
Testing Strategy
Unit Tests
- Test each tool independently
- Mock external services
Integration Tests
- Test agent-tool interactions
- Test orchestrator routing
End-to-End Tests
- Full workflow testing
- UI interaction testing
This architecture provides a solid foundation for an extensible, maintainable AI task automation system.