Commit c199a2f
perf(agent): eliminate coordinator re-delegation waste — 50%+ latency reduction
Root cause (Minecraft benchmark): after sub-agent successfully executed file_write
(134s), the coordinator made a redundant R2 API call (131s) that re-called file_write,
followed by a 45s permission timeout. Total waste: 176s = 51% of 343s session.
Fixes applied:
1. mod.rs — Remove delegation-completed tools from coordinator's cached_tools
After sub-agent results are recorded, tools successfully executed by sub-agents
(file_write, bash, etc.) are removed from coordinator's cached_tools. The model
physically cannot call them again — eliminates the hallucination at protocol level.
Previous approach (synthetic "Task completed" message) was insufficient; deepseek-chat
ignored it and still called file_write with 6,196 output tokens.
2. mod.rs — Anti-re-delegation warning in sub-agent result injection
When file_write/bash/patch_apply were executed by sub-agents, inject explicit
CRITICAL warning into coordinator context: "do NOT call these tools again".
Belt-and-suspenders with Fix 1.
3. post_batch.rs — Force no-tools when only synthesis steps remain
After delegation, if all pending plan steps have no tool_name (synthesis-only),
suppress tools for coordinator's next round via tool_decision.set_force_next().
Prevents the synthesis round from offering tools the model might hallucinate.
Expected timing improvement (FileManagement/single-file tasks):
Before: ~343s (sub-agent 138s + coordinator R2 131s + permission 45s + overhead)
After: ~150s (sub-agent 138s + synthesis 5s + overhead)
Reduction: ~56%
3404 tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 2e33dd1 commit c199a2f
2 files changed
Lines changed: 98 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
655 | 655 | | |
656 | 656 | | |
657 | 657 | | |
658 | | - | |
| 658 | + | |
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
| |||
939 | 939 | | |
940 | 940 | | |
941 | 941 | | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
942 | 952 | | |
943 | 953 | | |
944 | 954 | | |
945 | 955 | | |
946 | 956 | | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
947 | 983 | | |
948 | | - | |
| 984 | + | |
949 | 985 | | |
950 | 986 | | |
951 | 987 | | |
| |||
987 | 1023 | | |
988 | 1024 | | |
989 | 1025 | | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
990 | 1059 | | |
991 | 1060 | | |
992 | 1061 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
384 | 411 | | |
385 | 412 | | |
386 | 413 | | |
| |||
0 commit comments