Skip to content

The agent that grows with you

Merge remote-tracking branch 'origin/main' into HEAD

teknium11d5620ad87d3
diff --cc agent/model_metadata.py
index 30b10eab7d1,ad747c8d424..c4b34d8458d
--- a/agent/model_metadata.py
+++ b/agent/model_metadata.py
@@@ -1324,8 -1324,8 +1324,10 @@@ def parse_available_output_tokens_from_
r'available\s+tokens[:\s]+(\d+)',
# Switchyard: "max_tokens cannot exceed the configured model output limit of 16384".
r'output limit (?:of|is)\s*(\d+)',
+ # Azure OpenAI: "max_tokens is too large: 65536. This model supports at most 32768 completion tokens."
+ r'supports at most\s+(\d+)\s*(?:completion\s+)?tokens',
+ # Scaleway: "max_completion_tokens is limited to 16384 for glm-5.2".
+ r'(?:max_tokens|max_completion_tokens) is limited to\s*(\d+)',
r'=\s*(\d+)\s*$',
):
match = re.search(pattern, error_lower)
@@@ -1380,7 -1374,7 +1382,8 @@@ _OUTPUT_CAP_SIGNALS =
("in the output", "maximum context length"), ("requested", "output tokens"),
("should be",), ("less than or equal",), ("must be",), ("exceeds model", "maximum output tokens"),
("output limit",), ("maximum allowed number of output tokens",),
+ ("max_tokens is too large", "supports at most"), ("tokens from the input messages", "tokens for the completion"),
+ ("limited to",), # Scaleway: "max_completion_tokens is limited to 16384 for <model>" (#67453)
)
_INPUT_OVERFLOW_SIGNALS = (
"prompt is too long", "prompt too long", "input is too long", "input token",
@@@ -1397,7 -1391,7 +1400,8 @@@ _PARSEABLE_OUTPUT_CAP_SIGNALS =
("maximum context length", "in the completion"), ("maximum context length", "for the completion"),
("range of max_tokens should be",), ("exceeds model", "maximum output tokens"),
("output limit",), ("max_tokens", "maximum allowed number of output tokens"),
+ ("max_tokens is too large", "supports at most"), ("tokens from the input messages", "tokens for the completion"),
+ ("limited to",),
)
diff --cc tests/agent/test_output_cap_parsing.py
index a276097754a,efe786cc7cd..8578f69595c
--- a/tests/agent/test_output_cap_parsing.py
+++ b/tests/agent/test_output_cap_parsing.py
@@@ -210,30 -210,12 +210,36 @@@ class TestParseVllmTokenBasedOutputCap
+class TestParseAdvertisedCeilingWordings:
+ """Azure and SGLang name the ceiling without any phrase the parser knew (#78405, #83521).
+ Unrecognized, the 400 carried the bare ``max_tokens`` substring (or nothing at all) into
+ the compression path and a fresh session died with "cannot be shrunk further"."""
+
+ @pytest.mark.parametrize("msg, available", [
+ # Azure OpenAI (verbatim from #78405): the advertised completion ceiling IS the budget.
+ ("Error: max_tokens is too large: 65536. This model supports at most 32768 completion tokens.", 32768),
+ # SGLang (verbatim from #83521): window - input; never mentions max_tokens.
+ ("Requested token count exceeds the model's maximum context length of 131072 tokens. You requested "
+ "a total of 132528 tokens: 66992 tokens from the input messages and 65536 tokens for the completion. "
+ "Please reduce the number of tokens in the input messages or the completion to fit within the limit.",
+ 64080),
+ ])
+ def test_ceiling_is_parsed_and_classified_as_output_cap(self, msg, available):
+ assert parse_available_output_tokens_from_error(msg) == available
+ assert is_output_cap_error(msg) is True
+
+ def test_sglang_input_alone_over_window_routes_to_compression(self):
+ # Same wording, but the input by itself exceeds the window: shrinking the output cannot help.
+ msg = ("Requested token count exceeds the model's maximum context length of 100000 tokens. You requested "
+ "a total of 150000 tokens: 120000 tokens from the input messages and 30000 tokens for the completion.")
+ assert parse_available_output_tokens_from_error(msg) is None
+ assert is_output_cap_error(msg) is False
+ def test_limited_to_phrasing_is_an_output_cap():
+ """#67453: Scaleway rejects an oversized budget with "max_completion_tokens is limited to N for
+ <model>" — an output cap (step the budget down), not a context overflow (do not compress)."""
+ assert is_output_cap_error("max_completion_tokens is limited to 16384 for glm-5.2")
+ assert parse_available_output_tokens_from_error("max_completion_tokens is limited to 16384 for glm-5.2") == 16384
+ assert not is_output_cap_error("prompt is too long: max_tokens limited to 100 given the input")
class TestParseOpenAiCompletionSplit: