Commit 3b099d5
committed
feat(sandbox): add LiteLLMCompaction capability sized via litellm
Add `agents.extensions.sandbox.LiteLLMCompaction`, a drop-in subclass
of `agents.sandbox.capabilities.Compaction` whose default policy is
sized from `litellm.get_model_info()` rather than the OpenAI-only
context-window registry.
The default `Compaction` registry catalogues OpenAI families only, so
litellm-routed models (Anthropic, Bedrock, Vertex, custom proxy
aliases, ...) miss the lookup and fall back to a hard-coded 240k
`StaticCompactionPolicy` regardless of the model's actual input
window — compacting a 1M-context model at the same point as a 200k
model.
`LiteLLMCompaction` exposes two classmethods:
- `for_model(model, *, threshold=0.8)` resolves the cap via
`litellm.get_model_info()`. Falls back to a 200k window with a
WARNING when litellm has no entry (new beta IDs, custom proxy
aliases, Bedrock embedding entries with no `max_input_tokens`).
- `for_context_window(context_window, *, threshold=0.8)` builds the
same policy from an explicitly-provided cap, for callers whose
config layer already applies per-org ceilings or test overrides.
Purely additive — no released APIs change. Gated behind the existing
`openai-agents[litellm]` optional extra via
`raise_optional_dependency_error`, and exported from
`agents.extensions.sandbox` only when the extra is installed.1 parent 05492cd commit 3b099d5
1 file changed
Lines changed: 2681 additions & 3386 deletions
0 commit comments