Skip to content

feat: 引入 Todo 任务规划及上下文管理优化#47

Merged
minorcell merged 12 commits into1024XEngineer:mainfrom
phantom5099:main
Mar 25, 2026
Merged

feat: 引入 Todo 任务规划及上下文管理优化#47
minorcell merged 12 commits into1024XEngineer:mainfrom
phantom5099:main

Conversation

@phantom5099
Copy link
Copy Markdown
Collaborator

类型 (Type of change):

  • Bug fix (修复了中英文混杂问题)
  • New feature (引入了 Todo List 功能)
  • Refactoring (优化了 Token 剪枝逻辑)

描述 (Description)

本次 PR 旨在解决 Agent 在处理复杂、多步骤任务时因“单 JSON 捕获”机制导致的 状态丢失 和 决策鲁棒性不足 的核心痛点。通过引入一个 显式的任务清单 (Todo List) ,我们将 Agent 从一个简单的“指令执行单元”升级为了一个具备初步 规划、执行、反思 能力的“任务处理单元”。

同时,为了支撑更长周期的任务,我们对上下文 Token 剪枝策略进行了深度优化,使其在保留关键信息和节省 Token 之间取得了更好的平衡。

主要变更 (Key Changes)

✨ 1. 功能: 显式任务规划 (Todo List)

  • 领域建模 : 在 domain 层新增了 Todo 结构体、 TodoService 和 TodoRepository 接口,遵循了整洁架构(Clean Architecture)的最佳实践。
  • todo 工具 : 为 Agent 新增了 todo 工具,使其能够通过 add , update , list 等动作来显式地管理自己的任务计划,将“隐性思考”转化为“显性状态”。
  • 上下文集成 : 当前的 [TODO_LIST] 会被自动注入到 Agent 的上下文(System Prompt)中,使其在每一轮决策时都能看到自己的“待办事项”,避免了任务遗忘。
  • UI 集成 : TUI 界面底部新增了“任务清单”面板,实时展示 Agent 的当前任务及状态( pending , in_progress , completed ),极大地提升了任务执行过程的可观测性。
  • 单元测试 : 为 TodoService 编写了完整的单元测试 ( todo_service_test.go ),覆盖了所有核心业务逻辑,确保了功能的稳定可靠。
    🚀 2. 优化: 智能 Token 剪枝
  • “头尾”截断策略 : 将长文本(如 read 工具输出)的截断方式从“仅保留头部”优化为**“保留头部 60% + 尾部 40%”**。这确保了在读取长代码或日志时,Agent 既能看到文件结构,也能看到末尾的关键报错信息。
  • 工具上下文“软压缩” : 对于超出保留窗口的旧工具执行结果,不再直接丢弃,而是进行“压缩”: 保留工具名和执行状态,但移除其详细输出 。这使得 Agent 能“记得”自己做过什么(避免重复操作),同时释放了大量 Token。
  • 配置中心化 : 将硬编码的剪枝阈值(如 max_tool_context_messages )统一移至 app_config.go ,允许通过配置文件进行动态调整,增强了灵活性。
    🛠️ 3. 维护与重构
  • 本地化 : 统一了项目中散落的英文错误提示为中文,保证了用户体验的一致性。

测试验证 (How Has This Been Tested?)

  • 单元测试 : 新增的 TodoService 单元测试已全部通过 ( go test ./internal/server/service/... )。

Copy link
Copy Markdown
Collaborator

@minorcell minorcell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体方向不错——Todo 任务规划、Token 剪枝优化、配置集中化都是有价值的改动,测试也补得比较扎实。以下是几处值得关注的 bug 和架构问题,请评估修复。

Comment thread internal/server/service/todo_service.go Outdated
Comment thread internal/tui/core/model.go Outdated
Comment thread configs/persona.txt
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里看上去写的更像是markdown?而不是 txt ?

Comment thread internal/server/domain/todo.go
Comment thread configs/persona.txt
import (
"context"
"fmt"
"go-llm-demo/internal/server/domain"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 “go-llm-demo” 是啥?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模块名字,之前刚开始初始化的时候用了这个名字

Comment thread internal/server/infra/tools/todo.go Outdated
Comment thread internal/server/service/chat_service.go Outdated
Comment thread internal/server/infra/tools/todo.go Outdated
Comment thread internal/server/service/chat_service.go Outdated
Comment thread internal/server/service/security_service.go
Comment thread internal/server/service/todo_service_test.go Outdated
@minorcell
Copy link
Copy Markdown
Collaborator

@phantom5099

中文编码、path问题就其他的PR解决吧。这个我先merge了

@minorcell minorcell merged commit 2166a82 into 1024XEngineer:main Mar 25, 2026
2 checks passed
phantom5099 added a commit that referenced this pull request Apr 22, 2026
refactor(runtime): hard-cut lifecycle/completion/facts semantics
pionxe pushed a commit to pionxe/neo-code that referenced this pull request May 2, 2026
…7608084

test(gateway): 补充 runtime snapshot/todo 分支覆盖
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants