Plan Pressure Evictions • AI Agent SDK
plan_pressure_evictions: Return the “session_id“s to soft-evict, coldest (LRU) first.
plan_pressure_evictions
Function
</div>
This function is defined in the protocols module.
Return the `session_id`s to soft-evict, coldest (LRU) first.
A pure planner: it takes the container memory budget (typically the cgroup limit), the current anonymous `rss_mb and the warm-cache registry, and names the coldest rebuildable caches to shed until RSS is back within headroom_ratio` of the budget. It never touches the event loop or the caches themselves — the gateway enacts the returned plan.
Guards (a victim is skipped, never evicted, when):
- `
in_flightisTrue` — an executing turn must not be aborted, or - `
flushedisFalse` — an unflushed transcript is not yet rebuildable - from the store, so evicting it would lose data.
Returns an empty list when RSS is within budget, the budget is unknown (`None/<= 0`), or nothing evictable remains — so a host that can’t report a cgroup limit simply never soft-evicts (legacy behaviour).
Signature
def plan_pressure_evictions(budget_mb: Optional[float], rss_mb: float, warm_sessions: Sequence[WarmSession]) -> List[str]Parameters
Optional[float]No description available.
floatNo description available.
Sequence[WarmSession]No description available.
Returns
List[str]The result of the operation.
Uses
math.isfiniteevictable.sort
Source
View on GitHubpraisonaiagents/gateway/protocols.py at line 4949