+
    iHàj'J  ã                  ó   € R t ^ RIHt ^ RIHt ^ RIt^ RIHtHtH	t	 ^ RI
Ht ^ RIHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHtHt ]! RRR4      t]P6                  ! R4      tRt] ! R R4      4       tR R ltR# )u—  No-tool-call (final text) branch of the conversation turn loop: empty/think-only recovery,
intent-ack / stall-guard continuation, length-continuation joining, dropped-tool-call
re-prompt, scaffolding pop, stop gates, then the durable final flush. Extracted from
``run_conversation``; nothing here imports ``agent.conversation_loop`` at module level
(cycle) â€” loop-internal nudge constants resolve lazily.
)Úannotations)Ú	dataclassN)ÚAnyÚDictÚOptional)Úappend_message)Úanswer_in_reasoning_capability)ÚSTOP_PATH_MIN_CHARSÚis_runaway_repetition)Ústamp_failure)Úrecover_empty_response)Úapply_stop_gates)Úpartial_resultÚrepetition_copyzbefore deliveryz%so the repeated output was discarded.z; refusing to return azagent.conversation_loopc                  ó˜   € ] tR t^$t$ RtR]R&   R]R&   R]R&   R]R&   R]R&   R]R	&   R]R
&   R]R&   R]R&   R]R&   R]R&   RtR]R&   RtR# )ÚFinalResponseVerdictzñ``action``: ``"break"`` (turn ends with ``final_response``), ``"continue"`` (a
continuation/re-prompt/stop-gate asked for another API call) or ``"return"``
(``result`` is the turn's result dict). The other fields are the loop locals rebound.ÚstrÚactionr   Úactive_system_promptÚfinal_responseÚ_turn_exit_reasonÚ_preflight_compression_blockedÚcodex_ack_continuationsÚtruncated_response_partsÚlength_continue_retriesÚ_pending_verification_responseÚ(_pending_verification_response_previewedÚintÚapi_call_countNúOptional[dict[str, Any]]Úresult© )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r    Ú__static_attributes__r!   ó    Ú>/home/ubuntu/.hermes/hermes-agent/agent/turn_final_response.pyr   r   $   sV   ‡ ñ]ð ƒKØÓØÓØÓØ$'Ó'Ø Ó Ø!Ó!Ø Ó Ø$'Ó'Ø.1Ó1ØÓØ'+€FÐ$×+r)   r   c          (     óh   € 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RRRRRRRRRRR/# )é   Úagentr   Úassistant_messageÚresponseÚfinish_reasonÚmessagesÚapi_messagesÚconversation_historyr   Úuser_messager   r   r   r   r   r   r   r   r   Úeffective_task_idÚreturnr   r!   )Úformats   "r*   Ú__annotate__r8   8   sß   € ÷ @ñ @Øð@Ø&)ð@Ø58ð@ØILð@ØX[ð@àð@à-0ð@àBEð@àUXð@ð ð@ð 03ð@ð HKð@ð %(ð	@ð CFð	@ð
 "ð@ð
 =@ð@ð %(ð@ð TWð@ð ð@ð ñ@r)   c               óŽ  aaa	a
aaaaaaa€ ^ RI HpHpHpHp R:R VVVVV	VVV
VV3
R lllpVP
                  pRpVR8X  Ed#   VP                  '       Eg   Ve-   \        V\        4      '       dö   VP                  4       '       gà   \        ;QJ d1    R \        VRR4      ;'       g    R; 4       F  '       g   K   RM&	  R	M"! R \        VRR4      ;'       g    R; 4       4      '       g|   \        V 4      '       dk   V P                  V4      ;'       g    RpV'       dH   \        P                  R
\!        V4      V P"                  V P$                  S\'        R S 4       4      4       T;'       g    VP
                  ;'       g    Ro
R	V n        V P+                  S
4      '       g–   \-        WW#S
SWVS	SSSR7      pVP.                  o
VP0                  oVP2                  o	VP4                  oVP6                  oVP8                  R8X  d   V! RVP:                  4      # VP8                  R8X  d	   V! R4      # V! R4      # ^ V n        ^ V n        V PA                  4        V PC                  4        ^ RI"H#pH$pH%pH&pH'p V! V 4      p T PQ                  S
;'       g    R4      p!\S        \        V RR4      4      ;'       dM    V PT                  ;'       d9    S^8  ;'       d,    V! V!4      ;'       g    \S        V4      ;'       d	    V! V!4      p"V! S4      p#\S        \        V RR4      4      ;'       d2    V R8g  ;'       d%    S^8  ;'       d    V#^ 8„  ;'       d    V! V!VR7      p$V"'       d   Rp%MNV$'       d   Rp%MCV R8w  d;   V PT                  '       d)   S^8  d"   V PW                  VS
SV R8H  R7      '       d   Rp%MRp%V%'       dÌ   V%R8X  d   \        PY                  RS^,           4       M7V%R8X  d1   \        P                  R\!        V!4      V!R,          V#S^,           4       S^,          oV P[                  VR4      p&V'       d   S
V&R&   \]        SV&4       V P_                  V&4       \]        SRR R!V%R8X  d   TMT/4       SV n0        Ro
V! R4      # ^ oS'       dX   V! . SOS
R	3N4      o
. o^ oS F?  p'\        V'\b        4      '       g   K  V'Pe                  R"R4       V'Pe                  R#R4       KA  	  V PQ                  S
4      P                  4       o
S
'       d•   \!        S
4      \f        8¼  d�   \i        S
4      '       dp   \j        w  p(p)p*V Pm                  V Pn                   V( 2RRR$7       V Pq                  V4       V Ps                  SV4       V! R\u        \w        SSV)V*4      R%R4      4      # V P[                  W4      p+V'       d   S
V+R&   VR&8X  dÇ   VP                  '       gµ   \        V R'^ 4      ^8  d£   \        V R'^ 4      ^,           V n<        \        P                  R(V Px                  V P"                  V P$                  4       V P{                  R)V Px                   R*24       RV+R+&   \]        SV+4       \]        SRR R!VR+R/4       SV n0        Ro
V! R4      # ^ V n<        S'       dx   \        SR<,          \b        4      '       d[   \        ;QJ d#    V3R, l\|         4       F  '       g   K   RM	  R	M! V3R, l\|         4       4      '       d   SPe                  4        K  \        V V+S
SVSSR-7      p,V,P€                  oV,P‚                  oV,P„                  '       d   Ro
V! R4      # ^ R.ICHDp- R	p.\        V R/R	4      '       g*   T-! T S
\        V R0R4      ;'       g    R\        R17      w  o
p.p/V.'       d   V'       d   S
V+R&   MS
V+R!&   \]        SV+4        V P‹                  SV4       R6V R72oV PŽ                  '       g   V P‘                  R8S R924       V! R4      #   \Œ         d1    \        P                  R2\        T R3R4      ;'       g    R4RR57        Loi ; i)=a  Finish (or defer) a text-only assistant response in the original guard order. Every
continuation path sets ``final_response = None`` so an acknowledgment never suppresses
iteration-limit summarization; the final message is appended and flushed only after the
stop gates accept it.)Ú_CODEX_ACK_CONTINUATION_NUDGEÚ_DEGENERATE_FINAL_NUDGEÚ_DROPPED_TOOLCALL_NUDGE_CONTENTÚ_join_truncated_partsNc               ó$   € V ^8„  d   QhRRRRRR/# )r,   r   r   r    r   r6   r   r!   )r7   s   "r*   r8   Ú*finish_text_response.<locals>.__annotate__J   s#   € ÷ 
ñ 
˜ð 
Ð&>ð 
ÐJ^ñ 
r)   c                ó2   <
€ \        V SS	SSSSS
SSSVR 7      # ))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   s   &&€€€€€€€€€€r*   Ú_verdictÚ&finish_text_response.<locals>._verdictJ   s4   ø€ Ü#ØÐ0DÐUcØ/Ø+IØ$;Ø%=Ø$;Ø+IØ5]Ø)Øô
ð 	
r)   Ústopc              3  óT  "  € T Fž  p\        V\        4      ;'       d‚    VP                  R 4      R9   ;'       d3    VP                  R4      ;'       gM    VP                  R4      ;'       g4    \        VP                  R 4      ;'       g    R4      P	                  R4      x € K   	  R# 5i)ÚtypeÚ	signatureÚdataÚ z.native_assistantN)ÚthinkingÚredacted_thinking)Ú
isinstanceÚdictÚgetr   Úendswith)Ú.0Úds   & r*   Ú	<genexpr>Ú'finish_text_response.<locals>.<genexpr>j   s�   é € ð 
ñ
 Q�ô	 �qœ$Ó÷ ð Ø—‘�v“Ð"CÑC×mÐmÈÏÉÈ{ÓI[÷ JÐIlÐ_`×_dÑ_dÐekÓ_l÷ Jð JÜ�q—u‘u˜V“}×*Ð*¨Ó+×4Ñ4Ð5HÓIôó Qùs!   ‚B(žB(ºB(ÁB(Á,B(Â
B(Úreasoning_detailsTFuˆ   Reasoning-only clean stop (%d chars) â€” returning the reasoning as the final response (model=%s provider=%s api_calls=%d tool_turns=%d)c              3  ó¸   "  € T FP  p\        V\        4      '       g   K  VP                  R 4      R8X  g   K3  VP                  R4      '       g   KL  ^x € KR  	  R# 5i)ÚroleÚ	assistantÚ
tool_callsN)rK   rL   rM   )rO   Úms   & r*   rQ   rR   {   s>   é € Ðx™x˜!¬:°a¼×+>”AÀ1Ç5Á5ÈÃ=ÐT_ÑC_”AÐde×diÑdiÐjv×dw—A’A›xùs   ‚AŸA·AÁ
ArH   )r   r1   r2   r3   r   r   Úturn_exit_reasonÚpreflight_compression_blockedr6   ÚbreakÚcontinue)Úintent_ack_continuation_modeÚlooks_like_degenerate_finalÚ#promoted_reasoning_announces_actionÚtool_results_this_turnÚtrailing_continue_intentÚ_stall_guardsÚoff)r4   ÚstallÚ
degenerateÚ
codex_only)r4   Úassistant_contentr1   Úrequire_workspaceÚackuf   Stall guard: turn ending on trailing continue-intent with no tool calls â€” re-prompting to act (%d/2)ud   Degenerate final: %d-char fragment %r ended the turn after %d tool result(s) â€” re-prompting (%d/2):Né(   NÚ
incompleteÚapi_contentrU   ÚuserÚcontentÚ_length_continuation_fragmentÚ_length_continuation_nudge)ÚforceÚ
diagnosticÚ	truncatedrW   Ú_dropped_toolcall_retriesuŠ   finish_reason=tool_calls with empty tool_calls array (narration only) â€” re-prompting to emit the call (retry %d/3, model=%s provider=%s)u?   â†» Model signaled a tool call but sent none â€” re-prompting (z/3)Ú_dropped_toolcall_nudgec              3  óT   <"  € T F  pSR,          P                  V4      x € K  	  R# 5i)é   Néÿÿÿÿ)rM   )rO   Úflagr1   s   & €r*   rQ   rR   H  s%   øé € ÐPÑ3O¨4�˜•× Ñ  ×&Ð&Ó3Oùs   ƒ%()r   r1   r3   Úpending_verification_responseÚ'pending_verification_response_previewed)Úapply_llm_output_transformÚ_interrupt_requestedÚ_current_turn_id)Úturn_idÚloggeruf   final text-turn flush failed (session=%s) â€” reply is not yet durable; relying on finalize_turn retryÚ
session_idÚnone)Úexc_infoztext_response(finish_reason=Ú)u"   ðŸŽ‰ Conversation completed after z OpenAI-compatible API call(s))Nr!   rx   )IÚagent.conversation_loopr:   r;   r<   r=   rn   rW   rK   r   ÚstripÚanyÚgetattrr   Ú_extract_reasoningr€   ÚwarningÚlenÚmodelÚproviderÚsumÚ_mute_post_responseÚ_has_content_after_think_blockr   r   rY   r   rZ   r   r   r    Ú_empty_content_retriesÚ_thinking_prefill_retriesÚ_emit_pending_fallback_noticeÚ_clear_status_bufferÚagent.agent_runtime_helpersr]   r^   r_   r`   ra   Ú_strip_think_blocksÚboolÚvalid_tool_namesÚ"_looks_like_codex_intermediate_ackÚinfoÚ_build_assistant_messager   Ú_emit_interim_assistant_messageÚ_session_messagesrL   Úpopr	   r
   Ú_REPETITION_STOPPEDÚ_vprintÚ
log_prefixÚ_cleanup_task_resourcesÚ_persist_sessionr   r   rt   Ú_emit_diagnostic_statusÚ_EPHEMERAL_SCAFFOLDING_FLAGSr   rz   r{   Úcontinue_turnÚagent.turn_finalizerr|   Ú_flush_messages_to_session_dbÚ	ExceptionÚ
quiet_modeÚ_safe_print)0r-   r.   r/   r0   r1   r2   r3   r   r4   r   r   r   r   r   r   r   r   r   r5   r:   r;   r<   r=   rA   Ú_contentÚ	_promotedÚ_evr]   r^   r_   r`   ra   Ú	_ack_modeÚ_stall_textÚ_stall_continue_intentÚ
_tool_rowsÚ_degenerate_finalÚ_continuation_kindÚinterim_msgÚ_fragÚlineÚuser_responseÚerrorÚ	final_msgÚ_sgr|   Ú_transformedÚ_s0   &$$$d$$d$ddddddddd$                             r*   Úfinish_text_responser¾   8   s;  ÿú€ ÷ó ÷

÷ 
ó 
ð4 !×(Ñ(€HØ€Ià˜ÕØ!×,×,Ñ,ØÒ¤*¨X´s×";Ò";ÀHÇNÁN×DTÒDTß“ñ 
ô
 Ð.Ð0CÀTÓJ×PÐPÈbÐPó
——’ñ 
ô
 Ð.Ð0CÀTÓJ×PÐPÈbÐPó
÷ 
ò 
ô +¨5×1Ò1à×,Ñ,Ð->Ó?×GÐGÀ4ˆ	ßô �N‰NðMä�I“ §¡¨U¯^©^¸^ÜÑx™xÓxÓxô	ð ×AÐAÐ"3×";Ñ";×AÐA¸r€Nð !&€EÔð ×/Ñ/°×?Ò?Ü$Ø hÈnØ¨LØ!5ÀnØ.Ø*Hô
ˆð ×+Ñ+ˆØ×0Ñ0ÐØ"×7Ñ7ÐØ),×)JÑ)JÐ&Ø×+Ñ+ˆØ�:‰:˜Ô!Ù˜H c§j¡jÓ1Ð1Ø�:‰:˜Ô Ù˜GÓ$Ð$Ù˜
Ó#Ð#à#$€EÔ Ø&'€EÔ#ð 
×'Ñ'Ô)Ø	×ÑÔ ÷õ ñ
 -¨UÓ3€Ið ×+Ñ+¨N×,@Ð,@¸bÓA€KäŒW�U˜O¨TÓ2Ó3÷ 	
ð 	
Ø×"Ñ"÷	
ð 	
à# aÑ'÷	
ð 	
ñ % [Ó1÷ Vð VÜ�Y“×TÐTÑ$GÈÓ$Tð ñ (¨Ó1€JäŒW�U˜O¨TÓ2Ó3÷ 	Pð 	PØ˜Ñ÷	Pð 	Pà# aÑ'÷	Pð 	Pð ˜‰N÷	Pð 	Pñ (¨À,ÔOð ÷ Ø$Ñß	Ø)Ñà�UÔØ×"×"Ð"Ø# aÔ'Ø×4Ñ4Ø%¸ÐRZØ(¨LÑ8ð 5÷ 
ò 
ð
 #Ñà!ÐßØ Ô(Ü�K‰Kðà1°AÕ5õð
   <Ô/Ü�N‰Nð&Ü'*¨;Ó'7¸ÀSÕ9IÈ:Ø'¨!Õ+ôð
 	  1Õ$ÐØ×4Ñ4Ð5FÈÓUˆßð *8ˆK˜Ñ&Ü�x Ô-Ø×-Ñ-¨kÔ:Ü�xØ�FØØ+=ÀÔ+MÑ'Ø2ð	"
ô 	ð #+ˆÔð ˆÙ˜
Ó#Ð#àÐçÙ.Ð/cÐ1IÐ/cÈNÐ\aÐKbÐ/cÓdˆØ#%Ð Ø"#ÐãˆEÜ˜%¤×&Ô&Ø—	‘	Ð9¸4Ô@Ø—	‘	Ð6¸Ö=ñ ð
 ×.Ñ.¨~Ó>×DÑDÓF€N÷ 	Ü�ÓÔ#6Ô6Ü! .×1Ò1ä%8Ñ"ˆˆm˜UØ�‰˜×)Ñ)Ð*¨4¨&Ð1¸È$ˆÔOØ×%Ñ%Ð&7Ô8Ø×Ñ˜xÐ)=Ô>Ù˜¤-Ü˜8 ^°]ÀEÓJÈKÐY]ó#
ó ð 	ð ×.Ñ.Ð/@ÓP€Ißð $2ˆ	�-Ñ ð
 	˜Ô%Ø!×,×,Ð,Ü�EÐ6¸Ó:¸QÔ>ä*1°%Ð9TÐVWÓ*XÐ[\Õ*\ˆÔ'Ü�‰ð1ð ×+Ñ+¨U¯[©[¸%¿.¹.ô		
ð 	×%Ñ%ðØ"×<Ñ<Ð=¸SðBô	
ð 04ˆ	Ð+Ñ,Ü�x Ô+Ü�xØ�FØÐ6Ø% tð"
ô 	ð
 #+ˆÔØˆÙ˜
Ó#Ð#ð '(€EÔ#÷
 	Ü�x •|¤T×*Ò*ß‹CÔPÕ3OÓP�C�CŠCÔPÕ3OÓP×PÒPà�‰Žä
Øˆy¨À(Ø1Ø&DØ0Xô	€Cð &)×%FÑ%FÐ"Ø/2×/ZÑ/ZÐ,Ø
××ÐØˆÙ˜
Ó#Ð#õ @Ø€LÜ�5Ð0°%×8Ò8Ù*DØ�>¬7°5Ð:LÈbÓ+Q×+WÐ+WÐUWÔ`fô+
Ñ'ˆ˜ a÷ ßØ'5ˆI�mÒ$à#1ˆI�iÑ ä�8˜YÔ'ð
Ø×+Ñ+¨HÐ6JÔKð 7°}°oÀQÐGÐØ××ÐØ×ÑÐ>¸~Ð>NÐNlÐmÔnÙ�GÓÐøô ô 
Ü�‰ð>ä�E˜<¨Ó.×8Ð8°&Øð	 	ö 	
ð
ús   ß`	 à	.aà8	aáa)Ú_thinking_prefillÚ_empty_recovery_syntheticÚ_empty_terminal_sentinelru   ) r&   Ú
__future__r   Údataclassesr   ÚloggingÚtypingr   r   r   Úagent.message_metadatar   Úagent.reasoning_promotionr   Úagent.repetition_guardr	   r
   Úagent.turn_failure_copyr   Úagent.turn_empty_responser   Úagent.turn_stop_gatesr   Úagent.turn_truncationr   r   rŸ   Ú	getLoggerr€   r¥   r   r¾   r!   r)   r*   Ú<module>rÎ      s~   ðñõ #å !Û ß &Ñ &å 1Ý Dß MÝ 1Ý <Ý 2ß Aá%ØØ+ØóÐ ð
 
×	Ò	Ð4Ó	5€ð Ð ð ÷,ð ,ó ð,÷&@r)   