(
body: dict[str, Any],
*,
model: str,
session_id: str | None,
step_type: str,
)
| 51 | |
| 52 | |
| 53 | def apply_openai_cache_hints( |
| 54 | body: dict[str, Any], |
| 55 | *, |
| 56 | model: str, |
| 57 | session_id: str | None, |
| 58 | step_type: str, |
| 59 | ) -> CacheRequestPlan: |
| 60 | tools = body.get("tools") or body.get("customTools") or [] |
| 61 | if not session_id and not tools and step_type == "general": |
| 62 | return CacheRequestPlan(family="openai") |
| 63 | |
| 64 | key = _stable_prompt_cache_key(body, model=model, session_id=session_id, step_type=step_type) |
| 65 | if key: |
| 66 | body["prompt_cache_key"] = key |
| 67 | |
| 68 | retention = "" |
| 69 | if _is_openai_cache_retention_model(model): |
| 70 | retention = "24h" if (session_id and (step_type != "general" or tools)) else "in-memory" |
| 71 | body["prompt_cache_retention"] = retention |
| 72 | |
| 73 | return CacheRequestPlan( |
| 74 | family="openai", |
| 75 | mode="prompt_cache_key", |
| 76 | prompt_cache_key=key, |
| 77 | retention=retention, |
| 78 | ) |
| 79 | |
| 80 | |
| 81 | def apply_anthropic_cache_breakpoints( |
no test coverage detected