mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-29 06:28:23 +02:00
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:
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"))
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user