
    yj                         d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ dedz  fdZdddd	ddd
dedeez  dedededz  dedz  dedz  dedee         dz  deeeef                  dz  ddfdZdS )zr
Utility for logging traces from LLM calls.

This module provides structured JSONL logging of LLM inputs/outputs.
    N)Path)Any)	BaseModel)ConfiguredModelSettingsModelConfigsettingsreturnc                  P    t           j        rt          t           j                  S dS )z'Get the traces file path from settings.N)r   REASONING_TRACES_FILEr        F/DATA/AppData/hermes/projects/honcho/src/telemetry/reasoning_traces.pyget_reasoning_traces_file_pathr      s#    % 4H23334r   F)
max_tokensthinking_budget_tokensreasoning_effort	json_mode	stop_seqsmessages	task_typemodel_configpromptresponser   r   r   r   r   r   c                    t                      }
|
sdS |j        }t          |t                    r|                                }t          j                    | |j        |j        |||||dd|j        i||j	        |j
        |j        dd}|	|	|d         d<   n||d         d<   t          |d	          r|j        r|j        |d
         d<   t          |
d          5 }t          j        |                                t          j                   |                    t)          j        |          dz              t          j        |                                t          j                   ddd           dS # 1 swxY w Y   dS )a  
    Log a trace to the configured JSONL file.

    Args:
        task_type: Type of task (e.g., "minimal_deriver", "dialectic_chat")
        model_config: Model configuration used for the call
        prompt: The full prompt text sent to the LLM (used if messages is None)
        response: HonchoLLMCallResponse object with the LLM response
        max_tokens: Max output tokens setting
        thinking_budget_tokens: Anthropic thinking budget (if used)
        reasoning_effort: OpenAI reasoning effort (if used)
        json_mode: Whether JSON mode was enabled
        stop_seqs: Stop sequences used (if any)
        messages: Full conversation history for multi-turn/agentic calls
    N)r   r   r   r   r   tokens)contentr   finish_reasonsthinking_content)	timestampr   providermodelr   inputoutputr"   r   r   tool_calls_mader#   
tool_callsa
)r   r   
isinstancer   
model_dumptime	transportr!   input_tokensoutput_tokensr   r   hasattrr$   openfcntlflockfilenoLOCK_EXwritejsondumpsLOCK_UN)r   r   r   r   r   r   r   r   r   r   traces_filer   trace_entryfs                 r   log_reasoning_tracer;      s   8 122K  G'9%% '$$&& Y[[ *#$&< 0""
 
 h+
 ,&5 ( 9	
 
# #K0 +3GZ(()/GX& x*++ G0H G.6.FHl+ 
k3		 /1AHHJJ...	
;''$.///AHHJJ.../ / / / / / / / / / / / / / / / / /s   BE33E7:E7)__doc__r0   r5   r*   pathlibr   typingr   pydanticr   
src.configr   r   r   r   strintboollistdictr;   r   r   r   <module>rF      s                                 t     ")-#'"&,0J/ J/ J/J/ 77J/ J/ 	J/ d
J/  $JJ/ DjJ/ J/ Cy4J/ 4S>"T)J/ 
J/ J/ J/ J/ J/ J/r   