mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-04 12:56:02 +00:00
Add EventLog and Transcript persistence entities for storing auditable event facts and conversation history projection. Implement event-first AgentRunContext builder that produces Protocol v1 compliant context payloads with required fields: event, delivery, context (ContextAccess). Key changes: - EventLog ORM: auditable event records with indexes - Transcript ORM: conversation history projection with composite indexes - AgentRunContextBuilder: Protocol v1 payload with delivery, context, bootstrap - EventLogStore/TranscriptStore: async stores for fact sources - Host action handlers: HISTORY_PAGE, HISTORY_SEARCH, EVENT_GET, EVENT_PAGE - Context validation: build_context output validates via SDK AgentRunContext - Alembic migration for event_log and transcript tables - Alembic env.py imports all ORM models for autogenerate discovery Legacy compatibility: max-round messages go into bootstrap.messages and compatibility.legacy_messages, not top-level messages field.
86 lines
3.2 KiB
Python
86 lines
3.2 KiB
Python
"""EventLog persistence entity for storing auditable event facts."""
|
|
from __future__ import annotations
|
|
|
|
import sqlalchemy
|
|
import datetime
|
|
|
|
from .base import Base
|
|
|
|
|
|
class EventLog(Base):
|
|
"""EventLog stores auditable event records for AgentRunner.
|
|
|
|
This is the fact source for events - messages, tool calls, system events, etc.
|
|
Large payloads are stored separately as artifacts; this table stores
|
|
references and summaries.
|
|
"""
|
|
|
|
__tablename__ = 'event_log'
|
|
|
|
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True)
|
|
"""Auto-increment ID for sequencing."""
|
|
|
|
event_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=False, unique=True, index=True)
|
|
"""Unique event identifier."""
|
|
|
|
event_type = sqlalchemy.Column(sqlalchemy.String(100), nullable=False, index=True)
|
|
"""Event type (message.received, tool.call.started, etc.)."""
|
|
|
|
event_time = sqlalchemy.Column(sqlalchemy.DateTime, nullable=True)
|
|
"""When the event occurred."""
|
|
|
|
source = sqlalchemy.Column(sqlalchemy.String(50), nullable=False)
|
|
"""Event source (platform, webui, api, scheduler, system, pipeline_compat)."""
|
|
|
|
bot_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True, index=True)
|
|
"""Bot UUID that handled this event."""
|
|
|
|
workspace_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True)
|
|
"""Workspace ID for multi-tenant deployments."""
|
|
|
|
conversation_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True, index=True)
|
|
"""Conversation ID this event belongs to."""
|
|
|
|
thread_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True)
|
|
"""Thread ID if platform supports threads."""
|
|
|
|
# Actor information
|
|
actor_type = sqlalchemy.Column(sqlalchemy.String(50), nullable=True)
|
|
"""Actor type (user, system, runner)."""
|
|
|
|
actor_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True)
|
|
"""Actor identifier."""
|
|
|
|
actor_name = sqlalchemy.Column(sqlalchemy.String(255), nullable=True)
|
|
"""Actor display name."""
|
|
|
|
# Subject information
|
|
subject_type = sqlalchemy.Column(sqlalchemy.String(50), nullable=True)
|
|
"""Subject type (message, tool_call, artifact)."""
|
|
|
|
subject_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True)
|
|
"""Subject identifier."""
|
|
|
|
# Input information
|
|
input_summary = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
|
"""Brief summary of input (truncated text, max 1000 chars)."""
|
|
|
|
input_json = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
|
"""Full input JSON if reasonably sized (AgentInput as JSON string)."""
|
|
|
|
# Raw event reference
|
|
raw_ref = sqlalchemy.Column(sqlalchemy.String(255), nullable=True)
|
|
"""Reference to raw event payload in ArtifactStore."""
|
|
|
|
run_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True, index=True)
|
|
"""Run ID that processed this event."""
|
|
|
|
runner_id = sqlalchemy.Column(sqlalchemy.String(255), nullable=True)
|
|
"""Runner ID that processed this event."""
|
|
|
|
created_at = sqlalchemy.Column(sqlalchemy.DateTime, nullable=False, default=datetime.datetime.utcnow)
|
|
"""When this record was created."""
|
|
|
|
metadata_json = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
|
"""Additional metadata as JSON string."""
|