
    3fi                         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 dlmZ  ej                  e      Zdeded	efd
Zdeeeef      d	ee
   fdZy)    N)Sequence)Any)AgentAction)	AIMessageBaseMessageToolMessage)ToolAgentActionagent_actionobservationreturnc                 (   t        |t              s	 t        j                  |d      }n|}t        | j                  |d| j                  i      S # t        $ r t        |      }Y :t
        $ r# t        j                  d       t        |      }Y dw xY w)al  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_asciiz2Unexpected error converting observation to string.name)tool_call_idcontentadditional_kwargs)
isinstancestrjsondumps	TypeError	Exception_logger	exceptionr   r   tool)r
   r   r   s      n/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/agents/format_scratchpad/tools.py_create_tool_messager      s      k3'	'jj5AG !..!<#4#45   	'+&G 	'RS+&G	's   A B&(BBintermediate_stepsc                 "   g }| D ]  \  }}t        |t              rHg t        |j                        t	        ||      }|j                  |D cg c]	  }||vs| c}       ^|j                  t        |j                                |S c c}w )zConvert (AgentAction, tool output) tuples into `ToolMessage` objects.

    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(   3   s     H%7 A!klO4l../$\;?L OOLPSCx<OSPQOOIl.>.>?@A O Qs   	B
B
)r   loggingcollections.abcr   typingr   langchain_core.agentsr   langchain_core.messagesr   r   r   -langchain_classic.agents.output_parsers.toolsr	   	getLogger__name__r   r   tupler   r    r(        r   <module>r4      s      $  -  J
'

H
%! B {C'7!89	+r3   