+
    Ji                         R t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ]P                  ! ]	4      t
R R ltR R ltR
R R	 lltR# )zTrajectory saving utilities and static helpers.

_convert_to_trajectory_format stays as an AIAgent method (batch_runner.py
calls agent._convert_to_trajectory_format). Only the static helpers and
the file-write logic live here.
N)datetime)AnyDictListc                0    V ^8  d   QhR\         R\         /#    contentreturn)str)formats   "-/home/ubuntu/hermes-agent/agent/trajectory.py__annotate__r      s     o o o o    c                h    V '       d   RV 9  d   V # V P                  RR4      P                  RR4      # )z4Convert <REASONING_SCRATCHPAD> tags to <think> tags.<REASONING_SCRATCHPAD>z<think></REASONING_SCRATCHPAD>z</think>)replacer	   s   &r   convert_scratchpad_to_thinkr      s3    .g=??3Y?GGHacmnnr   c                0    V ^8  d   QhR\         R\        /# r   )r   bool)r   s   "r   r   r      s     \ \s \t \r   c                :    V '       g   R# RV 9   ;'       d    RV 9  # )zMCheck if content has an opening <REASONING_SCRATCHPAD> without a closing tag.Fr   r    r   s   &r   has_incomplete_scratchpadr      s"    #w.[[3LT[3[[r   c                    V ^8  d   QhR\         \        \        \        3,          ,          R\        R\        R\        /# )r   
trajectorymodel	completedfilename)r   r   r   r   r   )r   s   "r   r   r      s7     ; ;T#s(^ 4 ;S ;#;/2;r   c           	        Vf   V'       d   RMRpRV R\         P                  ! 4       P                  4       RVRV/p \        VRR	R
7      ;_uu_ 4       pVP	                  \
        P                  ! VRR7      R,           4       RRR4       \        P                  RV4       R#   + '       g   i     L(; i  \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)a]  Append a trajectory entry to a JSONL file.

Args:
    trajectory: The ShareGPT-format conversation list.
    model: Model name for metadata.
    completed: Whether the conversation completed successfully.
    filename: Override output filename. Defaults to trajectory_samples.jsonl
              or failed_trajectories.jsonl based on ``completed``.
Nztrajectory_samples.jsonlzfailed_trajectories.jsonlconversations	timestampr   r   azutf-8)encodingF)ensure_ascii
zTrajectory saved to %szFailed to save trajectory: %s)r   now	isoformatopenwritejsondumpsloggerinfo	Exceptionwarning)r   r   r   r   entryfes   &&&&   r   save_trajectoryr4      s     1:-@[ 	X\\^--/Y	E;(C'22aGGDJJu59D@A 3,h7 32  ;6::;s/   B5 /B"B5 "B2	-B5 5C! CC!)N)__doc__r+   loggingr   typingr   r   r   	getLogger__name__r-   r   r   r4   r   r   r   <module>r:      sA       " "			8	$o\; ;r   