LLM provider 上下文窗口溢出检测。
两路检测
- Error-based — provider 拒绝请求并返回包含已知模式的错误消息。
- Usage-based — 请求成功但报告的 input_tokens 超过上下文窗口。
溢出被归类为永久性错误(不重试,转而触发压缩)。
Summary
Functions
返回 true 如果错误字符串匹配已知的上下文窗口溢出模式。
返回所有溢出错误模式字符串列表。
返回 true 如果 input_tokens 超过 context_window。
Functions
返回 true 如果错误字符串匹配已知的上下文窗口溢出模式。
示例
iex> CMDC.Agent.Overflow.context_overflow?("context_length_exceeded")
true
iex> CMDC.Agent.Overflow.context_overflow?("rate_limit")
false
@spec overflow_patterns() :: [String.t()]
返回所有溢出错误模式字符串列表。
@spec usage_overflow?(non_neg_integer(), pos_integer()) :: boolean()
返回 true 如果 input_tokens 超过 context_window。
示例
iex> CMDC.Agent.Overflow.usage_overflow?(250_000, 200_000)
true