### Bugfixes — Agent Chat 'Думаю' State Leak - fix(agent-chat): loadHistory() now resets streamingState/idle + cancels stale submission — prevents 'Думаю' state leak across conversation switches - fix(agent-chat): onDisconnected/onDisconnectedPermanent cascade to streamingState — prevents permanent hang on connection loss during stream - fix(agent-chat): guard on isLoadingHistory — prevents false commit of 'agent unavailable' fallback when switching conversations - fix(agent-chat): remove race in _sendNow empty-response check vs Svelte microtask (duplicate logic removed, handles correctly) - fix(stream-processor): confirm_resolved now appends msg.text to partialText instead of dropping it ### Bugfixes — Backend PDF Upload - fix(document-parser): _detect_format_by_magic() — reads file header magic bytes as fallback when Gradio loses filename - fix(document-parser): improved name extraction — tries orig_name, path stem - fix(document-parser): @RELATION AgentChatTypes -> AgentChat.Types ### HITL Flow & Agent Chat Improvements - feat(agent): HITL resume confirm/deny with userId/userJwt/envId propagation - feat(agent): confirm_required metadata fallback via aget_state() after 'Event loop is closed' error during interrupt - feat(agent): interrupt_before re-enabled via AGENT_CONFIRM_TOOLS env var - feat(frontend): debug panel with connection/stream state monitoring - feat(frontend): AgentChatModel constructor options + onBeforeSend callback - feat(frontend): crypto.randomUUID() for local conversation ID on first send ### Backend Agent Refactoring - refactor(agent): langgraph_setup — monkey-patch for PydanticSerializationError - refactor(agent): tools.py — dual identity headers, expanded tool set - refactor(agent): run.py — _find_free_port, Gradio server port fallback - refactor(agent): app.py — file size validation, message truncation, HITL path ### Frontend - feat(dashboard-hub): DashboardHubModel with filters, pagination, git actions - feat(ui): DateRangeFilter component - feat(i18n): new dashboard keys; cache tooltips fix - fix(i18n): full run tooltips — cache is NOT ignored ### Semantic Protocol - chore(agents): update all agents with canonical format - chore(skills): sync semantics-core, semantics-contracts, molecular-cot-logging ### Housekeeping - chore: remove stale semantic reports (10 files, Jan 2026) - chore: update 033-gradio-agent-chat specs, contracts, UX, tasks, tests - chore: add .agents/ directory (mirrors .opencode/ agent layouts) - chore: update run.sh with DEV_MODE, port management
3.4 KiB
Implementation Plan: Gradio Agent Chat (LangGraph)
Branch: 033-gradio-agent-chat | Date: 2026-06-08 | Updated: 2026-06-29 | Spec: spec.md
Summary
Gradio agent backend + Svelte frontend via @gradio/client submit(). LangGraph create_react_agent() + static interrupt_before + PostgresSaver. Structured JSON metadata streaming. No REST confirmations, no custom WebSocket, no deprecated assistant tool registry for agent runtime.
Current Implementation Snapshot (2026-06-29)
/agentworks through SvelteKitAgentChat.svelteandAgentChatModel.svelte.ts, connecting with@gradio/clientto${window.location.origin}/api/agent/gradio.DEV_MODE=true ./run.shwiresBACKEND_URL,GRADIO_URL, andGRADIO_SERVER_PORT;backend/src/agent/run.pyallows port fallback only withGRADIO_ALLOW_PORT_FALLBACK=true.backend/src/agent/tools.pycontains 17 native LangChain@toolfunctions andget_tools_for_query()for intent-based subset selection.run_llm_validationuses/api/validation-tasks; Git, maintenance, migration, backup, and documentation tools call their existing FastAPI REST endpoints with dual identity headers.- HITL resume path recreates the agent with
interrupt_before=[], preventing repeated guardrail cards after confirm. /agentexposes debug info:conv_id, pendingthread_id, connection/streaming state, env/user, message count, last message id, active tool calls, and error.- Verified: backend agent tests
46 passed; frontendAgentChatModel.test.ts73 passed; frontend build passed.
Technical Context
Language: Python 3.9+/TypeScript Svelte 5 runes Key Dependencies: gradio>=5.0, langgraph>=0.2, langchain-core>=0.3, langchain-openai>=0.3, langgraph-checkpoint-postgres, pdfplumber, openpyxl (back); @gradio/client (front) Storage: PostgreSQL 16 (persistence + checkpoints via langgraph-checkpoint-postgres) Testing: pytest (back), vitest L1 model + L2 UX (front) Frontend: SvelteKit SPA, model-first (AgentChatModel.svelte.ts C4), runes-only Performance: First token <1.5s, streaming 60fps, file upload ≤10MB
Constitution Check — Passed
All 8 principles satisfied: semantic contracts, decision memory, external orchestrator, module discipline, RBAC, Svelte 5 runes, test-driven C3+, attention-optimized.
Project Structure
New/Changed Files
backend/src/agent/ — app.py, langgraph_setup.py, tools.py, middleware.py, document_parser.py
backend/src/api/routes/ — agent_conversations.py, auth.py
backend/src/models/ — agent.py
backend/src/schemas/ — agent.py
frontend/src/lib/models/ — AgentChatModel.svelte.ts (rewritten)
frontend/src/lib/components/agent/ — AgentChat.svelte
frontend/src/lib/components/assistant/ — ConversationList, ToolCallCard, ConfirmationCard, ConnectionIndicator
frontend/src/routes/agent/ — +page.svelte
frontend/src/types/ — agent.ts
docker/ — Dockerfile.agent, docker-compose.yml updated, nginx.conf updated
Deprecated
backend/src/api/routes/assistant/_tool_registry.py → @DEPRECATED Tombstone (FR-022).
Runtime Context-Budget Rule
The runtime MUST NOT pass all 17 tool schemas on every request. Use get_tools_for_query(query, prefetch_available) before create_agent() and keep dashboard-prefetched requests to show_capabilities only. This is required for local 4096-token LLM contexts.
#endregion (plan summary)