The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: parse the "limited to N" output-cap figure so the budget steps down
teknium15eb31233b451
diff --git a/agent/model_metadata.py b/agent/model_metadata.pyindex f93ecb79647..eeeca1812d6 100644--- a/agent/model_metadata.py+++ b/agent/model_metadata.py@@ -1284,6 +1284,8 @@ def parse_available_output_tokens_from_error(error_msg: str) -> Optional[int]: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+)',+ # 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)@@ -1345,6 +1347,7 @@ _PARSEABLE_OUTPUT_CAP_SIGNALS = (("maximum context length", "requested", "output tokens"),("range of max_tokens should be",), ("exceeds model", "maximum output tokens"),("output limit",), ("max_tokens", "maximum allowed number of output tokens"),+ ("limited to",),)diff --git a/tests/agent/test_output_cap_parsing.py b/tests/agent/test_output_cap_parsing.pyindex 6953abd8a2f..f21fac74151 100644--- a/tests/agent/test_output_cap_parsing.py+++ b/tests/agent/test_output_cap_parsing.py@@ -214,4 +214,5 @@ 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") == 16384assert not is_output_cap_error("prompt is too long: max_tokens limited to 100 given the input")diff --git a/website/docs/integrations/providers.md b/website/docs/integrations/providers.mdindex 785dbb8256d..bf1756e899e 100644--- a/website/docs/integrations/providers.md+++ b/website/docs/integrations/providers.md@@ -707,6 +707,7 @@ model:provider: custombase_url: http://localhost:8000/v1api_key: your-key-or-leave-empty-for-local+ # key_env: MY_PROVIDER_API_KEY # env var holding the key (alternative to api_key)```:::warning Legacy env vars