Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion sma-av-streamlit/core/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from datetime import datetime
from sqlalchemy import (
Column, Integer, String, Text, Boolean, DateTime, ForeignKey, Index
Column, Integer, String, Text, Boolean, DateTime, ForeignKey, Index, JSON
)
from sqlalchemy.orm import declarative_base, relationship

Expand All @@ -13,6 +13,7 @@ class Agent(Base):
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(255), nullable=False, unique=True, index=True)
domain = Column(String(255), nullable=True)
config_json = Column(JSON, nullable=False, default=dict)
Comment on lines 13 to +16

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add migration for new Agent.config_json column

The new Agent.config_json field is declared as non‑nullable JSON without providing any migration or hot‑fix to add it to existing databases. All queries against Agent now select agents.config_json, so any installation running a pre‑existing SQLite file will start raising OperationalError: no such column: agents.config_json on startup (the project’s Base.metadata.create_all() calls will create new tables but will not add columns to existing ones). Please add an ALTER TABLE migration similar to other hotfix migrations or gate use of the column until the schema is upgraded.

Useful? React with 👍 / 👎.

created_at = Column(DateTime, nullable=False, default=datetime.utcnow)

def __repr__(self) -> str:
Expand Down Expand Up @@ -40,12 +41,32 @@ class Run(Base):

agent = relationship("Agent", lazy="joined")
recipe = relationship("Recipe", lazy="joined")
evidence = relationship(
"Evidence",
back_populates="run",
cascade="all, delete-orphan",
passive_deletes=True,
)

def __repr__(self) -> str:
return f"<Run id={self.id} agent_id={self.agent_id} recipe_id={self.recipe_id} status={self.status!r}>"

Index("ix_runs_status_created", Run.status, Run.created_at.desc())

class Evidence(Base):
__tablename__ = "evidence"
id = Column(Integer, primary_key=True, autoincrement=True)
run_id = Column(Integer, ForeignKey("runs.id", ondelete="CASCADE"), nullable=False, index=True)
kind = Column(String(32), nullable=False, default="json")
label = Column(String(255), nullable=True)
payload = Column(JSON, nullable=True)
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)

run = relationship("Run", back_populates="evidence")

def __repr__(self) -> str:
return f"<Evidence id={self.id} run_id={self.run_id} kind={self.kind!r}>"

class Tool(Base):
__tablename__ = "tools"
id = Column(Integer, primary_key=True, autoincrement=True)
Expand Down Expand Up @@ -92,6 +113,7 @@ def __repr__(self) -> str:
"Agent",
"Recipe",
"Run",
"Evidence",
"Tool",
"ChatThread",
"ChatMessage",
Expand Down
2 changes: 1 addition & 1 deletion sma-av-streamlit/core/workflow/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def execute_recipe_run(db: Session, agent_id: int, recipe_id: int) -> Run:
db.add(run); db.commit(); db.refresh(run)
recipe_dict = load_recipe_dict(recipe.yaml_path)
for phase, message in run_workflow_phases(recipe_dict):
attach_json(db, run_id=run.id, payload={"phase": phase, "message": f"{agent.name}: {message}"})
attach_json(db, run_id=run.id, obj={"phase": phase, "message": f"{agent.name}: {message}"})
run.status = "completed"; db.commit(); db.refresh(run)
return run