feat(agent): add isContextOverflowError utility

Detects context overflow 400 errors from various LLM providers
(prompt too long, context length exceeded, request too large, etc.)
for use in auto-compaction recovery.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yushen 2026-02-12 14:43:33 +08:00
parent 5c3fd3ea06
commit f8ca4ca95e

View file

@ -0,0 +1,21 @@
/**
* Error classification utilities for agent error handling.
*/
/**
* Check if an error is a context overflow / "prompt too long" error from any LLM provider.
*
* These errors indicate the request exceeded the model's context window and should
* trigger auto-compaction rather than auth profile rotation.
*/
export function isContextOverflowError(error: unknown): boolean {
const msg = (error instanceof Error ? error.message : String(error)).toLowerCase();
return (
msg.includes("prompt is too long") ||
msg.includes("context length exceeded") ||
msg.includes("maximum context length") ||
msg.includes("request_too_large") ||
msg.includes("request size exceeds") ||
(msg.includes("413") && msg.includes("too large"))
);
}