Feature: Integrate workflow tracking and agent metadata to chat messages

This commit is contained in:
2026-06-15 14:58:08 +02:00
parent a6ba0db6ff
commit f43976f167
4 changed files with 33 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ DEFAULT_EMBED_MODEL = "nomic-embed-text:latest"
DEFAULT_RERANK_MODEL = DEFAULT_EMBED_MODEL
DEFAULT_ENRICHMENT_MODEL = "qwen3:4b"
DEFAULT_TRANSCRIPTION_MODEL = "base"
DEFAULT_WORKFLOW_ROUTER_MODEL = ""
DEFAULT_AUTO_DEEP_ENRICHMENT = True
BGE_EMBED_MODEL = "bge-m3:latest"
DEFAULT_SETTINGS: Dict[str, Any] = {
@@ -25,6 +26,7 @@ DEFAULT_SETTINGS: Dict[str, Any] = {
"rerankModel": DEFAULT_RERANK_MODEL,
"enrichmentModel": DEFAULT_ENRICHMENT_MODEL,
"transcriptionModel": DEFAULT_TRANSCRIPTION_MODEL,
"workflowRouterModel": DEFAULT_WORKFLOW_ROUTER_MODEL,
"autoDeepEnrichment": DEFAULT_AUTO_DEEP_ENRICHMENT,
}
@@ -148,6 +150,7 @@ def load_app_settings() -> Dict[str, Any]:
settings["chatModel"] = normalize_model_name(settings.get("chatModel"))
settings["visionModel"] = normalize_model_name(settings.get("visionModel"))
settings["transcriptionModel"] = normalize_transcription_model(settings.get("transcriptionModel"))
settings["workflowRouterModel"] = normalize_model_name(settings.get("workflowRouterModel"))
settings["autoDeepEnrichment"] = normalize_boolean(
settings.get("autoDeepEnrichment"),
DEFAULT_AUTO_DEEP_ENRICHMENT,
@@ -181,6 +184,11 @@ def get_transcription_model_preference() -> str:
return normalize_transcription_model(settings.get("transcriptionModel"))
def get_workflow_router_model_preference() -> str:
settings = load_app_settings()
return normalize_model_name(settings.get("workflowRouterModel"))
def get_auto_deep_enrichment_preference() -> bool:
settings = load_app_settings()
return normalize_boolean(

View File

@@ -41,6 +41,15 @@ def ensure_sources_column(engine):
conn.execute(text("ALTER TABLE chat_messages ADD COLUMN sources_json TEXT DEFAULT '[]'"))
if "attachments_json" not in cols:
conn.execute(text("ALTER TABLE chat_messages ADD COLUMN attachments_json TEXT DEFAULT '[]'"))
for column_name, definition in (
("workflow_id", "TEXT"),
("workflow_revision_id", "TEXT"),
("workflow_run_id", "TEXT"),
("agent_summary_json", "TEXT DEFAULT '{}'"),
("usage_json", "TEXT DEFAULT '{}'"),
):
if column_name not in cols:
conn.execute(text(f"ALTER TABLE chat_messages ADD COLUMN {column_name} {definition}"))
missing_ids = conn.execute(
text("SELECT id FROM chat_messages WHERE message_id IS NULL OR message_id = ''")
).fetchall()
@@ -53,5 +62,9 @@ def ensure_sources_column(engine):
"CREATE UNIQUE INDEX IF NOT EXISTS ix_chat_messages_message_id "
"ON chat_messages (message_id)"
))
conn.execute(text(
"CREATE INDEX IF NOT EXISTS ix_chat_messages_workflow_run_id "
"ON chat_messages (workflow_run_id)"
))
except Exception as e:
print("[db] ensure_sources_column error:", e)

View File

@@ -26,6 +26,11 @@ class ChatMessage(Base):
sources_json = Column(Text, nullable=True, default='[]')
# JSON-encoded list of inline image attachments for user messages.
attachments_json = Column(Text, nullable=True, default='[]')
workflow_id = Column(String(36), nullable=True)
workflow_revision_id = Column(String(36), nullable=True)
workflow_run_id = Column(String(36), nullable=True, index=True)
agent_summary_json = Column(Text, nullable=True, default='{}')
usage_json = Column(Text, nullable=True, default='{}')
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
session = relationship("ChatSession", back_populates="messages")

View File

@@ -1,5 +1,5 @@
from pydantic import BaseModel, ConfigDict
from typing import List, Optional
from typing import Any, Dict, List, Optional
from datetime import datetime
class ChatAttachment(BaseModel):
@@ -16,8 +16,13 @@ class Message(BaseModel):
message_id: Optional[str] = None
role: str
content: str
sources: Optional[List[str]] = None
sources: Optional[List[Any]] = None
attachments: Optional[List[ChatAttachment]] = None
workflow_id: Optional[str] = None
workflow_revision_id: Optional[str] = None
workflow_run_id: Optional[str] = None
agent_summary: Optional[Dict[str, Any]] = None
usage: Optional[Dict[str, Any]] = None
class ChatRequest(BaseModel):
session_id: str