
    @h                         S SK r S SKJr  S SKJr  S SKJrJrJr  S SK	J
r
  S\
S\S\4S	 jrS
\\\\4      S\\   4S jrg)    N)Sequence)AgentAction)	AIMessageBaseMessageToolMessage)ToolAgentActionagent_actionobservationreturnc                     [        U[        5      (       d   [        R                  " USS9nOUn[        U R                  USU R                  0S9$ ! [         a    [        U5      n N8f = f)aK  Convert agent action and observation into a tool message.

Args:
    agent_action: the tool invocation request from the agent.
    observation: the result of the tool invocation.
Returns:
    ToolMessage that corresponds to the original tool invocation.

Raises:
    ValueError: if the observation cannot be converted to a string.
F)ensure_asciiname)tool_call_idcontentadditional_kwargs)
isinstancestrjsondumps	Exceptionr   r   tool)r	   r
   r   s      `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/agents/format_scratchpad/tools.py_create_tool_messager      so     k3''	'jj5AG !..!<#4#45 	  	'+&G	's   A A('A(intermediate_stepsc                 0   / nU  H  u  p#[        U[        5      (       aL  / [        UR                  5      Q[	        X#5      PnUR                  U Vs/ sH  oUU;  d  M
  UPM     sn5        Mf  UR                  [        UR                  S95        M     U$ s  snf )zConvert (AgentAction, tool output) tuples into ToolMessages.

Args:
    intermediate_steps: Steps the LLM has taken to date, along with observations.

Returns:
    list of messages to send to the LLM for the next prediction.

)r   )	r   r   listmessage_logr   extendappendr   log)r   messagesr	   r
   new_messagesnews         r   format_to_tool_messagesr$   +   s     H%7!lO44l../$\?L OOLPLSx<OSLPQOOIl.>.>?@ &8 O Qs   B
B
)r   collections.abcr   langchain_core.agentsr   langchain_core.messagesr   r   r   %langchain.agents.output_parsers.toolsr   r   r   tupler   r$        r   <module>r,      sf     $ -  B! : {C'7!89	+r+   