Files
ZNJJ-api-server/.env.example
T
Eric Wang 97de142e6d feat(storage): add selectable SQLite and PostgreSQL persistence
- Select one storage backend per instance via AGENT_STORAGE, retaining
  memory as the backward-compatible default. Manage the selected async
  repository, official checkpointer and connection pools in lifespan;
  fail startup on unavailable or uninitialized storage without fallback.
- Add SQLite and PostgreSQL adapters, schema initialization CLI, sample
  PostgreSQL compose configuration and a Windows-compatible serve entry.
  SQLite enforces single-instance file ownership; PostgreSQL uses a
  dedicated pool for session advisory locks plus version/epoch fencing.
- Make repository IO and commit callbacks awaitable. Persist business
  fields, a complete committed graph snapshot and turn result/version in
  one business transaction before success. Rebuild execution checkpoints
  from that snapshot, discarding uncommitted progress after interruption.
- Support optional Idempotency-Key on durable chat requests. Replay
  committed results and return 409 on changed request content; delete
  removes business/history data and replay records while retaining only
  an epoch/version tombstone to reject stale commits.
- Document migration, database switching boundaries, backup/deployment
  expectations and crash recovery. Ignore generated database files.

Validation: 315 tests passed with real SQLite and isolated PostgreSQL,
including abrupt child-process exits before/after business commit;
both backends passed CLI migration and actual HTTP server restart smoke.
Existing API tests were rechecked after isolating them from user storage.
An initial Windows CreateProcess permission failure did not recur in the
full diagnostic run; failure assertions were not skipped or relaxed.
2026-10-24 13:41:54 +08:00

57 lines
2.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
DATABASE_URL=sqlite:///./test.db
SECRET_KEY=your_secret_key
DEBUG=True
ANALYSIS_SERVICE_URL=http://127.0.0.1:3030
ANALYSIS_AUTH_TOKEN=replace-with-fastgpt-api-key
APP_ID=replace-with-fastgpt-app-id
# Voice demo (Pipecat /ws-product). Relative to project root, or an absolute path.
VOICE_CONFIG=config/voice.json
# 会话持久化:每个应用实例只选一个,修改后重启。
# 默认 memory;数据库不可用不会回退到 memory。
# AGENT_STORAGE=sqlite
# AGENT_SQLITE_PATH=./data/agent.sqlite3
# AGENT_POSTGRES_DSN=postgresql://agent:replace-me@127.0.0.1:5432/agent
# AGENT_DB_POOL_SIZE=10
# AGENT_DB_LOCK_TIMEOUT_SECONDS=30
# 开发环境可自动建表;默认 false,部署前运行 python -m src.storage.migrate。
# AGENT_DB_AUTO_MIGRATE=false
# 可选本地 PostgreSQL compose 配置(密码须与 DSN 一致):
# AGENT_POSTGRES_USER=agent
# AGENT_POSTGRES_DB=agent
# AGENT_POSTGRES_PASSWORD=replace-me
# AGENT_POSTGRES_PORT=5432
# LangGraph chat backend(作业 2)
# AGENT_BACKEND=langgraph
#
# 命名 LLM 提供商组(均为 OpenAI 兼容接口):LLM_PROVIDERS 声明名单,
# LLM_PROVIDER 选择当前生效组;缺省或 fake = 离线脚本模型。
# 每组 LLM_<名>_BASE_URL / _API_KEY / _MODEL 必填;
# 可选 _TIMEOUT_SECONDS / _MAX_RETRIES / _TEMPERATURE / _EXTRA_BODY(JSON 字符串,
# 如思考开关 KIMI 网关为 {"reasoning_effort":"none"})。
# 超时/重试缺省:每次尝试 60 秒,最多额外重试 3 次,退避 1、2、4 秒。
# SDK 自动重试关闭;流式发出首个文本 token 后不重试。
# 单次 LLM 调用预算最多 247 秒(另加响应关闭清理);不是整轮聊天总超时。
# AGENT_HISTORY_MESSAGES=50:注入模型的对话历史上限(最近 N 条,
# 双向计数);调大支持长对话;0 = 不截断(对齐 FastGPT 全量历史)。
# AGENT_HISTORY_MESSAGES=0
# LLM_PROVIDERS=deepseek,kimi,gpt6luna
# LLM_PROVIDER=deepseek
# LLM_DEEPSEEK_BASE_URL=https://api.openai.com/v1
# LLM_DEEPSEEK_API_KEY=replace-with-llm-api-key
# LLM_DEEPSEEK_MODEL=gpt-4o-mini
# LLM_DEEPSEEK_EXTRA_BODY={"reasoning_effort":"none"}
# LLM_KIMI_BASE_URL=http://127.0.0.1:3425/v1
# LLM_KIMI_API_KEY=magpie
# LLM_KIMI_MODEL=kimi-code-cn/kimi-for-coding
# LLM_KIMI_EXTRA_BODY={"reasoning_effort":"none"}
# LLM_GPT6LUNA_BASE_URL=http://127.0.0.1:3425/v1
# LLM_GPT6LUNA_API_KEY=magpie
# LLM_GPT6LUNA_MODEL=codex/gpt-6-luna
# LLM_GPT6LUNA_EXTRA_BODY={"reasoning_effort":"none"}
# 本地网关需直连(系统代理会导致 5xx);外部网关如需代理:
# LLM_HTTP_TRUST_ENV=true