Skip to content

fix(agentic-enhancer): cap conversation input to avoid context overflow#105

Open
gadievron wants to merge 1 commit into
masterfrom
fix/agentic-enhancer-cap-conversation-input-to-avoid-context
Open

fix(agentic-enhancer): cap conversation input to avoid context overflow#105
gadievron wants to merge 1 commit into
masterfrom
fix/agentic-enhancer-cap-conversation-input-to-avoid-context

Conversation

@gadievron

Copy link
Copy Markdown
Collaborator

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

Coordination

Touches a file also modified by in-flight PR #51/#60 (region-disjoint; textual merge only).

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant