JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(context): 补充上下文配置注释
l_x_d10b8fe8a7aae
diff --git a/jiuwenswarm/resources/config.yaml b/jiuwenswarm/resources/config.yamlindex fa6757bb5d..9f1d37fa4d 100644--- a/jiuwenswarm/resources/config.yaml+++ b/jiuwenswarm/resources/config.yaml@@ -542,26 +542,61 @@ react:kv_cache_affinity_config:enable_kv_cache_release: falseenable_kv_cache_affinity: false+ # ============ 上下文引擎(上下文压缩/召回/会话记忆)============context_engine_config:- enable_openrouter_model_context_window_tokens: true- enable_reload: true- enabled: true+ enabled: true # 全局开关:false 时整个上下文引擎(含下列所有处理器)不生效+ enable_openrouter_model_context_window_tokens: true # 从 OpenRouter 拉取模型的上下文窗口大小;false 时按内置模型表解析+ # 显式覆盖上下文窗口 token 上限(正整数);注释掉或留空则按模型自动解析+ # context_window_tokens: 131072+ enable_reload: true # 卸载重载:开启后模型可通过 [[HANDLE:xxx]] 标记把已卸载的大消息原文拉回上下文++ enable_context_debug: false # 上下文压缩 debug 模式:开启后各处理器在阈值判断、片段切分、压缩重试、 前后对比等每个阶段落盘 JSONL 记录,便于排查压缩问题。关闭时零开销。默认关闭+ # debug 记录目录;留空则按环境变量 OPENJIUWEN_CONTEXT_DEBUG_DIR,+ # 再缺省落到 {workspace}/context/{session_id}_context/context_debug/+ # context_debug_dir:++ # 压缩召回:压缩器替换原始消息时,把原文分块归档到会话目录 compression_recall/,+ # 模型可通过 [[COMPRESSION_RECALL: id=...]] 标记按需召回原文。默认关闭。+ compression_recall_config:+ enabled: false # true 开启压缩召回(仅对对话/当前轮/轮次级三个压缩器生效)+ chunk_size_tokens: 3000 # 归档分块大小(tokens)+ chunk_overlap_tokens: 500 # 相邻分块重叠(tokens,须小于 chunk_size_tokens)++ # 消息摘要卸载器:把超大的工具消息摘要化卸载(保留 [[OFFLOAD:...]] 索引,可重载)message_summary_offloader_config:- add_message_threshold_ratio: 0.1- ttl_seconds: 300- ttl_context_occupancy_ratio: 0.5- ttl_message_threshold_ratio: 0.05+ protected_tool_names: ["read_file", "read_pdf"] # 这些工具的输出保持原文,不卸载+ add_message_threshold_ratio: 0.1 # 新增工具消息超过上下文窗口容量的该比例时,立即卸载+ ttl_seconds: 300 # 距上次模型请求空闲超过该秒数后,才允许做 TTL(闲时)卸载+ ttl_context_occupancy_ratio: 0.5 # 上下文占用超过该比例时,才允许做 TTL 卸载+ ttl_message_threshold_ratio: 0.05 # TTL 卸载时,单条工具消息超过窗口容量的该比例才被处理++ # 会话记忆:压缩发生前把已提交的关键信息沉淀为 session memory 笔记,+ # 后续作为压缩上下文块注入。默认关闭。+ # 配置分两层:外层是压缩器本体(何时触发、笔记多大);+ # 内层 memory 是异步更新器(SessionMemoryManager,由独立 agent/模型后台更新笔记)的行为参数。+ session_memory_compressor_config:+ enabled: false # true 开启会话记忆+ trigger_context_ratio: 0.8 # 上下文占用达到该比例时使用更新的笔记替换上下文、建议sessionmemory的阈值要小于等于下面的compressor,开启是下面的compressor作为兜底设计+ memory:+ update_trigger_context_ratio: 0.1 # 上下文占用达到该比例时异步更新记忆++ # 对话压缩器:整体对话历史超长时,把旧对话压缩成摘要dialogue_compressor_config:- trigger_context_ratio: 0.8- min_target_context_ratio: 0.1+ trigger_context_ratio: 0.8 # 上下文占用达到该比例时触发压缩+ min_target_context_ratio: 0.1 # 压缩目标下限(占窗口比例)++ # 当前轮次压缩器:单轮对话(含工具调用链)过长时压缩当前轮current_round_compressor_config:- trigger_context_ratio: 0.8- min_target_context_ratio: 0.1- keep_recent_messages: 4+ trigger_context_ratio: 0.8 # 上下文占用达到该比例时触发压缩+ min_target_context_ratio: 0.1 # 压缩目标下限(占窗口比例)+ keep_recent_messages: 4 # 保留最近消息数++ # 轮次级别压缩器:多轮长对话的三轮渐进式压缩(最强力,最后触发)round_level_compressor_config:- trigger_context_ratio: 0.8- min_target_context_ratio: 0.1- keep_recent_messages: 4+ trigger_context_ratio: 0.8 # 上下文占用达到该比例时触发压缩+ min_target_context_ratio: 0.1 # 压缩目标下限(占窗口比例)+ keep_recent_messages: 4 # 保留最近消息数+# 连续相同 reasoning+工具集 / 相同工具入参时,折叠重复轮次;超阈值后兜底中止reasoning_tool_loop_compact_config:enabled: true # 是否启用循环压缩diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.pyindex 15cc548ce3..57b545b753 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py@@ -33,7 +33,7 @@ if TYPE_CHECKING:from jiuwenswarm.server.runtime.agent_config_service import AgentDefinitionimport yaml-from openjiuwen.core.context_engine.schema.config import ContextEngineConfig+from openjiuwen.core.context_engine.schema.config import CompressionRecallConfig, ContextEngineConfigfrom openjiuwen.core.foundation.kv_cache import KVCacheAffinityConfigfrom openjiuwen.core.foundation.llm import ModelRequestConfig, ModelClientConfig, Modelfrom openjiuwen.core.foundation.llm.utils.provider_utils import is_openai_account_provider@@ -1180,12 +1180,26 @@ def _deep_agent_context_engine_config(react_cfg: dict[str, Any] | None) -> Contereact_cfg = react_cfg or {}cec = react_cfg.get("context_engine_config")cec = cec if isinstance(cec, dict) else {}+ recall = cec.get("compression_recall_config")+ recall = recall if isinstance(recall, dict) else {}return ReActAgentConfig().context_engine_config.model_copy(update={"enable_reload": bool(cec.get("enable_reload", False)),"enable_openrouter_model_context_window_tokens": bool(cec.get("enable_openrouter_model_context_window_tokens", False)),+ # 显式设置的上下文窗口上限;非法值回退 None(由 agent-core 按模型解析)+ "context_window_tokens": parse_int(cec.get("context_window_tokens"), None),+ # 上下文压缩 debug 落盘开关;目录缺省时由 agent-core 按+ # OPENJIUWEN_CONTEXT_DEBUG_DIR / workspace 默认路径解析+ "enable_context_debug": bool(cec.get("enable_context_debug", False)),+ "context_debug_dir": cec.get("context_debug_dir") or None,+ # 压缩召回:压缩时归档原始消息,供模型按需召回+ "compression_recall_config": CompressionRecallConfig(+ enabled=bool(recall.get("enabled", False)),+ chunk_size_tokens=parse_int(recall.get("chunk_size_tokens"), 3000),+ chunk_overlap_tokens=parse_int(recall.get("chunk_overlap_tokens"), 300),+ ),})@@ -1264,6 +1278,11 @@ def _build_context_processor_rail(config: dict[str, Any]) -> ContextProcessorRaiif isinstance(offloader_cfg, dict) and offloader_cfg:user_processors.append(("MessageSummaryOffloader", offloader_cfg))+ # 会话记忆:preset 链中默认为禁用,此处用配置覆盖启用+ session_memory_compressor_cfg = context_engine_cfg.get("session_memory_compressor_config", {})+ if isinstance(session_memory_compressor_cfg, dict) and session_memory_compressor_cfg:+ user_processors.append(("SessionMemoryCompressor", session_memory_compressor_cfg))+compressor_cfg = context_engine_cfg.get("dialogue_compressor_config", {})if isinstance(compressor_cfg, dict) and compressor_cfg:user_processors.append(("DialogueCompressor", compressor_cfg))