From 79faf0296b572aca337a2e716102ad1ef573067d Mon Sep 17 00:00:00 2001 From: John F Rucker Date: Sun, 2 Nov 2025 01:32:36 -0700 Subject: [PATCH] Add agent config and evidence support for workflow runs --- sma-av-streamlit/core/db/models.py | 24 +++++++++++++++++++++++- sma-av-streamlit/core/workflow/engine.py | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sma-av-streamlit/core/db/models.py b/sma-av-streamlit/core/db/models.py index fec5103..e0ff27f 100644 --- a/sma-av-streamlit/core/db/models.py +++ b/sma-av-streamlit/core/db/models.py @@ -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 @@ -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) created_at = Column(DateTime, nullable=False, default=datetime.utcnow) def __repr__(self) -> str: @@ -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"" 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"" + class Tool(Base): __tablename__ = "tools" id = Column(Integer, primary_key=True, autoincrement=True) @@ -92,6 +113,7 @@ def __repr__(self) -> str: "Agent", "Recipe", "Run", + "Evidence", "Tool", "ChatThread", "ChatMessage", diff --git a/sma-av-streamlit/core/workflow/engine.py b/sma-av-streamlit/core/workflow/engine.py index e6dd328..ff2ccae 100644 --- a/sma-av-streamlit/core/workflow/engine.py +++ b/sma-av-streamlit/core/workflow/engine.py @@ -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