fix(agentic-enhancer): cap conversation input to avoid context overflow#105
Open
gadievron wants to merge 1 commit into
Open
fix(agentic-enhancer): cap conversation input to avoid context overflow#105gadievron wants to merge 1 commit into
gadievron wants to merge 1 commit into
Conversation
The agent built the LLM conversation with no input budget: get_user_prompt inlined primary_code verbatim (prompts.py) and the loop appended raw, untruncated tool results every iteration via json.dumps(result) (agent.py append sites). On a large unit the constructed input grew without bound across iterations until it overflowed the model context (400), losing the enhancement. MAX_ITERATIONS=20 bounds depth but not per-item size. Operative guard: an input budget at the consumption points. - prompts.py: cap inlined primary_code (MAX_PRIMARY_CODE_CHARS). - agent.py: add cap_tool_result_content() and use it at both tool-result append sites (MAX_TOOL_RESULT_CHARS). - agent.py: graceful anthropic.BadRequestError (400) fallback returns a neutral incomplete result instead of crashing the enhancement. A deferred sibling is out of scope here: tools.py _read_function returns the whole function body uncapped; the consumption-point cap above contains it. Tests: tests/test_agent.py (5 tests, RED before fix). All passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The agent built the LLM conversation with no input budget: get_user_prompt
inlined primary_code verbatim (prompts.py) and the loop appended raw,
untruncated tool results every iteration via json.dumps(result) (agent.py
append sites). On a large unit the constructed input grew without bound across
iterations until it overflowed the model context (400), losing the
enhancement. MAX_ITERATIONS=20 bounds depth but not per-item size.
Operative guard: an input budget at the consumption points.
append sites (MAX_TOOL_RESULT_CHARS).
incomplete result instead of crashing the enhancement.
A deferred sibling is out of scope here: tools.py _read_function returns the
whole function body uncapped; the consumption-point cap above contains it.
Tests: tests/test_agent.py (5 tests, RED before fix). All passing.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Coordination
Touches a file also modified by in-flight PR #51/#60 (region-disjoint; textual merge only).