Infrastructure: - Add Redis and Celery workers to all docker-compose files - Fix celery migration race condition in entrypoint.sh - Add healthchecks and resource limits to dev compose - Update .env.template with Redis/Celery variables Backend Models & Schemas: - Rename Sprint.completed_points to velocity (per requirements) - Add AgentInstance.name as required field - Rename Issue external tracker fields for consistency - Add IssueSource and TrackerType enums - Add Project.default_tracker_type field Backend Fixes: - Add Celery retry configuration with exponential backoff - Remove unused sequence counter from EventBus - Add mypy overrides for test dependencies - Fix test file using wrong schema (UserUpdate -> dict) Frontend Fixes: - Fix memory leak in useProjectEvents (proper cleanup) - Fix race condition with stale closure in reconnection - Sync TokenWithUser type with regenerated API client - Fix expires_in null handling in useAuth - Clean up unused imports in prototype pages - Add ESLint relaxed rules for prototype files CI/CD: - Add E2E testing stage with Testcontainers - Add security scanning with Trivy and pip-audit - Add dependency caching for faster builds Tests: - Update all tests to use renamed fields (velocity, name, etc.) - Fix 14 schema test failures - All 1500 tests pass with 91% coverage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
112 lines
3.3 KiB
Python
112 lines
3.3 KiB
Python
# app/models/syndarix/agent_instance.py
|
|
"""
|
|
AgentInstance model for Syndarix AI consulting platform.
|
|
|
|
An AgentInstance is a spawned instance of an AgentType, assigned to a
|
|
specific project to perform work.
|
|
"""
|
|
|
|
from sqlalchemy import (
|
|
BigInteger,
|
|
Column,
|
|
DateTime,
|
|
Enum,
|
|
ForeignKey,
|
|
Index,
|
|
Integer,
|
|
Numeric,
|
|
String,
|
|
Text,
|
|
)
|
|
from sqlalchemy.dialects.postgresql import (
|
|
JSONB,
|
|
UUID as PGUUID,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.models.base import Base, TimestampMixin, UUIDMixin
|
|
|
|
from .enums import AgentStatus
|
|
|
|
|
|
class AgentInstance(Base, UUIDMixin, TimestampMixin):
|
|
"""
|
|
AgentInstance model representing a spawned agent working on a project.
|
|
|
|
Tracks:
|
|
- Current status and task
|
|
- Memory (short-term in DB, long-term reference to vector store)
|
|
- Session information for MCP connections
|
|
- Usage metrics (tasks completed, tokens, cost)
|
|
"""
|
|
|
|
__tablename__ = "agent_instances"
|
|
|
|
# Foreign keys
|
|
agent_type_id = Column(
|
|
PGUUID(as_uuid=True),
|
|
ForeignKey("agent_types.id", ondelete="RESTRICT"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
|
|
project_id = Column(
|
|
PGUUID(as_uuid=True),
|
|
ForeignKey("projects.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
|
|
# Agent instance name (e.g., "Dave", "Eve") for personality
|
|
name = Column(String(100), nullable=False, index=True)
|
|
|
|
# Status tracking
|
|
status: Column[AgentStatus] = Column(
|
|
Enum(AgentStatus),
|
|
default=AgentStatus.IDLE,
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
|
|
# Current task description (brief summary of what agent is doing)
|
|
current_task = Column(Text, nullable=True)
|
|
|
|
# Short-term memory stored in database (conversation context, recent decisions)
|
|
short_term_memory = Column(JSONB, default=dict, nullable=False)
|
|
|
|
# Reference to long-term memory in vector store (e.g., "project-123/agent-456")
|
|
long_term_memory_ref = Column(String(500), nullable=True)
|
|
|
|
# Session ID for active MCP connections
|
|
session_id = Column(String(255), nullable=True, index=True)
|
|
|
|
# Activity tracking
|
|
last_activity_at = Column(DateTime(timezone=True), nullable=True, index=True)
|
|
terminated_at = Column(DateTime(timezone=True), nullable=True, index=True)
|
|
|
|
# Usage metrics
|
|
tasks_completed = Column(Integer, default=0, nullable=False)
|
|
tokens_used = Column(BigInteger, default=0, nullable=False)
|
|
cost_incurred = Column(Numeric(precision=10, scale=4), default=0, nullable=False)
|
|
|
|
# Relationships
|
|
agent_type = relationship("AgentType", back_populates="instances")
|
|
project = relationship("Project", back_populates="agent_instances")
|
|
assigned_issues = relationship(
|
|
"Issue",
|
|
back_populates="assigned_agent",
|
|
foreign_keys="Issue.assigned_agent_id",
|
|
)
|
|
|
|
__table_args__ = (
|
|
Index("ix_agent_instances_project_status", "project_id", "status"),
|
|
Index("ix_agent_instances_type_status", "agent_type_id", "status"),
|
|
Index("ix_agent_instances_project_type", "project_id", "agent_type_id"),
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return (
|
|
f"<AgentInstance {self.name} ({self.id}) type={self.agent_type_id} "
|
|
f"project={self.project_id} status={self.status.value}>"
|
|
)
|