# DeepSeek V4 Chat — Module Documentation Status: **integrated** (v1.0.0, 2026-08-09) · Registry: `modules/chat-module.yaml` ## 1. Overview The chat module integrates the DeepSeek-V4-Sovereign model into the Sovereign stack as a conversational core: session management (bounded history), sovereign-context system prompt, OpenAI-compatible API client, and a deterministic local-echo fallback so the module runs — and is testable — with zero external dependencies. ## 2. Architecture ``` chat/ ├── core.py ChatMessage · ChatSession · DeepSeekV4Client └── api/ ├── routes.py /api/v1/chat/* (5 endpoints) └── app.py standalone app (port 8003) site/chat.html chat web UI (self-contained, responsive) ``` Wired into `src/sovereign/main.py` with a guarded include (same pattern as matrix/kyrexis/pec5d/coldcase). ## 3. Behavior - **API mode** — `DEEPSEEK_API_KEY` set: OpenAI-compatible `/chat/completions` call; errors surface as 502. - **Local mode** — no key: deterministic sovereign echo, no network. - **Sessions** — in-memory, bounded to `max_history` (50), system prompt always retained. ## 4. Configuration `config/chat.yaml` — model id/base/temperature/max_tokens, session bounds, system prompt. Keys via env only. ## 5. Verification - `tests/test_chat.py` — 7 tests (defaults, sessions, bounding, local echo, env config, model list, API surface). - Registry validator covers the `chat` module entry. ## 6. Production notes - In production set `DEEPSEEK_API_KEY` (or a gateway URL) and serve behind TLS; the UI (`site/chat.html`) talks to `/api/v1/chat` same-origin. - The local echo is a smoke path, not a production model answerer.