feat(config): configurable conversation history window (B3)
FastGPT maintains full history server-side; LangGraph truncated the injected history at a hardcoded 50 messages, so long conversations behaved differently across backends. - Config.AGENT_HISTORY_MESSAGES (env): max messages injected into the model prompt (recent N, both roles counted); default 50 unchanged; larger values support long conversations; 0 = no truncation, matching FastGPT's full-history semantics. Only the injected window is affected - dialogue stays fully persisted in the checkpoint. - validate(): rejects negative values; 0 and positive accepted - conversation_history reads the config (import-time class attribute, monkeypatched in tests); explicit None-check keeps 0 falsy-safe - .env.example documents the knob Verified: 225 unit tests (6 new history-window tests)
This commit is contained in:
@@ -33,6 +33,11 @@ class Config:
|
||||
# 运行时选择:LLM_PROVIDER=<名>;缺省或 fake = 离线脚本模型。
|
||||
LLM_PROVIDERS = os.getenv("LLM_PROVIDERS", "")
|
||||
LLM_PROVIDER = os.getenv("LLM_PROVIDER", "")
|
||||
# 对话历史注入模型时的最大消息条数(最近 N 条,双向计数)。
|
||||
# 默认 50(约 25 轮);调大支持长对话;0 = 不截断(与 FastGPT
|
||||
# 服务端全量历史语义对齐)。对话正文仍随 checkpoint 全量保存,
|
||||
# 本参数只影响注入提示词的历史窗口。
|
||||
AGENT_HISTORY_MESSAGES = int(os.getenv("AGENT_HISTORY_MESSAGES", "50"))
|
||||
# LLM 客户端是否信任系统代理(Windows 注册表)。缺省 False:
|
||||
# 本地网关(127.0.0.1)必须直连;外部网关若需代理设为 true。
|
||||
LLM_HTTP_TRUST_ENV = os.getenv("LLM_HTTP_TRUST_ENV", "false").lower() in (
|
||||
@@ -149,6 +154,8 @@ class Config:
|
||||
f"Unknown LLM_PROVIDER {cls.LLM_PROVIDER!r}; "
|
||||
f"configured: {sorted(profiles)}"
|
||||
)
|
||||
if cls.AGENT_HISTORY_MESSAGES < 0:
|
||||
raise ValueError("AGENT_HISTORY_MESSAGES must be >= 0 (0 = 不截断)")
|
||||
if cls.AGENT_BACKEND != "fastgpt":
|
||||
return
|
||||
required = [
|
||||
|
||||
Reference in New Issue
Block a user