对比 TreeCode context tree 与原始线性上下文。
当前状态:pilot harness 已跑通,baseline 和 tree 各完成 1 次 smoke run;还不是统计结论。
-
实验开关:
TREECODE_CONTEXT_TREE=0/10:线性模式,禁用 tree 初始化和context_tree工具1:实验模式,第一次 prompt 自动建树,启用context_tree工具- 未设置:正常 TreeCode 行为,树通过
/tree初始化
-
agent 自主操作节点
- 新增内置工具
context_tree - 支持
list / switch / link / unlink / delete / root / compact - agent 可以先 list,再 link 指定分支
- 新增内置工具
-
无头运行
treecode run新增--directory,可以从 TreeCode 仓库运行,但把会话定位到任务工作区
-
实验环境
- 隔离配置:
config/opencode.json - 每次 run 独立 SQLite:
runs/<runID>/session.db - 自动采集 token、cost、tool calls、tree 节点/link、测试结果
- 隔离配置:
treecode-lab/
config/ 隔离的 OpenCode 配置
fixtures/ pilot 任务仓库
tasks/pilot/ pilot 任务定义
src/runner.ts 单次 run
src/report.ts 聚合报告
src/cli.ts CLI
runs/ 原始运行记录
results/ 聚合用单次结果
复制模板并填入凭据:
Copy-Item config/opencode.example.json config/opencode.json当前 config/opencode.json 已从本机 TreeCode 配置复制,包含 provider 和 model。
cd D:\deveTools\treecode-lab
# 线性基线
bun run src/cli.ts run --task repair-add --condition baseline --repeat 1
# TreeCode context tree
bun run src/cli.ts run --task repair-add --condition tree --repeat 1
# 多 seed
bun run src/cli.ts run --task pricing-service --condition baseline --seed 1 --repeat 3
# 聚合指定任务
bun run src/cli.ts report --task pricing-service可选环境变量:
TREE_CODE_DIR TreeCode 仓库路径,默认 D:/deveTools/opencode-context-tree
TREECODE_LAB_CONFIG 实验配置目录,默认 <lab>/config
TREECODE_MODEL 覆盖模型
TREECODE_AGENT 覆盖 agent,默认 build
| 条件 | 环境 | 说明 |
|---|---|---|
| baseline | TREECODE_CONTEXT_TREE=0 |
纯线性历史,无 tree 工具 |
| tree | TREECODE_CONTEXT_TREE=1 |
自动建树,agent 可用 context_tree |
| tree-link | TREECODE_CONTEXT_TREE=1 + link 提示 |
link 专用提示,需要多轮/多分支任务 |
- 测试是否通过
- token:input / output / reasoning / cache read / cache write
- 每次请求放入 agent 的上下文 token:每次 assistant 调用记录
input + cache read + cache write - 上下文 token 的 avg / max / first / last,以及逐次
perCall数组 - cost
- 运行时间
- agent 消息数、tool 调用数
context_tree调用数- tree 节点数、link 数、最大深度、compaction 数
- 原始事件:
runs/<runID>/events.jsonl - 会话导出:
runs/<runID>/export.json
repair-add,1 seed:
| condition | pass | total tokens | ctx avg | ctx max | tools | tree nodes | tree calls |
|---|---|---|---|---|---|---|---|
| baseline | 1/1 | 49,350 | 6,829 | 7,710 | 10 | 0 | 0 |
| tree | 1/1 | 51,248 | 7,044 | 8,009 | 11 | 1 | 1 |
tree run 中 agent 实际调用了 context_tree。这验证了工具链路,不代表性能结论。
pricing-service 复杂任务,3 seeds,8/9 初始测试失败:
| condition | pass | total tokens | ctx avg | ctx max | time | tools | tree calls |
|---|---|---|---|---|---|---|---|
| baseline | 3/3 | 72,945 | 9,650 | 14,575 | 228s | 13.7 | 0 |
| tree | 3/3 | 85,167 | 10,739 | 16,244 | 201s | 15.3 | 1 |
逐 seed 总 token:
| seed | baseline | tree |
|---|---|---|
| 1 | 86,942 | 80,564 |
| 2 | 71,258 | 67,306 |
| 3 | 60,634 | 107,631 |
3 seeds 后结论反转:tree 组平均总 token 更高,平均上下文也更高;tree 组略快,但差异不大。这个任务只有 1 个节点、没有 link,tree 主要体现为工具/上下文开销。
link-service,1 seed:
- 分支 A:调查 discount 缺陷,不改代码
- 新建 root:调查 shipping 缺陷,不改代码
- 最终分支:link 分支 A,再修复全部测试
| condition | pass | total tokens | ctx avg | ctx max | time | tools | links |
|---|---|---|---|---|---|---|---|
| baseline | 1/1 | 352,284 | 15,990 | 25,241 | 625s | 27 | 0 |
| tree | 1/1 | 225,663 | 8,825 | 18,494 | 749s | 40 | 0 |
| tree-link | 1/1 | 263,120 | 9,405 | 16,808 | 970s | 46 | 1 |
修复前的 full-link 版本:726,702 token,73 次工具调用,失败。
改为 link summary 后:263,120 token,46 次工具调用,通过。
link summary 默认只保留链接分支的:
- 用户 prompt
- assistant 的 text
- compaction summary
不注入 linked branch 的 tool calls、tool output 和 reasoning。
可用 TREECODE_CONTEXT_LINK_MODE=full 回到完整注入,用于对照。
这个任务仍是 1 seed:tree 和 tree-link 都通过,但 tree-link 比 tree 多花 token,说明 link 有价值但成本仍存在。
查看:
bun run src/cli.ts report --task link-service上下文 token 定义:
perCall = assistant.tokens.input + assistant.tokens.cache.read + assistant.tokens.cache.write
ctx avg = mean(perCall)
ctx max = max(perCall)
total tokens 是整段会话累计值;ctx avg/max 是每次模型请求实际携带的 prompt 上下文大小。
本地 pilot 用于验证 harness。正式实验建议:
- SWE-bench Lite / Verified
- 需要 Linux + Docker 或远程 Linux runner
- 当前机器没有 Docker/WSL,不能直接跑官方 harness
- 适配方式:每个任务 clone 仓库到固定 commit,应用 test patch,运行官方 tests
- Terminal-Bench 2.0
- 同样依赖容器环境
- Aider polyglot
- 可作为 Windows 友好的补充
- 需要按语言配置测试命令
- Link 压力测试
- 从同仓库配对 issue 构造多分支任务
- 标注应该 link 的目标节点,计算 link precision/recall
任务 JSON 格式:
{
"id": "repair-add",
"fixture": "fixtures/repair-math",
"prompt": "...",
"test": "bun test",
"timeoutSec": 600
}fixture 也可以是绝对路径的已 checkout 仓库。
- 只有 1 个 pilot 任务,不能做统计结论
- tree-link 需要多轮任务,当前 runner 是单 prompt
- 没有 Docker/WSL,官方 SWE-bench 需要远程 Linux 环境
- 模型可能不使用
context_tree,需要在任务提示或策略层强制/引导 - 当前报告只做均值,正式实验需要配对检验和置信区间
- 增加多轮 runner,支持中途 switch/link/compact
- 增加 SWE-bench/Linux 远程适配
- 增加 20–50 个 pilot 任务
- 跑 baseline/tree/tree-link 各 3 seeds
- 输出 success vs token/cost Pareto 曲线