Determine whether to use max_completion_tokens instead of max_tokens. Newer OpenAI models (o1, o3, o4, gpt-4o, gpt-5, etc.) require max_completion_tokens. Anthropic and other providers still use max_tokens.
(model_name: str, base_url: str)
| 21 | |
| 22 | # (base_url, model_name) pairs whose provider rejected cache_control markers. |
| 23 | # Module-level because sub-agent runs re-create model instances per tool call |
| 24 | # (see generate_sub_module_documentations); the fallback probe should only |
| 25 | # happen once per provider/model, not once per sub-module. |
| 26 | _CACHE_UNSUPPORTED: set = set() |
| 27 | |
| 28 | _EPHEMERAL_CACHE = {"type": "ephemeral"} |
| 29 | |
| 30 | |
| 31 | def _add_cache_control_to_message(message) -> None: |
| 32 | """Attach an ephemeral ``cache_control`` marker to an OpenAI-format message in place. |
| 33 | |
| 34 | Tool messages get the marker at message level: OpenAI-compatible proxies |
| 35 | (e.g. LiteLLM) map that onto the Anthropic ``tool_result`` block, whereas a |
| 36 | part-level marker would land on a nested block, which Anthropic rejects. |
| 37 | Other roles get it on the last content part (string content is converted to |
| 38 | a single text part). |
| 39 | """ |
| 40 | if message.get("role") == "tool": |
| 41 | message.setdefault("cache_control", dict(_EPHEMERAL_CACHE)) |
no outgoing calls
no test coverage detected