§
    ™Štjâ  ã                   óz   — d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ dedefd	„Z G d
„ de¦  «        ZdS )é    N)ÚLiteral)ÚAgentActionÚAgentFinish)ÚField)Úoverride)ÚAgentOutputParserÚtextÚreturnc                 óx   — dddddddœ}|                      ¦   «         D ]\  }}|                      ||¦  «        } Œ| S )z1Convert custom tag delimiters back into XML tags.z<tool>z</tool>z<tool_input>z</tool_input>z<observation>z</observation>)z[[tool]]z	[[/tool]]z[[tool_input]]z[[/tool_input]]z[[observation]]z[[/observation]])ÚitemsÚreplace)r	   ÚreplacementsÚreplÚorigs       úi/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_classic/agents/output_parsers/xml.pyÚ	_unescaper      s]   € ð ØØ(Ø*Ø*Ø,ðð €Lð #×(Ò(Ñ*Ô*ð (ð (‰
ˆˆdØ�|Š|˜D $Ñ'Ô'ˆˆØ€Kó    c                   ó¨   — e Zd ZU dZ ed¬¦  «        Zed         dz  ed<   	 ede	de
ez  fd„¦   «         Zede	fd	„¦   «         Zede	fd
„¦   «         ZdS )ÚXMLAgentOutputParsera˜  Parses tool invocations and final answers from XML-formatted agent output.

    This parser extracts structured information from XML tags to determine whether
    an agent should perform a tool action or provide a final answer. It includes
    built-in escaping support to safely handle tool names and inputs
    containing XML special characters.

    Args:
        escape_format: The escaping format to use when parsing XML content.
            Supports 'minimal' which uses custom delimiters like [[tool]] to replace
            XML tags within content, preventing parsing conflicts.
            Use 'minimal' if using a corresponding encoding format that uses
            the _escape function when formatting the output (e.g., with format_xml).

    Expected formats:
        Tool invocation (returns AgentAction):
            <tool>search</tool>
            <tool_input>what is 2 + 2</tool_input>

        Final answer (returns AgentFinish):
            <final_answer>The answer is 4</final_answer>

    !!! note
        Minimal escaping allows tool names containing XML tags to be safely represented.
        For example, a tool named `search<tool>nested</tool>` would be escaped as
        `search[[tool]]nested[[/tool]]` in the XML and automatically unescaped during
        parsing.

    Raises:
        ValueError: If the input doesn't match either expected XML format or
            contains malformed XML structure.
    Úminimal)ÚdefaultNÚescape_formatr	   r
   c                 ó  — t          j        d|t           j        ¦  «        }|rÙt          |¦  «        dk    r"dt          |¦  «        › d�}t	          |¦  «        ‚|d         }t          j        d|t           j        ¦  «        }t          |¦  «        dk    r"dt          |¦  «        › d�}t	          |¦  «        ‚|r|d         nd}| j        d	k    rt          |¦  «        }t          |¦  «        }t          |||¬
¦  «        S d|v r}d|v ryt          j        d|t           j        ¦  «        }t          |¦  «        dk    rd}t	          |¦  «        ‚|d         }| j        d	k    rt          |¦  «        }t          d|i|¬¦  «        S d}t	          |¦  «        ‚)Nz<tool>(.*?)</tool>é   zHMalformed tool invocation: expected exactly one <tool> block, but found ú.r   z<tool_input>(.*?)</tool_input>zNMalformed tool invocation: expected at most one <tool_input> block, but found Ú r   )ÚtoolÚ
tool_inputÚlogz<final_answer>z</final_answer>z"<final_answer>(.*?)</final_answer>zNMalformed output: expected exactly one <final_answer>...</final_answer> block.Úoutput)Úreturn_valuesr   zTMalformed output: expected either a tool invocation or a final answer in XML format.)	ÚreÚfindallÚDOTALLÚlenÚ
ValueErrorr   r   r   r   )	Úselfr	   Útool_matchesÚmsgÚ_toolÚinput_matchesÚ_tool_inputÚmatchesÚanswers	            r   ÚparsezXMLAgentOutputParser.parseE   sÐ  € õ ”zÐ"7¸½r¼yÑIÔIˆØð 	MÝ�<Ñ Ô  AÒ%Ð%ð6Ý!$ \Ñ!2Ô!2ð6ð 6ð 6ð õ ! ‘o”oÐ%Ø  ”OˆEõ œJØ1°4½¼ñô ˆMõ �=Ñ!Ô! AÒ%Ð%ð>Ý(+¨MÑ(:Ô(:ð>ð >ð >ð õ ! ‘o”oÐ%Ø.;ÐC˜-¨Ô*Ð*ÀˆKð Ô! YÒ.Ð.Ý! %Ñ(Ô(�Ý'¨Ñ4Ô4�å E°kÀtÐLÑLÔLÐLà˜tÐ#Ð#Ð(9¸TÐ(AÐ(AÝ”jÐ!FÈÍbÌiÑXÔXˆGÝ�7‰|Œ|˜qÒ Ð ð>ð õ ! ‘o”oÐ%Ø˜Q”ZˆFàÔ! YÒ.Ð.Ý" 6Ñ*Ô*�Ý¨h¸Ð-?ÀTÐJÑJÔJÐJð/ð 	õ ˜‰oŒoÐr   c                 ó   — t           ‚)N)ÚNotImplementedError©r'   s    r   Úget_format_instructionsz,XMLAgentOutputParser.get_format_instructionsx   s   € å!Ð!r   c                 ó   — dS )Nz	xml-agent© r2   s    r   Ú_typezXMLAgentOutputParser._type|   s   € àˆ{r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú__annotations__r   Ústrr   r   r/   r3   Úpropertyr6   r5   r   r   r   r      sÑ   € € € € € € ðð ðB 05¨u¸YÐ/GÑ/GÔ/G€M�7˜9Ô%¨Ñ,ÐGÐGÑGðð ð0˜#ð 0 +°Ñ";ð 0ð 0ð 0ñ „Xð0ðd ð"¨ð "ð "ð "ñ „Xð"ð ð�sð ð ð ñ „Xðð ð r   r   )r"   Útypingr   Úlangchain_core.agentsr   r   Úpydanticr   Útyping_extensionsr   Úlangchain_classic.agentsr   r<   r   r   r5   r   r   ú<module>rC      sÏ   ðØ 	€	€	€	Ø Ð Ð Ð Ð Ð à :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &à 6Ð 6Ð 6Ð 6Ð 6Ð 6ð�Cð ˜Cð ð ð ð ðdð dð dð dð dÐ,ñ dô dð dð dð dr   