
    h                     ~    d dl 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
 de
dedefd	Zd
eeeef      dee   fdZy)    N)Sequence)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 :w xY w)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      f/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain/agents/format_scratchpad/tools.py_create_tool_messager      sl     k3'	'jj5AG !..!<#4#45 	  	'+&G	's   A A'&A'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 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 A!klO4l../$\;?L OOLPSCx<OSPQOOIl.>.>?@A 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+   