+
    iHàj   ã                  ó°   € R t ^ RIHt ^ RIHt ^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHt ]P                  ! R4      t] ! R R	4      4       tR
 R ltR# )aš  Outer-loop exception handler for the conversation turn loop: phase-aware classification
(interpreter shutdown, deterministic local post-processing bug vs API-path failure),
unanswered tool_call error results, and the per-turn error cap that stops the loop from
spinning until the budget is gone. Nothing here imports ``agent.conversation_loop`` at
module level (cycle); loop-internal constants resolve lazily.
)Úannotations)Ú	dataclassN)ÚAny)Úappend_message)Úshort_detailÚ	site_copyzagent.conversation_loopc                  óN   € ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   R]R&   R	tR
# )ÚOuterErrorVerdictz¼``action`` is ``"break"`` (turn ends with ``final_response``/``turn_exit_reason`` set)
or ``"fallthrough"`` (retry the iteration). The other fields are the loop locals the
handler rebinds.ÚstrÚactionr   Ú_outer_error_countÚ_turn_exit_reasonÚfailedÚfinal_response© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    Ú;/home/ubuntu/.hermes/hermes-agent/agent/turn_loop_errors.pyr	   r	      s%   ‡ ñð ƒKØÓØÓØƒKØ×r   r	   c               ó@   € 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/
# )é   Úagentr   Úer   Úapi_call_countÚmessagesÚconversation_historyr   r   r   Úreturnr	   r   )Úformats   "r   Ú__annotate__r#   #   sj   € ÷ H#ñ H#ØðH#ØðH#Ø/2ðH#ØDGðH#ØSVðH#àðH#à25ðH#à?BðH#àTWðH#ð ñH#r   c               óì  aaaa€ ^ RI Hp	Hp
HpHpHp R VVVV3R llpS^,          o\        P                  ! 4       '       g   V! V4      '       d{   RV RV 2p V P                  RV 2RR7       \        P                  V4        V P                  WE4       R	oRo\        V R
R4      p\!        R	V'       d   RV R2MRR7      oV! R4      # \#        4       pVP$                  pVe   VP'                  \(        P*                  P-                  \(        P*                  P/                  VP0                  P2                  P4                  4      4      ^ ,          4       VP6                  pK‚  \9        VV
,          4      ;'       d    VV	,          '       * pV'       d   RV RV: 2pM	RV RV: 2p\        V RR4      '       d   \        P;                  V4       M V P                  RV 2RR7       \        P=                  RV4       \?        \A        V4      ^,
          R)R)4       EF:  pVV,          p\C        V\D        4      '       g    EMVPG                  R4      R8X  d   K>  VPG                  R4      R8X  dè   VPG                  R4      '       dÑ   VV^,           R  Uu0 uF<  p\C        V\D        4      '       g   K  VPG                  R4      R8X  g   K3  VR,          kK>  	  ppVR,           Fq  pV'       g   K  \C        V\D        4      '       g   K%  VR,          V9  g   K5  \I        VRRRV! 4       PJ                  PM                  V4      RVR,          RRV 2/4       Ks  	   M	  \O        V\Q        ^V PR                  4      4      pV'       g   W0PR                  ^,
          8¼  g   SV8¼  du   \U        V4      pV'       d   R VR!,           R"2o\!        R#VR$7      oM>SV8¼  d   RoR%VR!,           R"2o\!        R&VR$7      oMR'VR!,           R"2o\!        R&VR$7      oV! R4      # V! R(4      #   \        \        3 d     EL¾i ; i  \         d     EL©i ; i  \        \        3 d    \        P;                  T4        EL‡i ; iu upi )*u�  Handle an exception that escaped the response-processing block. Shutdown and
local-processing errors are deterministic and end the turn; API-path errors retry until
``min(_MAX_OUTER_LOOP_ERRORS, max_iterations)`` escaped exceptions. The assistant
message is never appended here: a prefill/interim assistant may already be the tail
(assistantâ†’assistant); ``finalize_turn`` appends only when safe.)Ú_API_CALL_MODULESÚ_LOCAL_PROCESSING_MODULESÚ_MAX_OUTER_LOOP_ERRORSÚ_is_interpreter_shutdown_errorÚ_rac               ó    € V ^8„  d   QhRRRR/# )r   r   r
   r!   r	   r   )r"   s   "r   r#   Ú-handle_outer_loop_error.<locals>.__annotate__1   s   € ÷ 
ñ 
˜ð 
Ð!2ñ 
r   c                ó$   <€ \        V SSSSR 7      # )©r   r   r   r   r   )r	   r-   s   &€€€€r   Ú_verdictÚ)handle_outer_loop_error.<locals>._verdict1   s   ø€ Ü ØÐ.@Ø/¸È~ô
ð 	
r   u<   Interpreter is shutting down â€” cannot continue (API call #z): u   â�Œ T)Ú
diagnosticÚinterpreter_shutdownÚ
session_idNz (CLI: `hermes --resume z`)Ú )ÚresumeÚbreakz6Error during local message processing after API call #z: zError during API call #Úsuppress_status_outputFz Outer loop error in API call #%dÚroleÚtoolÚ	assistantÚ
tool_callsÚtool_call_idÚidÚnameÚcontentzError executing tool: zlocal_processing_error(:NéP   NÚ)Úlocal_processing_error)Údetailzrepeated_outer_errors(Ú
loop_errorzerror_near_max_iterations(Úfallthroughéÿÿÿÿ)+Úagent.conversation_loopr%   r&   r'   r(   r)   ÚsysÚis_finalizingÚ_safe_printÚOSErrorÚ
ValueErrorÚloggerÚwarningÚ_persist_sessionÚ	ExceptionÚgetattrr   ÚsetÚ__traceback__ÚaddÚosÚpathÚsplitextÚbasenameÚtb_frameÚf_codeÚco_filenameÚtb_nextÚboolÚerrorÚ	exceptionÚrangeÚlenÚ
isinstanceÚdictÚgetr   ÚAIAgentÚ_get_tool_call_name_staticÚminÚmaxÚmax_iterationsr   )r   r   r   r   r   r    r   r   r   r%   r&   r'   r(   r)   r.   Ú	error_msgÚ_sidÚtb_module_namesÚ_tbÚ_is_local_processing_errorÚidxÚmsgÚmÚanswered_idsÚtcÚ_outer_error_caprB   s   &$d$$$ddd                  r   Úhandle_outer_loop_errorrt   #   s;  û€ ÷õ ÷

ó 
ð ˜!ÕÐô ×Ò×ÒÑ<¸Q×?Ò?ØRÐSaÐRbÐbeÐfgÐehÐiˆ	ð	Ø×Ñ  Y KÐ0¸TÐÔBô 	�‰�yÔ!ð	Ø×"Ñ" 8ÔBð 3ÐØˆÜ�u˜l¨DÓ1ˆÜ"Ø"×RVÐ-EÀdÀVÈ2Ñ+NÐ\^ô
ˆñ ˜Ó Ð ô !$£€OØ
�/‰/€CØ
Š/Ø×ÑœBŸG™G×,Ñ,¬R¯W©W×-=Ñ-=¸c¿l¹l×>QÑ>Q×>]Ñ>]Ó-^Ó_Ð`aÕbÔcØ�k‰kŠÜ!% oÐ8QÕ&QÓ!R÷ "ð "ØÐ+Õ+ôXÐ÷ "ØLÈ^ÐL\Ð\^Ð_`Ñ^cÐd‰	à-¨nÐ-=¸RÀ¹uÐEˆ	ô ˆuÐ.°×6Ò6Ü�‰�YÕð	$Ø×Ñ  Y KÐ0¸TÐÔBô
 ×ÑÐ7¸ÔHô ”S˜“] QÕ&¨¨B×/ˆØ�s�mˆÜ˜#œt×$Ò$ÚØ�7‰7�6‹?˜fÔ$ÙØ�7‰7�6‹?˜kÔ)¨c¯g©g°l×.CÒ.Cð " #¨¥' (Ñ+óá+�AÜ˜a¤×&ô "à+,¯5©5°«=¸FÑ+Bô "��.×!Ð!Ù+ð ð ð
 ˜,×'Ð'�ß‘2œ* R¬×.Ô.°2°dµ8À<Ö3OÜ" 8Ø Ø¡£§¡× HÑ HÈÓ LØ&¨¨4­Ø!Ð%;¸I¸;Ð#Gð	.ö ñ (ñ 	ñ) 0ô6 Ð1´3°q¸%×:NÑ:NÓ3OÓPÐç"Ø×1Ñ1°AÕ5Ô5ØÐ!1Ô1ô ˜a“ˆß%Ø"9¸)ÀC½.Ð9IÈÐ KÐÜ&Ð'?ÈÔO‰NØÐ#3Ô3ØˆFØ"8¸À3½Ð8HÈÐ JÐÜ& |¸FÔC‰Nà"<¸YÀs½^Ð<LÈAÐ NÐÜ& |¸FÔCˆNÙ˜Ó Ð Ù�MÓ"Ð"øôA œÐ$ô 	Úð	ûô ô 	Úð	ûô@ œÐ$ô 	$Ü�L‰L˜×#ð	$üòsH   ÁP ÂP2 ÇQ ÊQ1Ê/Q1ËQ1ÐP/Ð.P/Ð2QÑ QÑ&Q.Ñ-Q.)r   Ú
__future__r   Údataclassesr   ÚloggingrT   rG   Útypingr   Úagent.message_metadatar   Úagent.turn_failure_copyr   r   Ú	getLoggerrL   r	   rt   r   r   r   Ú<module>r|      sT   ðñõ #å !Û Û 	Û 
Ý å 1ß ;à	×	Ò	Ð4Ó	5€ð ÷	ð 	ó ð	÷H#r   