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_flight is True` — an executing turn must not be aborted, or
  • `flushed is False` — 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/&lt;= 0`), or nothing evictable remains — so a host that can’t report a cgroup limit simply never soft-evicts (legacy behaviour).

Signature

python
def plan_pressure_evictions(budget_mb: Optional[float], rss_mb: float, warm_sessions: Sequence[WarmSession]) -> List[str]

Parameters

ParamField Optional[float]

No description available.

ParamField float

No description available.

ParamField Sequence[WarmSession]

No description available.

Returns

ResponseField List[str]

The result of the operation.

Uses

  • math.isfinite
  • evictable.sort

Source

View on GitHub

praisonaiagents/gateway/protocols.py at line 4949