
    @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K
JrJrJr  S SKJrJr  S SKJr   " S	 S
\5      rS\S\\\   \4   4S jr " S S\5      rg)    N)JSONDecodeError)Union)AgentActionAgentActionMessageLogAgentFinish)OutputParserException)	AIMessageBaseMessageToolCall)ChatGeneration
Generation)MultiActionAgentOutputParserc                        \ rS rSr% \\S'   Srg)ToolAgentAction   tool_call_id N)__name__
__module____qualname____firstlineno__str__annotations____static_attributes__r       ]/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/agents/output_parsers/tools.pyr   r      s    7r   r   messagereturnc                 &   [        U [        5      (       d  S[        U 5       3n[        U5      e/ nU R                  (       a  U R                  nOU R
                  R                  S5      (       d)  [        SU R                  0[        U R                  5      S9$ / nU R
                  S    HL  nUS   nUS   n [        R                  " US   =(       d    S5      nUR                  [        XgUS	   S
95        MN     U Hn  nUS   nUS   n	U	R                  SU	5      n
U R                  (       a  SU R                   S3OSnSU SU
 SU S3nUR                  [!        UU
UU /US	   S95        Mp     U$ ! [         a  nSU S3n[        U5      UeSnAff = f)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.Nr(   __arg1zresponded: 
z
Invoking: `z` with `z`
)tool
tool_inputr#   message_logr   )
isinstancer	   type	TypeErrorr    additional_kwargsgetr   contentr   jsonloadsappendr   r   r   r   )r   msgactionsr    	tool_callr$   function_namer(   e_tool_inputr,   content_msgr#   s                r   parse_ai_message_to_tool_actionr>      s    gy))+DM?;nG''
((,,\::'9( 
 
 22<@I ,H$V,M
8zz(;"7"?4@!!-yO A  	 "&)' __X{;
;B??GOO#4B7PTm_HZLK=PRS"%$I&t_	
  , N9 # 828* =9 :  ,C0a78s   7>E//
F9FFc            	           \ rS rSrSr\S\4S j5       rSS.S\\	   S\
S\\\   \4   4S	 jjrS
\S\\\   \4   4S jrSrg)ToolsAgentOutputParserP   zParses 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                     g)Nztools-agent-output-parserr   )selfs    r   _typeToolsAgentOutputParser._typeY   s    *r   F)partialresultrF   c                    [        US   [        5      (       d  Sn[        U5      eUS   R                  n[	        U5      $ )Nr   z6This output parser only works on ChatGeneration output)r.   r   
ValueErrorr   r>   )rC   rG   rF   r7   r   s        r   parse_result#ToolsAgentOutputParser.parse_result]   s>     &)^44JCS/!)##.w77r   textc                     Sn[        U5      e)NzCan only parse messages)rI   )rC   rL   r7   s      r   parseToolsAgentOutputParser.parsei   s    'or   r   N)r   r   r   r   __doc__propertyr   rD   listr   boolr   r   r   rJ   rN   r   r   r   r   r@   r@   P   s~     +s + + 	
8Z 
8 	
8
 
tK +-	.
8# %[(9;(F"G r   r@   )r4   r   typingr   langchain_core.agentsr   r   r   langchain_core.exceptionsr   langchain_core.messagesr	   r
   r   langchain_core.outputsr   r   langchain.agents.agentr   r   rR   r>   r@   r   r   r   <module>rZ      sh        Q Q ; 
 > ?8+ 8
77
4k)*7t9 r   