Major architectural improvement to replace in-memory task storage with database-backed persistence while maintaining backward compatibility. Changes: - Created Task SQLAlchemy model matching database schema - Added Workflow and Execution SQLAlchemy models - Created TaskService for database CRUD operations - Updated UnifiedCoordinator to use database persistence - Modified task APIs to leverage database storage - Added task loading from database on coordinator initialization - Implemented status change persistence during task execution - Enhanced task cleanup with database support - Added comprehensive task statistics from database Benefits: - Tasks persist across application restarts - Better scalability and reliability - Historical task data retention - Comprehensive task filtering and querying - Maintains in-memory cache for performance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, JSON
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from ..core.database import Base
|
|
|
|
class Agent(Base):
|
|
__tablename__ = "agents"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
name = Column(String, nullable=False) # Agent display name
|
|
endpoint = Column(String, nullable=False)
|
|
model = Column(String, nullable=True)
|
|
specialty = Column(String, nullable=True)
|
|
specialization = Column(String, nullable=True) # Legacy field for compatibility
|
|
max_concurrent = Column(Integer, default=2)
|
|
current_tasks = Column(Integer, default=0)
|
|
agent_type = Column(String, default="ollama") # "ollama" or "cli"
|
|
cli_config = Column(JSON, nullable=True) # CLI-specific configuration
|
|
capabilities = Column(JSON, nullable=True) # Agent capabilities
|
|
hardware_config = Column(JSON, nullable=True) # Hardware configuration
|
|
status = Column(String, default="offline") # Agent status
|
|
performance_targets = Column(JSON, nullable=True) # Performance targets
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
last_seen = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
# Relationships
|
|
tasks = relationship("Task", back_populates="assigned_agent")
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"id": self.id,
|
|
"name": self.name,
|
|
"endpoint": self.endpoint,
|
|
"model": self.model,
|
|
"specialty": self.specialty,
|
|
"specialization": self.specialization,
|
|
"max_concurrent": self.max_concurrent,
|
|
"current_tasks": self.current_tasks,
|
|
"agent_type": self.agent_type,
|
|
"cli_config": self.cli_config,
|
|
"capabilities": self.capabilities,
|
|
"hardware_config": self.hardware_config,
|
|
"status": self.status,
|
|
"performance_targets": self.performance_targets,
|
|
"created_at": self.created_at.isoformat() if self.created_at else None,
|
|
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
|
|
"last_seen": self.last_seen.isoformat() if self.last_seen else None
|
|
} |