o
    Jjg                     @   s   d dl Z d dlmZmZmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ dedede
fd	d
Zdeeeef  dee	 fddZdS )    N)ListSequenceTuple)AgentAction)	AIMessageBaseMessageToolMessage)ToolAgentActionagent_actionobservationreturnc                 C   sR   t |tsz	tj|dd}W n ty   t|}Y nw |}t| j|d| jidS )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    r   `/var/www/html/zoom/venv/lib/python3.10/site-packages/langchain/agents/format_scratchpad/tools.py_create_tool_message   s   
r   intermediate_stepsc                    sb   g  | D ]*\}}t |tr%t|jt||g }  fdd|D  q t|jd q S )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.

    c                    s   g | ]}| vr|qS r   r   ).0newmessagesr   r   
<listcomp><   s    z+format_to_tool_messages.<locals>.<listcomp>)r   )	r   r	   listmessage_logr   extendappendr   log)r   r
   r   new_messagesr   r   r   format_to_tool_messages*   s   
r'   )r   typingr   r   r   langchain_core.agentsr   langchain_core.messagesr   r   r   %langchain.agents.output_parsers.toolsr	   r   r   r'   r   r   r   r   <module>   s"    
