refactor: redesign context config with orthogonal model and add /compact command#9346
Open
Rail1bc wants to merge 6 commits into
Open
refactor: redesign context config with orthogonal model and add /compact command#9346Rail1bc wants to merge 6 commits into
Rail1bc wants to merge 6 commits into
Conversation
…rigger/disposal model Replace the old implicit-value config (-1 = no limit, <=0 = disabled) with explicit bool switches and a clean separation between trigger conditions (WHEN) and disposal behaviors (WHAT). Core changes: - ContextConfig: 7 old fields → 12 orthogonal fields + summary_provider - ContextManager.process(): independent trigger checks → unified disposal (summary first, discard fallback) → retention constraint → double-check - Add _migra_context_config() + _validate_context_config() migration helpers for zero-downtime config upgrade Co-Authored-By: deepseek-v4-flash <deepseek-ai@claude-code-best.win>
… agent pipeline - Add new context_management config fields to MainAgentBuildConfig - Update default config with new orthogonal trigger/disposal defaults - Thread context_config through ToolLoopAgentRunner and agent sub-stages - Update existing tests to match new config field names and defaults Co-Authored-By: deepseek-v4-flash <deepseek-ai@claude-code-best.win>
…ocales Replace old truncate_and_compress keys with new context_management field translations covering all 13 new trigger/disposal fields. Updates zh-CN, en-US, and ru-RU locale files. Co-Authored-By: deepseek-v4-flash <deepseek-ai@claude-code-best.win>
Add comprehensive test suites for: - ContextConfig validation and field defaults - Context migration helpers (_migra_context_config, _validate_context_config) - MainAgentBuildConfig new context_management fields Co-Authored-By: deepseek-v4-flash <deepseek-ai@claude-code-best.win>
Add a /compact command that manually triggers ContextManager.process() on the current conversation, applying the orthogonal trigger/disposal model (summary first, discard fallback, retention bound, double-check) without fully clearing the conversation history. Includes shared helper extraction for /compact and /reset commands, robustness fixes (json corruption, None guards, multimodal content), and migration retention_method bug fix. Co-Authored-By: deepseek-v4-flash <deepseek-ai@claude-code-best.win>
Add comprehensive tests for: - ContextManager.process() with all disposal strategies - /compact command: permission, error handling, compression scenarios - Tool call metadata preservation across conversation round-trips - Edge cases: empty history, no-conversation, compressor failures Co-Authored-By: deepseek-v4-flash <deepseek-ai@claude-code-best.win>
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
Author
|
@sourcery-ai review |
Contributor
|
Sorry @Rail1bc, your pull request is larger than the review limit of 150000 diff characters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
重构上下文管理配置模型,使其更加正交、可组合,并新增
/compact命令支持主动触发压缩。解决 #9252、#8348、#9281 等 issue 的实际需求。核心变更
summary_provider字段_migra_context_config()+_validate_context_config()覆盖全部旧→新字段映射,自动迁移,向后兼容context_management结构,13 个新字段翻译/compact命令:手动触发压缩,读取对话历史 →ContextManager.process()→ 写回 DB。第三方 runner 跳过,异常保留上下文,群聊非隔离默认仅管理员/compact回归测试,总计 220 passed,6 failed(6 个为预先存在的失败,与本 PR 无关)Modifications / 改动点
astrbot/core/agent/context/config.pyastrbot/core/agent/context/manager.pyastrbot/core/agent/runners/tool_loop_agent_runner.pyastrbot/core/astr_main_agent.pyastrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.pyastrbot/core/config/default.pyastrbot/core/utils/migra_helper.py_migra_context_config()+_validate_context_config()dashboard/src/i18n/locales/en-US/features/config-metadata.jsondashboard/src/i18n/locales/ru-RU/features/config-metadata.jsondashboard/src/i18n/locales/zh-CN/features/config-metadata.jsonastrbot/builtin_stars/builtin_commands/commands/conversation.py/compact命令 + 共享 helpersastrbot/builtin_stars/builtin_commands/main.py@filter.command("compact")Test Results
(6 failed 为预先存在的测试失败,非本 PR 引入)
tests/agent/test_context_config_new.pytests/agent/test_context_manager_new.pytests/unit/test_context_migration.pytests/unit/test_main_agent_build_config_new.pytests/agent/test_context_manager.pytests/test_conversation_commands.py/compact权限/错误处理/压缩场景/元数据保留tests/unit/test_astr_main_agent.py覆盖路径:
enable_turn_limit/enable_token_guard(含阈值边界 0.5~0.99)enable_summary=false→ discardChecklist
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
[] 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。