+
    iHàjš9  ã                  ó"  € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ]P*                  ! R	4      t]P.                  ! R
]P0                  4      t] ! R R4      4       tRR/R R lltR R ltR R ltR# )u  Empty / thinking-only final-response recovery ladder for the conversation turn loop.

Runs when the model returned no visible text after ``<think>`` blocks. Ladder order is
load-bearing: partial-stream recovery â†’ reuse prior turn content (housekeeping tools only)
â†’ one post-tool-call nudge â†’ thinking-only prefill continuation (Ã—2) â†’ empty-response
retries (budgeted, deterministic-empty short-circuit) â†’ fallback provider â†’ terminal
``(empty)`` sentinel. Nothing here imports ``agent.conversation_loop`` at module level.
)ÚannotationsN)Ú	dataclass)ÚAnyÚDictÚListÚOptional)Úempty_response_guard)Úappend_message)Ú_refund_api_call)Úinterruptible_backoff_sleepzagent.conversation_loopz<think>|<thinking>|<reasoning>c                  ób   € ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   R]R	&   R
]R&   R]R&   RtR# )ÚEmptyResponseVerdictu�  Outcome of ``recover_empty_response``.

``action``: ``"break"`` (turn is done â€” ``final_response`` is set), ``"continue"``
(re-enter the OUTER turn loop: a nudge/prefill row was appended, a retry wait
elapsed, or a fallback was activated and preflight must re-run), ``"return"``
(interrupted during a retry wait â€” return ``result``) or ``"fallthrough"``
(unreachable: every path exits; kept for the contract).ÚstrÚactionúOptional[dict[str, Any]]Úresultr   Úfinal_responseÚturn_exit_reasonÚactive_system_promptÚboolÚpreflight_compression_blockedÚintÚapi_call_count© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    Ú>/home/ubuntu/.hermes/hermes-agent/agent/turn_empty_response.pyr   r      s2   ‡ ñ?ð ƒKØ$Ó$ØÓØÓØÓØ#'Ó'Ø×r!   r   Úobserved_generationFc               ó<   € V ^8„  d   QhRRRRRRRRRRR	RR
RRRRR/	# )é   Úagentr   ÚresponseÚfinish_reasonr   Úempty_candidater   ÚmessagesÚconversation_historyr   r   r#   ÚreturnÚtupler   )Úformats   "r"   Ú__annotate__r/   .   sV   € ÷ 0+ñ 0+Øð0+Øð0+Ø.1ð0+ØDHð0+ØWZð0+àð0+à/2ð0+àIMð0+ð ñ0+r!   c               ó¢  € ^ RI Hp V'       d   \        P                  ! WWR7       V'       d   \        P                  ! W4      M\        P
                  p	T;'       d    \        P                  ! V 4      p
V'       d   V P                  V	8  d	   V
'       d   RRV
3# V ;P                  ^,          un        V P                  pV! VRRR7      p\        P                  RW¹WÀP                  4       V	\        P
                  8  d   RMR	pV P                  R
V RV	 RVR RV 24       \        WRVVVRRV RV	 R2RV RV	 R2R7	      pVe   RWê3# RRV
3# )a  Budgeted empty-response retry. Each empty attempt re-bills the full input, so the
signature is recorded and deterministic empties stop burning paid retries (fails
open: missing usage or any output keeps the budget). Returns
``(action_or_None, interrupt_result, deterministic_empty)``.)Újittered_backoff)r(   r'   r#   Ng      @g      N@)Ú
base_delayÚ	max_delayuL   Empty response (no content or reasoning) â€” retry %d/%d in %.1fs (model=%s)u,    â€” high-cost request, reduced retry budgetÚ u/   âš ï¸� Empty response from model â€” retrying (Ú/z) in z.0fÚsz>Interrupt detected during empty-response retry wait, aborting.zAOperation interrupted: retrying empty response from model (retry z).zempty response retry backoff (Ú))r*   r+   r   Úabort_messageÚinterrupt_textÚactivity_labelr,   Úcontinue)Úagent.retry_utilsr1   Ú_empty_guardÚrecord_empty_attemptÚempty_retry_budgetÚDEFAULT_EMPTY_RETRY_BUDGETÚdeterministic_emptyÚ_empty_content_retriesÚloggerÚwarningÚmodelÚ_buffer_diagnostic_statusr   )r&   r'   r(   r)   r*   r+   r   r#   r1   ÚbudgetÚdeterministicÚnÚ	wait_timeÚ_budget_noteÚ_interrupteds   &&&&$$$$       r"   Ú_retry_emptyrM   .   sp  € õ 3çÜ×)Ò)Ø¸õ	
÷
 ô 	×'Ò'¨Ô8Ü ,× GÑ Gð ð $×OÐO¬×(HÒ(HÈÓ(O€Mß × <Ñ <¸vÔ EÏmØ�T˜=Ð(Ð(Ø	× Ò  AÕ%Õ Ø×$Ñ$€AÙ  ¨s¸dÔC€IÜ
‡N�NØVØ	�9Ÿk™kôð ”L×;Ñ;Ô;ñ 	7ØACð ð 
×#Ñ#Ø
9¸!¸¸A¸f¸XÀUÈ9ÐUXÈ/ÐYZÐ[gÐZhÐiôô /Ø˜$ØØ1Ø%ØVàOÐPQÈsÐRSÐTZÐS[Ð[]Ð^à7¸°s¸!¸F¸8À1ÐEô
€Lð ÒØ˜Ð4Ð4Ø�t˜]Ð*Ð*r!   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r%   r&   r   Úassistant_messager(   r   r*   r,   r   )r.   s   "r"   r/   r/   a   s1   € ÷ (ñ (˜3ð (°3ð (Àsð (ÐVYð (Ð^añ (r!   c                ó|  € \         P                  ! V 4      pVe   V P                  RVR R24       V P                  4        V P	                  V4      pV P                  V4       V P                  W4      pRVR&   RVR&   \        W64       V'       ge   \        P                  RV P                  V P                  V P                  4       T P                  R	V P                  '       d   R
MR,           4       R# \        P                  RV P                  V P                  V P                  4       V P                  R4       R# )u   Retries and fallback exhausted: persist the ``(empty)`` sentinel row and return the
delivery text. Reasoning is never copied into the delivery text here â€” the persisted row
keeps the sentinel so later "continue" turns don't replay it and loop on empties.u1   â„¹ï¸� Estimated cost of these empty attempts: ~$z.2fzF (input tokens are billed per attempt even when no answer is produced)ú(empty)ÚcontentTÚ_empty_terminal_sentinelzfEmpty response (no content or reasoning) after %d retries. No fallback available. model=%s provider=%su/   â�Œ Model returned no content after all retriesz and fallback attempts.z#. No fallback providers configured.zfReasoning-only response after %d retries; keeping it out of the terminal result (model=%s provider=%s)u[   âš ï¸� Model produced reasoning but no visible response after all retries. Returning empty.)r=   Ústreak_cost_usdrF   Ú_flush_status_bufferÚ_extract_reasoningÚ)_drop_trailing_empty_response_scaffoldingÚ_build_assistant_messager	   rC   rD   rB   rE   ÚproviderÚ_emit_diagnostic_statusÚ_fallback_chain)r&   rO   r(   r*   Ú_streak_costÚreasoning_textÚassistant_msgs   &&&&   r"   Ú_terminal_emptyr_   a   s/  € ô  ×/Ò/°Ó6€LØÒØ×'Ñ'Ø?ÀÈSÐ?Qð R;ð <ô	
ð 
×ÑÔ Ø×-Ñ-Ð.?Ó@€NØ	×3Ñ3°HÔ=Ø×2Ñ2Ð3DÓT€MØ(€M�)ÑØ04€MÐ,Ñ-Ü�8Ô+çÜ�‰ð#à×(Ñ(¨%¯+©+Ø�N‰Nô		
ð 	×%Ñ%Ø=Ø,1×,A×,AÐ,AÑ(Ø4õ6ô	
ñ
 ä
‡N�Nð	!à×$Ñ$ e§k¡k°5·>±>ôð
 
×!Ñ!Øeôñ r!   c               óL   € V ^8„  d   QhRRRRRRRRRRRR	R
RRRRRRRRRRRRR/# )r%   r&   r   rO   r'   r(   r   r   r*   zlist[dict[str, Any]]Úapi_messagesr+   r   r   r   r   r   r   r,   r   r   )r.   s   "r"   r/   r/   Œ   s�   € ÷ [ñ [Øð[Ø#&ð[Ø25ð[ØFIð[Ø^að[à"ð[à25ð[àMPð[ð ð[ð 03ð[ð GJð[ð $(ð	[ð
 ñ[r!   c               óü	  aaa	aa€ ^ RI HpHp V
oVoR.R VVVV	V3R lllp\        V RR4      ;'       g    RpV P	                  V4      '       dc   RoV P                  V4      P                  4       p\        P                  R\        V4      4       V P                  R	4       VoR
V n        V! R4      # \        V RR4      pV'       d†   \        V RR
4      '       ds   Ro\        P                  R4       V P                  R4       RV n        R
V n        ^ V n        V P                  V4      P                  4       oRV n        SV n        V! R4      # \         ;QJ d    R VR/R  4       F  '       g   K   RM	  R
M! R VR/R  4       4      p\#        \$        P'                  S;'       g    R4      4      pV'       d˜   \        V RR
4      '       g…   V'       g}   RV n        RV n        R
V n        \        P                  R4       V P+                  R4       V P-                  W4      pRVR&   RVR&   \/        VV4       \/        VRRRVRR/4       V! R4      # \#        \        VRR4      ;'       g-    \        VRR4      ;'       g    \        VRR4      ;'       g    T4      pV'       d›   V P0                  ^8  dŠ   V ;P0                  ^,          un        \        P                  RV P0                  4       V P+                  R V P0                   R!24       V P-                  VR"4      pRVR#&   \/        VV4       WPn        V! R4      # V P                  S4      P                  4       '       * pT;'       d    V'       * ;'       g    V P0                  ^8¬  p\5        WVVVVS	VR$7      w  pppVe
   V! VV4      # V'       dF   V'       d>   \        P7                  R%V P8                  V P:                  V4       V P+                  R&4       V'       dí   V P<                  '       dÛ   \        P7                  R'V P                  V P8                  V P:                  4       V P+                  R(4       V P?                  4       '       d~   V! WS4      o^ V n        V P+                  R)V P8                   R*V P:                   R+24       \        P                  R,V P8                  V P:                  4       R
o\A        V S	4      o	V! R4      # R-o\C        WW54      oV! R4      # )0uå   Recover from a final response with no visible content (see module docstring for
the ladder). Role alternation is preserved: the post-tool nudge appends the empty
assistant row BEFORE the user-level hint (APIs reject toolâ†’user).)Ú_EMPTY_TOOL_RESPONSE_NUDGEÚ_sync_failover_system_messageNc               ó$   € V ^8„  d   QhRRRRRR/# )r%   r   r   r   r   r,   r   r   )r.   s   "r"   r/   Ú,recover_empty_response.<locals>.__annotate__š   s#   € ÷ 
ñ 
˜ð 
Ð&>ð 
ÐJ^ñ 
r!   c           
     ó&   <€ \        WSSSSSR 7      # ))r   r   r   r   r   r   r   )r   )r   r   Ú_preflight_compression_blockedÚ_turn_exit_reasonr   r   r   s   &&€€€€€r"   Ú_verdictÚ(recover_empty_response.<locals>._verdictš   s!   ø€ Ü#Ø¸Ø.ÐEYØ*HØ)ô	
ð 	
r!   Ú _current_streamed_assistant_textr4   Úpartial_stream_recoveryuG   Partial stream content delivered (%d chars) â€” using as final responseuD   â†» Stream interrupted â€” using delivered content as final responseFÚbreakÚ_last_content_with_toolsÚ$_last_content_tools_all_housekeepingÚfallback_prior_turn_contentuO   Empty follow-up after tool calls â€” using prior turn content as final responseuM   â†» Empty response after tool calls â€” using earlier content as final answerTc              3  óH   "  € T F  qP                  R 4      R8H  x € K  	  R# 5i)ÚroleÚtoolN)Úget)Ú.0Úms   & r"   Ú	<genexpr>Ú)recover_empty_response.<locals>.<genexpr>Ç   s   é € ÐI¹=°aŸ%™% ›-¨6Ö1»=ùs   ‚ "Ú_post_tool_empty_retrieduH   Empty response after tool calls â€” nudging model to continue processinguD   âš ï¸� Model returned empty after tool calls â€” nudging to continuerQ   rR   Ú_empty_recovery_syntheticrs   Úuserr;   Ú	reasoningÚreasoning_contentÚreasoning_detailsuM   Thinking-only response (no visible content) â€” prefilling to continue (%d/2)u7   â†» Thinking-only response â€” prefilling to continue (z/2)Ú
incompleteÚ_thinking_prefill)r*   r+   r   r#   ug   Repeated empty response detected (model=%s provider=%s finish_reason=%s) â€” skipping remaining retriesug   âš ï¸� Model is repeatedly returning empty content â€” skipping further retries to avoid repeat chargesuO   Empty response after %d retries â€” attempting fallback (model=%s, provider=%s)uL   âš ï¸� Model returning empty responses â€” switching to fallback provider...u   â†» Switched to fallback: z (r7   z<Fallback activated after empty responses: now using %s on %sÚempty_response_exhausted)Néûÿÿÿ)"Úagent.conversation_looprc   rd   ÚgetattrÚ_has_content_after_think_blockÚ_strip_think_blocksÚstriprC   ÚinfoÚlenrZ   Ú_response_was_previewedro   rp   rB   Ú_reused_response_textÚanyr   Ú_INLINE_THINK_REÚsearchrz   rF   rX   r	   Ú_thinking_prefill_retriesÚ_session_messagesrM   rD   rE   rY   r[   Ú_try_activate_fallbackr
   r_   )r&   rO   r'   r(   r   r*   ra   r+   r   r   r   r   rc   rd   rj   Ú_partial_streamedÚ
_recoveredÚfallbackÚ_prior_was_toolÚ_has_inline_thinkingÚ
_nudge_msgÚ_has_structuredÚinterim_msgÚ_truly_emptyÚ_empty_candidater   Úinterrupt_resultÚ_deterministic_emptyrh   ri   s   &&&&d$$$dd$$                @@r"   Úrecover_empty_responserŸ   Œ   sÐ  ü€ ÷ bà(ÐØ%BÐ"÷
ö 
ô   Ð'IÈ2ÓN×TÐTÐRTÐØ×+Ñ+Ð,=×>Ò>Ø5ÐØ×.Ñ.Ð/@ÓA×GÑGÓIˆ
Ü�‰ØUÜ�
‹Oô	
ð 	×%Ñ%Ð&oÔpØ#ˆð ).ˆÔ%Ù˜Ó Ð ô
 �uÐ8¸$Ó?€Hß”G˜EÐ#IÈ5×QÒQØ9ÐÜ�‰ÐeÔfØ×%Ñ%Ð&uÔvØ)-ˆÔ&Ø5:ˆÔ2Ø'(ˆÔ$à×2Ñ2°8Ó<×BÑBÓDˆØ(,ˆÔ%ð '5ˆÔ#Ù˜Ó Ð ÷ “cÑI¸8ÀBÀC¹=ÓI—c—c’cÑI¸8ÀBÀC¹=ÓIÓI€Oô  Ô 0× 7Ñ 7¸×8LÐ8LÈ"Ó MÓNÐçÜ˜Ð9¸5×AÒAß$à)-ˆÔ&à)-ˆÔ&Ø5:ˆÔ2Ü�‰ÐaÔbØ×'Ñ'Ð(qÔrà×3Ñ3Ð4EÓUˆ
Ø )ˆ
�9ÑØ26ˆ
Ð.Ñ/Ü�x Ô,Ü�xØ�F˜IÐ'AÐC^Ð`dð"
ô 	ñ ˜
Ó#Ð#ô ÜÐ! ;°Ó5÷ 	 ð 	 ÜÐ$Ð&9¸4Ó@÷	 ð 	 äÐ$Ð&9¸4Ó@÷	 ð 	 ð  ó	€O÷ ˜5×:Ñ:¸QÔ>Ø×'Ò'¨1Õ,Õ'Ü�‰Ø[Ø×+Ñ+ô	
ð 	×'Ñ'ØEÀe×FeÑFeÐEfÐfiÐjô	
ð ×4Ñ4Ð5FÈÓUˆØ+/ˆÐ'Ñ(Ü�x Ô-Ø"*ÔÙ˜
Ó#Ð#ð ×0Ñ0°Ó@×FÑFÓHÔH€LØ#×eÐe¨_Ô)<×)dÐ)dÀ×@_Ñ@_ÐcdÑ@dÐÜ5AØ˜Ð(8À8Ø1À.Ø+ô6Ñ2€FÐÐ2ð
 ÒÙ˜Ð 0Ó1Ð1ç×,Ü�‰ð)à�K‰K˜Ÿ™¨ô	
ð
 	×'Ñ'ð&ô	
÷ ˜×-×-Ð-Ü�‰Ø]Ø×(Ñ(¨%¯+©+°u·~±~ô	
ð 	×'Ñ'Ð(yÔzØ×'Ñ'×)Ò)Ù#@ÀÐVjÓ#kÐ Ø+,ˆEÔ(Ø×+Ñ+Ð.HÈÏÉÈÐU[Ð\a×\jÑ\jÐ[kÐklÐ,mÔnÜ�K‰KØNØ—‘˜UŸ^™^ôð .3Ð*ô .¨e°^ÓDˆNÙ˜JÓ'Ð'à2ÐÜ$ U¸}ÓW€NÙ�GÓÐr!   )r   Ú
__future__r   ÚloggingÚreÚdataclassesr   Útypingr   r   r   r   r&   r   r=   Úagent.message_metadatar	   Úagent.turn_context_compactionr
   Úagent.turn_recoveryr   Ú	getLoggerrC   ÚcompileÚ
IGNORECASErŽ   r   rM   r_   rŸ   r   r!   r"   Ú<module>r«      s„   ðñõ #ã Û 	Ý !ß ,Ó ,å 6Ý 1Ý :Ý ;à	×	Ò	Ð4Ó	5€à—:’:Ð?ÀÇÁÓOÐ ð ÷ð ó ðð$0+àPU÷0+õf(÷V[r!   