Files
ai-worker-platform/backend/app/models/worker.py
T

50 lines
1.8 KiB
Python

"""AI Worker model - the 'virtual employee' profile."""
from sqlalchemy import Column, String, Integer, Text, Boolean, ForeignKey, Float
from app.models.base import Base, TimestampMixin, TenantMixin
class AIWorker(Base, TimestampMixin, TenantMixin):
"""An AI Worker is a 'virtual employee' profile.
Combines: model config + system prompt (role) + tool whitelist + cost limits.
Status: active, idle, busy, offline, cooling
"""
__tablename__ = "ai_workers"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(200), nullable=False)
description = Column(Text, default="")
# Model configuration
provider = Column(String(100), nullable=False, default="openai")
model_name = Column(String(200), nullable=False, default="gpt-4o-mini")
api_key = Column(String(500), nullable=True) # If empty, uses default
base_url = Column(String(500), nullable=True)
temperature = Column(Float, default=0.7)
# Role / system prompt
system_prompt = Column(Text, default="You are a helpful AI assistant.")
# Tool whitelist (JSON array of tool names)
tools = Column(Text, default="[]")
# Cost limits
max_cost_per_task_cents = Column(Integer, nullable=True)
max_cost_per_month_cents = Column(Integer, nullable=True)
# Status
status = Column(String(50), default="active")
is_active = Column(Boolean, default=True)
# Available time window (JSON: {"start": "09:00", "end": "18:00"})
available_hours = Column(Text, default='{"start": "00:00", "end": "23:59"}')
# Current load
current_task_count = Column(Integer, default=0)
max_concurrent_tasks = Column(Integer, default=1)
def __repr__(self):
return f"<AIWorker {self.name} ({self.provider}/{self.model_name})>"