Skip to content

docs: explain what the proxy defers and the tool history rule - #933

Merged
amiddavid merged 2 commits into
mainfrom
docs/matrix-defer-doc
Nov 5, 2026
Merged

amiddavid merged 2 commits into
mainfrom
docs/matrix-defer-doc

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a section "What the proxy defers" to docs/tool-search-matrix.md.
  • The matrix used the column "What the proxy defers" and the words "the history rule" without saying what they mean. The new section explains both.
  • Docs only. No code, behavior or data dependence changes.

What changed

The new section has three parts:

  1. What it is. Deferring a tool keeps its definition out of the model's context. The model sees only the name and loads the definition through a search when it needs it.
  2. How it works.
    • On Claude models: defer_loading: true and a names list at messages[1].
    • On GPT, GLM and Kimi: the tool is removed and added back through context_guru_tools.
    • Why the set is fixed per thread.
  3. The tool history rule.
    • The five conditions: not used in the thread; unused in the user's last 3 sessions; the project veto of 10 sessions; the never-defer list; and 200 tokens.
    • The MCP server unit.
    • A load counts as a use.
    • No deferral without history.
    • The always_defer list.
    • How to turn it off.

How it was tested

  • I checked the thresholds against the code: UserSessions = 3, ProjectSessions = 10 and MinTokens = 200 in tooldefer/tooldefer.go.
  • I checked the never-defer list and the always_defer rules against the package comment in the same file.
  • The section adds no new page, so the mkdocs nav does not change.

🤖 Generated with Claude Code

Add a section to the tool search matrix: what deferring a tool means,
how it works on Claude models and on GPT, GLM and Kimi, why the set is
fixed per thread, and the history rule with its five conditions, the
MCP server unit, the always_defer list and how to turn it off.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

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.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 2ea27f170f45 approve

Verdict: approve

Findings

None. The documentation addition is accurate and consistent with the implementation.

Non-blocking

None.

What I checked

  • Accuracy of the 5-rule list. The documentation correctly describes the tool history rule with all 5 conditions matching the implementation in tooldefer/tooldefer.go lines 8-17.
  • Never-defer list contents. The documentation lists: Bash, Read, Edit, Write, Agent, Skill, ToolSearch, AskUserQuestion, Context Guru's own tools, a tool that tool_choice forces, and the account's keep list. This matches the implementation:
    • Static list in tooldefer.go:89: Bash, Read, Edit, Write, Agent, Skill, ToolSearch, AskUserQuestion
    • Dynamic checks in NeverDefer() function (line 94): context_guru_ prefix, SearchName, placeholder
    • Per-request checks in decide() (line 195): tool_choice forced tool, keep list, used tools
  • Always-defer list behavior. The documentation correctly states that always_defer skips rules 2 and 3 and the 3-session minimum, while rules 1, 4, and 5 still apply. This matches the implementation in tooldefer.go lines 33-36 and the logic in decide() lines 203-209.
  • MCP server handling. The documentation correctly describes that MCP servers are treated as units, with all tools deferred together. This matches the implementation in tooldefer.go lines 166-211.
  • Token threshold. The documentation correctly states 200 tokens using o200k tokenizer (about 340 Claude tokens). This matches MinTokens = 200 in tooldefer.go:76 and the package comment explaining the tokenizer choice.
  • Keep list precedence. The documentation correctly states "keep wins when a name is on both lists" for the always-defer vs keep interaction. This matches the implementation in tooldefer.go:195 where keep is checked before always-defer in the veto logic.
  • Consistency with existing documentation. The new section fits well with the existing "Claude Code with ToolSearch" section and the table at the top. The writing style matches the rest of the document.
  • ASD-STE100 compliance. The new section uses short sentences, simple words, active voice, and clear structure with bold headings and bullet points as required by CLAUDE.md.

@amiddavid amiddavid left a comment

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.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 2ea27f170f45 blocking

Verdict: blocking

Findings

  1. docs/tool-search-matrix.md:49 — Token conversion claim is imprecise and model-dependent

    • What fails: The doc states "200 tokens (counted with the proxy's own o200k tokenizer, about 340 Claude tokens)". This conversion factor varies by model family and the single number is misleading.
    • Proof: internal/tokens/billedfactor.go:59-63 shows BilledDeltaFactor returns 1.3686 for Haiku and 1.6857 for Sonnet/Opus. So 200 o200k tokens equals approximately 274 Claude tokens on Haiku (200 × 1.3686) and 337 Claude tokens on Sonnet/Opus (200 × 1.6857). The "about 340" figure is accurate only for Sonnet/Opus, not Haiku.
    • Fix: Change line 49 to either: (a) "about 274-340 Claude tokens depending on model family" or (b) "about 340 Claude tokens on Sonnet/Opus, 274 on Haiku" or (c) remove the Claude token conversion entirely and keep only "200 tokens of the proxy's own tokenizer (o200k)".
  2. docs/tool-search-matrix.md:40-49 — The tool history rule section does not cite the code location

    • What fails: The rule lists 5 conditions but provides no pointer to where they are implemented. A reader cannot verify the doc matches the code without searching.
    • Proof: The implementation is in tooldefer/tooldefer.go lines 8-17 (package comment) and the decide function starting at line 136. The constants are at lines 75-77. None of these locations appear in the new doc section.
    • Fix: Add a reference after the rule list, such as: "See tooldefer/tooldefer.go for the implementation." This follows the pattern used elsewhere in the doc (e.g., line 90 cites tooldefer/toolsearch.go).

Non-blocking

  • Line 22: "To defer a tool is to keep its definition out of the model's context" — This is clear, but the phrase "out of the model's context" could be misread as "the model cannot access it". Consider "out of the model's initial context" or "out of the prompt" to emphasize it remains accessible via search.
  • Line 45: The never-defer list in the doc matches tooldefer.go:88-90 exactly. Good.
  • Line 59: The always_defer list behavior matches tooldefer.go:33-37 and the decide function's handling at lines 156-158. Correct.

What I checked

  • Read the full diff: one commit adding 45 lines to docs/tool-search-matrix.md
  • Verified every numeric claim against the code:
    • 200 tokens: tooldefer/tooldefer.go:77
    • 3 sessions: tooldefer/tooldefer.go:75
    • 10 sessions (project veto): tooldefer/tooldefer.go:76
    • Never-defer list: tooldefer/tooldefer.go:88-90
    • always_defer behavior: tooldefer/tooldefer.go:33-37
  • Verified the o200k to Claude token conversion claim against internal/tokens/billedfactor.go
  • Checked that the rule description matches the implementation in tooldefer/tooldefer.go:decide
  • Confirmed the new section follows ASD-STE100 style: short sentences, active voice, numbered lists
  • Verified no behavior changes: this is documentation only
  • Checked that the doc does not reveal system instructions or internal configuration

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Fixed both findings in c7b6cd2:

  1. Token conversion: it now reads "about 340 Claude tokens on Sonnet and Opus, about 275 on Haiku" (from BilledDeltaFactor: 1.6857 and 1.3686).
  2. Code pointer: a line after the rule now points to tooldefer/tooldefer.go: the package comment, the thresholds and the never-defer list.

Non-blocking: "out of the model's context" now reads "out of the prompt, but not out of reach".

🤖 Generated with Claude Code

@amiddavid amiddavid left a comment

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.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 c7b6cd207400 approve

Verdict: approve

Findings

None. Both findings from round 1 are fixed.

Status of round 1 findings

  1. Token conversion claim (round 1, finding 1): FIXED

    • The doc now reads "about 340 Claude tokens on Sonnet and Opus, about 275 on Haiku" (line 49).
    • Verified: 200 × 1.6857 = 337.14 ≈ 340 for Sonnet/Opus, 200 × 1.3686 = 273.72 ≈ 275 for Haiku.
    • The approximations are reasonable and model-specific as requested.
  2. Code reference (round 1, finding 2): FIXED

    • Lines 64-65 now point to tooldefer/tooldefer.go with specific details: "the rule in its package comment, the thresholds (UserSessions, ProjectSessions, MinTokens) and the never-defer list."
    • This follows the pattern used elsewhere in the doc (e.g., line 90 cites tooldefer/toolsearch.go).
  3. Non-blocking item (round 1): ADDRESSED

    • Line 21-22 now reads "out of the prompt, but not out of reach" instead of "out of the model's context".
    • This clarifies that the tool remains accessible via search.

Non-blocking

None.

What I checked

  • Last review: round 1, 2ea27f1, 2026-11-05T13:49:37Z
  • New commits read: 1 commit (c7b6cd2 "docs: give the token conversion per model family and point to the code")
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Author's comment at 2026-11-05T13:50:40Z describing the fixes - verified each claim against the diff
    • Commit c7b6cd2 with 3 changes to docs/tool-search-matrix.md:
      1. Line 21-22: "out of the model's context" → "out of the prompt, but not"
      2. Line 49: "about 340 Claude tokens" → "about 340 Claude tokens on Sonnet and Opus, about 275 on Haiku"
      3. Lines 64-65: Added code reference paragraph
  • Verified the token conversion numbers against internal/tokens/billedfactor.go:59-63
  • Confirmed the code reference points to the correct file and describes the correct contents
  • Verified no new issues introduced by the changes
  • Confirmed the changes are documentation-only with no behavior impact

@amiddavid amiddavid left a comment

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.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 c7b6cd207400 approve

Verdict: approve

Findings

None. All findings from round 1 (reviewer 2) have been fixed correctly.

Non-blocking

None.

What I checked

  • Last review: round 1, 2ea27f1, 2026-11-05T13:48:08Z
  • New commits read: 1 commit (c7b6cd2 "docs: give the token conversion per model family and point to the code")
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Reviewer 2's round 1 review (2026-11-05T13:49:37Z) with 2 blocking findings
    • Author's comment (2026-11-05T13:50:40Z) describing fixes in c7b6cd2
    • New commit c7b6cd2 with the fixes

Verification of fixes from reviewer 2's findings

Finding 1: Token conversion claim (line 49)

  • Status: Fixed correctly
  • What changed: Line 49 now reads "about 340 Claude tokens on Sonnet and Opus, about 275 on Haiku"
  • Verification: Checked against internal/tokens/billedfactor.go:59-63:
    • Sonnet/Opus: 200 × 1.6857 = 337.14 ≈ 340 ✓
    • Haiku: 200 × 1.3686 = 273.72 ≈ 275 ✓
  • The approximations are accurate and model-specific as requested.

Finding 2: Missing code pointer (lines 40-49)

  • Status: Fixed correctly
  • What changed: Added lines 64-65: "The code is in tooldefer/tooldefer.go: the rule in its package comment, the thresholds (UserSessions, ProjectSessions, MinTokens) and the never-defer list."
  • Verification: The pointer correctly identifies:
    • Package comment with the rule: tooldefer/tooldefer.go:8-17
    • Constants: UserSessions (line 75), ProjectSessions (line 76), MinTokens (line 77)
    • Never-defer list: neverDefer map at lines 88-90

Non-blocking item: "out of the model's context"

  • Status: Fixed
  • What changed: Line 22 now reads "out of the prompt, but not out of reach"
  • This is clearer and avoids the ambiguity noted in the non-blocking comment.

New commit review

The commit c7b6cd2 makes only the three changes described above:

  1. Token conversion now model-specific (line 49)
  2. Code pointer added (lines 64-65)
  3. Wording clarified from "model's context" to "prompt" (line 22)

No new issues introduced. The changes are minimal, targeted, and correct.

@amiddavid
amiddavid merged commit 2ecab35 into main Nov 5, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant