Repository navigation
Conversation
996e687 to
a1c6586
Compare
a1c6586 to
7712906
Compare
0295fd7 to
1b6395a
Compare
b9e6489 to
7cbab3d
Compare
0edbab2 to
2d686ca
Compare
A tool result larger than half of what is left of the context budget is shortened before the model sees it. A tool that can size its own answer, e.g. by leaving out older articles of a ticket, does better than a cut afterwards, but it cannot know the limit. tool_result_budget() returns how many characters a tool result of the current run can have. The agent updates it for every request to the model, from the same calculation that shortens results, so tools read the value of the latest request. It is None outside of a run. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
2d686ca to
3dbac77
Compare
868eb9c to
54967ca
Compare
3dbac77 to
a9feebb
Compare
54967ca to
58d2da5
Compare
|
Thanks, this is cleanly done, and taking
For Zammad I'd rather follow the pattern other tools here already use ( If we later need content-aware cutting, such as always keeping the first customer message, that should go into the agent's truncation, for example as a hint from the tool about which items to keep. That way the budget stays with the agent. So I'd suggest closing this and changing #335 to use paging. |
|
Great feedback! I'll do exactly what you proposed now, thank you |
Lets tools know how large their result may be before it is shortened.
Base: #338 (
feat/shorten-json-objects). Merge #338 first. #335 builds on this PR.Why
A tool result larger than half of what is left of the context budget is shortened before the model sees it. A tool that can size its own answer, for example by leaving out older articles of a ticket, does better than a cut afterwards, but it has no way to know the limit, so it would have to guess a fixed number that only fits the default context budget.
What
tool_result_budget()returns how many characters a tool result of the current run can have without being shortened. Outside of a run it returnsNone._compact_current_turn()uses (max_tool_result_chars()), so tools read the value of the latest request.The first user is the Zammad tools in #335, which pass the budget to integration_zammad so a ticket is cut at article boundaries.
80 lines added, 4 removed.
How to test
python -m pytest tests. New tests intests/test_context_window.pycheck that the budget reaches tools that run in tasks of their own, and that the agent sets it below half the budget once instructions and tools are counted.🤖 AI (if applicable)
Code, tests and this description were drafted with Claude Code (claude-opus-5-5) under my direction.
Generated by Claude Code