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:
parent
5c3fd3ea06
commit
f8ca4ca95e
1 changed files with 21 additions and 0 deletions
21
packages/core/src/agent/errors.ts
Normal file
21
packages/core/src/agent/errors.ts
Normal 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"))
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue