+
    iHàjy  ã                  ó¼   € R t ^ RIHt ^ RIt^ RIHtHtHtHt ^ RI	H
t
 ^ RIHtHt ^ RIHt ]]]]]3,          ]],          R3,          tR R ltR	 R
 ltR R ltR# )a¦  Scripted prelude: tool calls a prompt built-in plays before the turn's first model call.

A prelude is a generator owned by the caller that starts the turn (the desktop onboarding opening is the
intended one). Each step it yields ``(content, tool_name, args)``: the assistant text and the one
tool call that row carries. The loop runs it through the unchanged ``run_tool_round`` (row persisted
before the tool runs, interim text and tool events emitted, tool hooks fired) and sends the tool's
result string back into the generator, so a later step can use an earlier answer.

It runs before any provider call, so the rows sit between this turn's user message and the first
model call: nothing cached is mutated, the system prompt is untouched, no user row is added, and
roles alternate ``user -> assistant(tool_calls) -> tool -> ... -> assistant(model)``. No API call is
counted and no ``pre/post_api_request`` hook fires for a step.
)ÚannotationsN)ÚAnyÚ	GeneratorÚOptionalÚTuple)Údeterministic_call_id)ÚNormalizedResponseÚbuild_tool_call)Úrun_tool_roundc          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	é   Ú
session_idÚstrÚnameÚargsÚdictÚindexÚintÚreturn© )Úformats   "Ú@/home/ubuntu/.hermes/hermes-agent/agent/turn_scripted_prelude.pyÚ__annotate__r      s6   € ÷ bñ b ð b¨3ð b°dð bÀ3ð bÈ3ñ bó    c           
     óP   € \        W R\        P                  ! VRR7       2V4      # )z§Seeded by the session, the call and its place in history: no two chats share an id (a rerun plays
the same card at the same place), and it stays byte-stable on replay.Ú:T)Ú	sort_keys)r   ÚjsonÚdumps)r   r   r   r   s   &&&&r   Úprelude_call_idr      s*   € ô ! ¨°Q´t·z²zÀ$ÐRVÔ7WÐ6XÐ'YÐ[`ÓaÐar   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úagentr   ÚsÚpreludeÚPreluder   r   )r   s   "r   r   r   !   s(   € ÷ ñ  ð ¨ð °gð À#ñ r   c                ó&  € ^ RI Hp RRrTV P                  '       gÔ    VP                  V4      w  rgpRTn        \        TR\        \        T P                  Yx\        TP                  4      4      Yx4      .R7      Tn        T! \        Y4      pTP                  R8w  d   MRTP                  '       d   TP                  R	,          M/ p	T	P                  R4      R8X  d   T	P                  R4      MRpKå  VP!                  4        V#   \         d     K   i ; i)
zµPlay ``prelude`` into the loop state ``s``; returns the last tool round's verdict, or None when
no step ran. The caller ends the turn on ``return`` and skips the model on ``break``.)Ú
_run_phaseNÚ
tool_calls)ÚcontentÚfinish_reasonr'   ÚcontinueÚroleÚtoolr(   éÿÿÿÿ)Úagent.conversation_loopr&   Ú_interrupt_requestedÚsendÚStopIterationr)   r   r	   r   r   ÚlenÚmessagesÚassistant_messager
   ÚactionÚgetÚclose)
r!   r"   r#   r&   ÚverdictÚresultr(   r   r   Útails
   &&&       r   Úrun_scripted_preluder;   !   sî   € õ 3à˜DˆVØ×(×(Ð(ð	Ø")§,¡,¨vÓ"6ÑˆG˜4ð 'ˆŒÜ0Ø¨<Ü'¬¸×8HÑ8HÈ$ÔVYÐZ[×ZdÑZdÓVeÓ(fÐhlÓsÐtôvˆÔñ œ^¨UÓ6ˆØ�>‰>˜ZÔ'ØØ!"§§ ˆq�z‰z˜"Ž~°ˆØ(,¯©°Ó(8¸FÔ(B�—‘˜)Ô$ÈŠØ‡M�M„OØ€Nøô ô 	Úð	ús   �D ÄDÄDc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r!   r   r"   r#   zOptional[Prelude]r   ztuple[str, Any]r   )r   s   "r   r   r   9   s)   € ÷ ñ ˜ð  ð Ð.?ð ÀOñ r   c                ó„   € Ve   \        WV4      MRpVe*   VP                  R9   d   VP                  VP                  3# R# )z�``("return", result)`` ends the turn now, ``("break", None)`` skips the model call, ``("run", None)`` runs
the loop as usual (also when there is no prelude).N)r   Úbreak)ÚrunN)r;   r5   r9   )r!   r"   r#   r8   s   &&& r   Úplay_preluder@   9   sE   € ð :AÒ9LÔ" 5¨WÔ5ÐRV€GØÒ˜wŸ~™~Ð1DÔDØ�~‰~˜wŸ~™~Ð-Ð-ØÐr   )Ú__doc__Ú
__future__r   r   Útypingr   r   r   r   Úagent.message_sanitizationr   Úagent.transports.typesr   r	   Úagent.turn_tool_roundr
   Útupler   r   r$   r   r;   r@   r   r   r   Ú<module>rH      sQ   ðñõ #ã ß 2Ó 2å <ß FÝ 0à
�E˜#˜s D˜.Õ)¨8°C­=¸$Ð>Õ
?€õbõ÷0r   