diff --git a/run_agent.py b/run_agent.py index 4c0d3be4b..36452bc68 100644 --- a/run_agent.py +++ b/run_agent.py @@ -1748,10 +1748,25 @@ class AIAgent: aux_base_url = str(getattr(client, "base_url", "")) aux_api_key = str(getattr(client, "api_key", "")) + + # Read user-configured context_length for the compression model. + # Custom endpoints often don't support /models API queries so + # get_model_context_length() falls through to the 128K default, + # ignoring the explicit config value. Pass it as the highest- + # priority hint so the configured value is always respected. + _aux_cfg = (self.config or {}).get("auxiliary", {}).get("compression", {}) + _aux_context_config = _aux_cfg.get("context_length") if isinstance(_aux_cfg, dict) else None + if _aux_context_config is not None: + try: + _aux_context_config = int(_aux_context_config) + except (TypeError, ValueError): + _aux_context_config = None + aux_context = get_model_context_length( aux_model, base_url=aux_base_url, api_key=aux_api_key, + config_context_length=_aux_context_config, ) threshold = self.context_compressor.threshold_tokens