+
    -pÐjW  ã                  ó^   € R t ^ RIHt ^ RIHtHt ^tRt^t^t	RRR^ R]R]R	]R
]	/R R llt
R# )a«  Send-path image eviction policy shared by both stateless outbound passes.

Two passes retire old tool-result images from the per-request copy of the conversation:
``agent.context_compressor.evict_stale_outbound_tool_images`` on the OpenAI-shaped list and
``agent.anthropic_message_convert._evict_old_screenshots`` on the Anthropic wire list. Both run
from scratch on a fresh clone every request, so they must agree on one policy or the second
pass re-evicts on a different frontier than the first (#113517). This module is stdlib-only so
the wire converter, a leaf, can import it without dragging in the compaction stack.

Why the trigger is a provider limit, not a keep-newest count: retiring an image edits a message
the provider has already cached, and Anthropic matches its prompt cache on an exact byte prefix.
A keep-newest-N window retires one more message on every new image, so every turn is a
full-prefix miss. Holding images until the request would cross a real API limit and then
retiring a batch costs one slower turn per batch and nothing below the limit.

20 is the documented threshold at which Anthropic applies a stricter per-image dimension cap
(2000 px) to EVERY image in the request, counting images nested in tool_result content. The hard
ceilings are higher (100 images per request on 200K-context models, 600 otherwise) but the 32 MB
request-size limit usually binds first, which the byte budget guards with headroom for text.
)Úannotations)ÚOptionalÚSequencei 6nÚcarrier_bytes_newest_firstNÚreserved_bytesÚlimitÚbudgetÚbatchÚfloorc               ó<   € V ^8„  d   QhRRRRRRRRRRR	RR
RRRRR/	# )é   Úcarrier_blocks_newest_firstzSequence[int]Úreserved_blocksÚintr   zOptional[Sequence[int]]r   r   r   r	   r
   Úreturn© )Úformats   "Ú*/opt/hermes/agent/image_eviction_policy.pyÚ__annotate__r   !   sb   € ÷ ?ñ ?Ø!.ð?àð?ð !8ð	?ð
 ð?ð ð?ð ð?ð ð?ð ð?ð 	ñ?ó    c               ó
  aaaaaaaaa€ \        V 4      pVo^ .V^,           ,          o^ .V^,           ,          o\        V4       FJ  p	SV	,          W	,          ,           SV	^,           &   SV	,          Se
   SV	,          M^ ,           SV	^,           &   KL  	  R VVVV3R lloR VVVV3R lloS! V4      '       d   ^ # \        \        V^ 4      V4      pS! ^ 4      '       g   S! V4      '       d	   W‡,
          MTp
V
^ 8:  d   ^ # S! ^ 4      '       d&   \        V3R l\        V^,           4       4       4      M^ p\        ^\        WkV,
          4      4      p^ pWÚ8  d,   \        WÜ,           V
4      pS! W�,
          4      '       g   K.   V# V# )u«  How many of the OLDEST image-bearing tool results to retire.

``carrier_blocks_newest_first`` is the image-block count per image-bearing tool result,
newest first; ``reserved_blocks`` counts images the pass must never rewrite (user
uploads). The byte dimension is active only when ``carrier_bytes_newest_first`` is
given (the wire pass has no sizes).

The retire count must be a STEP FUNCTION of the overshoot, because the pass is recomputed
on every request: an exact ``count - limit`` target moves the frontier on every new image,
and a fixed one-batch retire stops enforcing the limit after the first batch. So the count
advances in quanta until the request fits.

The quantum is ``batch`` capped at ``window - floor``, where ``window`` is how many newest
carriers fit under the ceiling. A quantum wider than that would step past the newest frames
on every advance; cutting each step back to exactly ``total - floor`` instead makes the
retire count track ``total`` again â€” the per-image frontier this policy exists to avoid,
visible whenever a tool result carries several images or uploads fill most of the ceiling.
Holding for ``window - floor`` turns per advance is the most the floor allows.

The floor is a SATISFIABILITY floor: it shelters the newest frames only when reserved
uploads alone breach the block ceiling (no retirement can fix that), and never under byte
pressure â€” the request-size limit is hard and the provider answers 413.
c               ó    € V ^8„  d   QhRRRR/# ©r   Úkeptr   r   Úboolr   )r   s   "r   r   Ú1outbound_image_retire_count.<locals>.__annotate__K   s   € ÷ Lñ L˜ð L ñ Lr   c                óB   <€ SR J ;'       g    SSV ,          ,           S8*  # ©Nr   )r   r   Ú
bytes_keptr   Úsizess   &€€€€r   Ú
_bytes_fitÚ/outbound_image_retire_count.<locals>._bytes_fitK   s$   ø€ Ø˜ˆ}×KÐK °¸DÕ1AÕ AÀVÑ KÐKr   c               ó    € V ^8„  d   QhRRRR/# r   r   )r   s   "r   r   r   N   s   € ÷ Qñ Q�Cð Q˜Dñ Qr   c                óJ   <€ SSV ,          ,           S8*  ;'       d	    S! V 4      # r   r   )r   r    Úblocks_keptr   r   s   &€€€€r   Ú_fitsÚ*outbound_image_retire_count.<locals>._fitsN   s%   ø€ Ø ¨TÕ!2Õ2°eÑ;×PÐPÁ
È4Ó@PÐPr   c              3  óH   <"  € T F  pS! V4      '       g   K  Vx € K  	  R # 5ir   r   )Ú.0Úkr%   s   & €r   Ú	<genexpr>Ú.outbound_image_retire_count.<locals>.<genexpr>X   s   øé € Ð9Ñ,�q±°a·—’Ó,ùs   ƒ"˜
")ÚlenÚrangeÚminÚmax)r   r   r   r   r   r   r	   r
   ÚtotalÚiÚ
max_retireÚwindowÚquantumÚretirer    r%   r$   r   r   s   &f$ddd$$      @@@@@r   Úoutbound_image_retire_countr6   !   sK  ÿø€ ôD Ð+Ó,€EØ&€EØ�#˜ �Õ#€KØ�˜ �	Õ"€JÜ�5Ž\ˆØ(¨�^Ð.IÕ.LÕLˆ�A˜•EÑØ& q�M¸Ò9J¨U°1®XÐPQÕRˆ
�1�q•5Óñ ÷Ló L÷Qó Qñ ˆU‡|‚|Ùä”�E˜1“˜uÓ%€EÙ&+¨A§h¢h±:¸e×3DÒ3D�–È%€JØ�Q„ÙÙ=BÀ1¿XºXŒSÔ9œE %¨!¥)Ô,Ó9Ô9È1€FÜ�!”S˜¨¥Ó/Ó0€Gà€FØ
Ô
Ü�VÕ% zÓ2ˆÙ�•× Ô ØØ€Mˆ6€Mr   )Ú__doc__Ú
__future__r   Útypingr   r   ÚOUTBOUND_IMAGE_LIMITÚOUTBOUND_IMAGE_BUDGET_BYTESÚIMAGE_EVICTION_BATCHÚOUTBOUND_IMAGE_FLOORr6   r   r   r   Ú<module>r>      sp   ðñõ* #ç %àÐ Ø(Ð ØÐ àÐ ð?ð ;?ð	?ð
 ð?ð &ð?ð .ð?ð &ð?ð &÷?ñ ?r   