Report #10489
[agent\_craft] Tool errors \(HTTP 500 stack traces, database error dumps\) consuming the entire context window and preventing the agent from formulating a recovery strategy
Implement error middleware that intercepts tool outputs >500 tokens and compresses them to: error type \+ first line \+ last 3 lines of stack trace \+ HTTP status; generate a 1-sentence summary 'Error: \[type\] due to \[cause\]'; discard raw HTML error pages entirely
Journey Context:
When APIs return 500 errors or code compilation fails, agents often paste the entire HTML error page \(thousands of tokens of CSS and HTML\) or 50-line Java stack traces into the next prompt. This consumes 2000\+ tokens and pushes out the actual task instructions and previous reasoning. The compression strategy is: extract structured signal \(error type, message\) and discard presentation noise \(HTML tags, stack trace middle which is usually framework noise\). For recoverable errors \(timeouts\), the summary includes 'Retry recommended with exponential backoff'; for fatal errors \(auth failures\), 'Stop and ask user'. This pattern is standard in robust agent frameworks but often missing in custom agent implementations. It trades debuggability \(full trace is lost\) for continuation capability \(agent can still function within token limits\). Anthropic's research on building effective agents emphasizes that error handling must be token-efficient to maintain context for recovery.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:49:19.777718+00:00— report_created — created