feat(agent): Gradio-powered LangGraph agent chat with streaming, tool calls, file upload, conversation persistence
- Gradio 5.50.0 ChatInterface with type='messages' streaming - LangGraph create_react_agent with InMemorySaver checkpointer - 4 @tool functions: search_dashboards, get_health_summary, list_environments, get_task_status - Structured ChatMessage metadata (7 discriminator types: stream_token, tool_start/end/error, confirm_required, confirm_resolved, error) - HITL resume via second submit() with interrupt_before/Command - Dual-identity RBAC: service JWT + user JWT for tool calls - File upload (10 MB limit, pdfplumber/xlsx/JSON parser) - Conversation persistence via POST /api/agent/conversations/save - REST API: list, history, archive conversations; multi-tab gate; LLM config - LLM provider selection via Admin -> LLM Settings (assistant_planner_provider) - Svelte 5 AgentChatModel with stream event queue, dedup, stream_status watcher - MarkdownRenderer using svelte-markdown with semantic Tailwind tokens - ToolCallCard (3 states: executing/completed/failed) - ConversationList with search, date grouping, infinite scroll - ConnectionIndicator with Gradio health status - /agent route with two-column layout - Vite proxy /api/agent/gradio -> Gradio SSE - Fixed: not_() SQLAlchemy operator, route collision with _admin_routes - Fixed: conversation_id -> id normalization, .pyc cache staleness - Fixed: event.data array parsing (Gradio returns [jsonStr, null]) - Requirements pinned: gradio==5.50.0, pydantic>=2.7,<=2.12.3
This commit is contained in:
60
backend/src/models/agent.py
Normal file
60
backend/src/models/agent.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# backend/src/models/agent.py
|
||||
# #region Models.Agent [C:2] [TYPE Module] [SEMANTICS agent,model,database]
|
||||
# @BRIEF SQLAlchemy models for Gradio Agent Chat conversations.
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import JSON, Boolean, Column, DateTime, ForeignKey, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from .mapping import Base
|
||||
|
||||
|
||||
def _uuid() -> str:
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
# #region Models.Agent.AgentConversation [C:2] [TYPE Class] [SEMANTICS agent,conversation,model]
|
||||
# @ingroup Models
|
||||
# @BRIEF A multi-turn agent chat conversation. Soft-delete via is_archived.
|
||||
# @RELATION DEPENDS_ON -> [Models.User]
|
||||
|
||||
class AgentConversation(Base):
|
||||
__tablename__ = "agent_conversations"
|
||||
|
||||
id = Column(String, primary_key=True, default=_uuid)
|
||||
user_id = Column(String, nullable=False, index=True)
|
||||
title = Column(String(256), nullable=False, server_default="New Conversation")
|
||||
is_archived = Column(Boolean, default=False, server_default="false")
|
||||
created_at = Column(DateTime, server_default="now()")
|
||||
updated_at = Column(DateTime, server_default="now()", onupdate="now()")
|
||||
|
||||
messages = relationship(
|
||||
"AgentMessage",
|
||||
back_populates="conversation",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="AgentMessage.created_at",
|
||||
)
|
||||
# #endregion Models.Agent.AgentConversation
|
||||
|
||||
|
||||
# #region Models.Agent.AgentMessage [C:2] [TYPE Class] [SEMANTICS agent,message,model]
|
||||
# @ingroup Models
|
||||
# @BRIEF A single message in an agent conversation.
|
||||
# @RELATION DEPENDS_ON -> [Models.Agent.AgentConversation]
|
||||
|
||||
class AgentMessage(Base):
|
||||
__tablename__ = "agent_messages"
|
||||
|
||||
id = Column(String, primary_key=True, default=_uuid)
|
||||
conversation_id = Column(String, ForeignKey("agent_conversations.id"), nullable=False, index=True)
|
||||
role = Column(String(16), nullable=False) # user | assistant | tool | system
|
||||
text = Column(Text, nullable=True)
|
||||
state = Column(String(32), nullable=True)
|
||||
tool_calls = Column(JSON, nullable=True) # [{tool, input, output, error, status}]
|
||||
attachments = Column(JSON, nullable=True) # [{name, type, size, extracted_text}]
|
||||
created_at = Column(DateTime, server_default="now()")
|
||||
|
||||
conversation = relationship("AgentConversation", back_populates="messages")
|
||||
# #endregion Models.Agent.AgentMessage
|
||||
# #endregion Models.Agent
|
||||
Reference in New Issue
Block a user