+
    iHàj  ã                  óL   € R t ^ RIHt ^ RIt^ RItR R lt ! R R4      tR.tR# )uO  Per-agent iteration budget â€” thread-safe consume/refund counter.

Each ``AIAgent`` (parent or subagent) holds its own :class:`IterationBudget`: the parent's
cap is ``max_iterations`` (default 500), each subagent's ``delegation.max_iterations``
(default 50), so total iterations across parent + subagents can exceed the parent's cap.
)ÚannotationsNc               ó   € V ^8„  d   QhRR/# )é   Úreturnzfloat | None© )Úformats   "Ú;/home/ubuntu/.hermes/hermes-agent/agent/iteration_budget.pyÚ__annotate__r	      s   € ÷ Eñ E¨\ñ Eó    c                óâ   € V e   \        V \        4      '       d   R#  \        V 4      p\
        P                  ! T4      '       d   ^ Tu;8  d	   ^8  d   T#  R#   \        \        3 d     R# i ; i)zDA finite ratio strictly between zero and one, or None (feature off).N)Ú
isinstanceÚboolÚfloatÚ	TypeErrorÚ
ValueErrorÚmathÚisfinite)ÚvalueÚratios   & r   Únormalize_budget_warning_ratior      sd   € à‚}œ
 5¬$×/Ò/ÙðÜ�e“ˆô —M’M %×(Ò(¨Q°®]¸¬]ˆ5ÐD¨]ÀÐDøô ”zÐ"ô Úðús   žA ÁA.Á-A.c                  ój   € ] tR t^tRtR R ltR R ltR R lt]R R	 l4       t	]R
 R l4       t
RtR# )ÚIterationBudgetz™Thread-safe iteration counter; ``execute_code`` (programmatic tool calling)
iterations are refunded via :meth:`refund` so they don't eat into the budget.c               ó   € V ^8„  d   QhRR/# )r   Ú	max_totalÚintr   )r   s   "r   r	   ÚIterationBudget.__annotate__   s   € ÷ &ñ & #ñ &r
   c                	óT   € Wn         ^ V n        \        P                  ! 4       V n        R# ©é    N)r   Ú_usedÚ	threadingÚLockÚ_lock)Úselfr   s   &&r   Ú__init__ÚIterationBudget.__init__   s   € Ø"ŒØˆŒ
Ü—^’^Ó%ˆŽ
r
   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r	   r   "   s   € ÷ ñ ˜ñ r
   c                óè   € V P                   ;_uu_ 4        V P                  V P                  8¼  d    RRR4       R# V ;P                  ^,          un         RRR4       R#   + '       g   i     R# ; i)z7Try to consume one iteration.  Returns True if allowed.NFT©r"   r   r   ©r#   s   &r   ÚconsumeÚIterationBudget.consume"   sC   € à�Z�Z‹ZØ�z‰z˜TŸ^™^Ô+Ø÷ ‰Zð �JŠJ˜!�O�JØ÷	 �Z�ZŠZús   •A ¼A Á A1	c               ó   € V ^8„  d   QhRR/# )r   r   ÚNoner   )r   s   "r   r	   r   *   s   € ÷  ñ  ˜ñ  r
   c                ó¼   € V P                   ;_uu_ 4        V P                  ^ 8”  d   V ;P                  ^,          un        RRR4       R#   + '       g   i     R# ; i)z6Give back one iteration (e.g. for execute_code turns).N©r"   r   r)   s   &r   ÚrefundÚIterationBudget.refund*   s/   € à�Z�Z‹ZØ�z‰z˜AŒ~Ø—
’
˜a••
÷ �Z�ZŠZús   •+A
Á
A	c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r   r	   r   1   s   € ÷ ñ �cñ r
   c                	ó€   € V P                   ;_uu_ 4        V P                  uuR R R 4       #   + '       g   i     R # ; i)Nr/   r)   s   &r   ÚusedÚIterationBudget.used0   s   € à�Z�Z‹ZØ—:‘:÷ �Z�Z‹Zús   •,¬=	c               ó   € V ^8„  d   QhRR/# r3   r   )r   s   "r   r	   r   6   s   € ÷ 7ñ 7˜3ñ 7r
   c                	ó¶   € V P                   ;_uu_ 4        \        ^ V P                  V P                  ,
          4      uuRRR4       #   + '       g   i     R# ; ir   )r"   Úmaxr   r   r)   s   &r   Ú	remainingÚIterationBudget.remaining5   s.   € à�Z�Z‹ZÜ�q˜$Ÿ.™.¨4¯:©:Õ5Ó6÷ �Z�Z‹Zús   •'AÁA	r(   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   r*   r0   Úpropertyr5   r:   Ú__static_attributes__r   r
   r   r   r      s?   † ñUõ&õ
õ ð ôó ðð ô7ó ô7r
   r   )r@   Ú
__future__r   r   r    r   r   Ú__all__r   r
   r   Ú<module>rE      s0   ðñõ #ã Û õE÷7ñ 7ðD Ð
‚r
   