Agent Backend MVP
Run (Local)
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 15000
Run (Docker Compose)
- Fill env values:
cp .env.example .env
Set GIGACHAT_TOKEN in .env.
- Start:
docker compose up --build
- Public API:
http://localhost:15000/api/* - PostgreSQL + pgvector runs in
dbservice onlocalhost:5432
Stop:
docker compose down
Public API
POST /api/rag/sessionsPOST /api/rag/sessions/{rag_session_id}/changesGET /api/rag/sessions/{rag_session_id}/jobs/{index_job_id}GET /api/rag/sessions/{rag_session_id}/jobs/{index_job_id}/events(SSE progress)POST /api/chat/dialogsPOST /api/chat/messagesGET /api/tasks/{task_id}GET /api/events?task_id=...POST /api/index/snapshotPOST /api/index/changesGET /api/index/jobs/{index_job_id}GET /api/index/jobs/{index_job_id}/events(legacy SSE progress)
RAG indexing SSE events (/api/rag/sessions/{rag_session_id}/jobs/{index_job_id}/events):
index_status:{"index_job_id","status","total_files",...}index_progress:{"index_job_id","current_file_index","total_files","processed_files","current_file_path","current_file_name"}terminal:{"index_job_id","status":"done|error",...}(final event; stream closes after this event)
Session Model
rag_session_id: identifies indexed project chunks in RAG.dialog_session_id: identifies one independent dialog context within arag_session_id.- Multiple dialogs can share one
rag_session_id.
Recommended flow:
- call
POST /api/rag/sessionsafter project selection; - wait for indexing job completion;
- call
POST /api/chat/dialogswithrag_session_id; - call
POST /api/chat/messageswithdialog_session_id+rag_session_id.
/api/chat/messages supports explicit routing hint:
mode: "auto" | "project_qa" | "project_edits" | "docs_generation" | "qa"- Legacy aliases are still accepted:
code_change,analytics_review.
Persistence
Persisted in PostgreSQL:
rag_sessions,rag_chunks,rag_index_jobsdialog_sessions,chat_messagesrouter_context(agent routing context per dialog session)- LangGraph checkpoints via
PostgresSaver(thread id =dialog_session_id)
Notes:
- RAG vectors are stored in
pgvectorcolumn (rag_chunks.embedding). - Agent context/history is restored after restart for same
dialog_session_id.
Agent Runtime
- Router + context store (
app/modules/agent/engine/router/*) - LangGraph flow execution (
app/modules/agent/engine/graphs/*) - Route selection:
default/general-> answer flowproject/qa-> answer flowproject/edits-> conservative changeset flow for non-code file updatesdocs/generation-> answer and/or changeset flow
- LLM provider: GigaChat (
chat/completions) - Prompts for graph LLM nodes:
app/modules/agent/prompts/*.txtgeneral_answer.txtproject_answer.txtproject_edits_plan.txtproject_edits_apply.txtproject_edits_self_check.txtdocs_generation.txtdocs_execution_summary.txt
Modules Structure
app/modules/chat/*: chat API, tasks, session-scoped orchestration, event streaming.app/modules/agent/*: intent router, LangGraph flows, confluence integration, changeset validation.app/modules/rag/*: indexing API/jobs and retrieval service.app/modules/shared/*: cross-module primitives (event bus, retry, idempotency).app/modules/contracts.py: fixed inter-module contracts (AgentRunner,RagRetriever,RagIndexer).
Module Boundaries
chatdepends on contractAgentRunner, but not on concreteagentinternals.agentdepends on contractRagRetriever, but not onragindexing internals.ragexposes public/internal API and service implementation.- wiring is centralized in
app/modules/application.py.
Internal API (for integration)
POST /internal/rag/index/snapshotPOST /internal/rag/index/changesGET /internal/rag/index/jobs/{index_job_id}POST /internal/rag/retrievePOST /internal/tools/confluence/fetch
Environment
.env.examplecontains full list of parameters..envis used by Docker Compose fordbandbackend.GIGACHAT_TOKEN: Basic credentials for OAuth exchange (required for LLM/embeddings).DATABASE_URL: PostgreSQL DSN, defaultpostgresql+psycopg://agent:agent@db:5432/agent.GIGACHAT_AUTH_URL: defaulthttps://ngw.devices.sberbank.ru:9443/api/v2/oauth.GIGACHAT_API_URL: defaulthttps://gigachat.devices.sberbank.ru/api/v1.GIGACHAT_SCOPE: defaultGIGACHAT_API_PERS.GIGACHAT_SSL_VERIFY:true|false, defaulttrue.GIGACHAT_MODEL: chat model name, defaultGigaChat.GIGACHAT_EMBEDDING_MODEL: embedding model name, defaultEmbeddings.AGENT_PROMPTS_DIR: optional override path for prompt files.
Troubleshooting:
- If indexing shows
failed_files > 0andindexed_files = 0, check backend logs for TLS/auth errors to GigaChat. - In corporate environments with custom TLS chain, set
GIGACHAT_SSL_VERIFY=false(or install proper CA certs in container).
Description
Languages
Python
100%