
    Ng                         d dl Z d dl mZ d dlmZm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mZ d dlmZ  G d	 d
e          Zdedeee         ef         fdZ G d de          ZdS )    N)JSONDecodeError)ListUnion)AgentActionAgentActionMessageLogAgentFinish)OutputParserException)	AIMessageBaseMessageToolCall)ChatGeneration
Generation)MultiActionAgentOutputParserc                       e Zd ZU eed<   dS )ToolAgentActiontool_call_idN)__name__
__module____qualname__str__annotations__     a/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain/agents/output_parsers/tools.pyr   r      s         77r   r   messagereturnc                    t          | t                    st          dt          |                      g }| j        r| j        }n| j                            d          s*t          d| j        it          | j                            S g }| j        d         D ]{}|d         }|d         }	 t          j        |d         pd          }|                    t          |||d	         
                     [# t          $ r t          d| d          w xY w|D ]o}|d         }|d         }d|v r	|d         }n|}| j        rd| j         dnd}	d| d| d|	 d}
|                    t!          |||
| g|d	                              p|S )z6Parse an AI message potentially containing tool_calls.zExpected an AI message got 
tool_callsoutput)return_valueslogfunctionname	argumentsz{}id)r#   argsr%   zCould not parse tool input: z+ because the `arguments` is not valid JSON.r&   __arg1zresponded: 
z
Invoking: `z` with `z`
)tool
tool_inputr!   message_logr   )
isinstancer
   	TypeErrortyper   additional_kwargsgetr   contentr   jsonloadsappendr   r   r	   r   )r   actionsr   	tool_callr"   function_namer&   _tool_inputr*   content_msgr!   s              r   parse_ai_message_to_tool_actionr:      s(    gy)) GEd7mmEEFFFG '

(,,\:: 	'9s7??S?S    
 2<@ 	 	I ,H$V,M	z(;"7"?4@@!!-dyOOO    #   +:8 : : :  
   
 
	 "&)'{""$X.JJ$J;B?T7GO7777PTSmSSZSSKSSS"%$I&t_  	
 	
 	
 	
 Ns   ,AC44Dc            	           e Zd ZdZedefd            Zdddee         de	de
ee         ef         fdZd	ede
ee         ef         fd
ZdS )ToolsAgentOutputParserzParses a message into agent actions/finish.

    If a tool_calls parameter is passed, then that is used to get
    the tool names and tool inputs.

    If one is not passed, then the AIMessage is assumed to be the final output.
    r   c                     dS )Nztools-agent-output-parserr   )selfs    r   _typezToolsAgentOutputParser._typeY   s    **r   F)partialresultr@   c                    t          |d         t                    st          d          |d         j        }t	          |          S )Nr   z6This output parser only works on ChatGeneration output)r,   r   
ValueErrorr   r:   )r>   rA   r@   r   s       r   parse_resultz#ToolsAgentOutputParser.parse_result]   sD     &)^44 	WUVVV)#.w777r   textc                      t          d          )NzCan only parse messages)rC   )r>   rE   s     r   parsezToolsAgentOutputParser.parsee   s    2333r   N)r   r   r   __doc__propertyr   r?   r   r   boolr   r   r   rD   rG   r   r   r   r<   r<   P   s          +s + + + X+ <A8 8 8:&8488	tK +-	.8 8 8 84# 4%[(9;(F"G 4 4 4 4 4 4r   r<   )r2   r   typingr   r   langchain_core.agentsr   r   r   langchain_core.exceptionsr	   langchain_core.messagesr
   r   r   langchain_core.outputsr   r   langchain.agents.agentr   r   r:   r<   r   r   r   <module>rQ      sZ                        Q Q Q Q Q Q Q Q Q Q ; ; ; ; ; ;         
 > = = = = = = = ? ? ? ? ? ?8 8 8 8 8+ 8 8 8
77
4k)*7 7 7 7t4 4 4 4 49 4 4 4 4 4r   