Ë
    ´Œj®  ã                   ón   — d dl Z d dlmZmZmZ d dlmZmZ d dlm	Z	 d dl
mZ dedefd„Z G d	„ d
e«      Zy)é    N)ÚLiteralÚOptionalÚUnion)ÚAgentActionÚAgentFinish)ÚField)ÚAgentOutputParserÚtextÚreturnc                 ól   — dddddddœ}|j                  «       D ]  \  }}| j                  ||«      } Œ | 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       úm/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain/agents/output_parsers/xml.pyÚ	_unescaper   
   sK   € ð ØØ(Ø*Ø*Ø,ñ€Lð #×(Ñ(Ö*‰
ˆˆdØ�|‰|˜D $Ó'‰ð +à€Kó    c                   óx   — e Zd ZU dZ ed¬«      Zeed      ed<   	 de	de
eef   fd„Zde	fd„Zede	fd	„«       Zy
)Ú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)ÚdefaultÚescape_formatr
   r   c                 óÂ  — t        j                  d|t         j                  «      }|r¶t        |«      dk7  rdt        |«      › d�}t	        |«      ‚|d   }t        j                  d|t         j                  «      }t        |«      dkD  rdt        |«      › d�}t	        |«      ‚|r|d   nd}| j
                  d	k(  rt        |«      }t        |«      }t        |||¬
«      S d|v rrd|v rnt        j                  d|t         j                  «      }t        |«      dk7  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.parseD   s  € ä—z‘zÐ"7¸¼r¿y¹yÓIˆÙÜ�<Ó  AÒ%ð!Ü!$ \Ó!2Ð 3°1ð6ð ô ! “oÐ%Ø  ‘OˆEô ŸJ™JØ1°4¼¿¹óˆMô �=Ó! AÒ%ð(Ü(+¨MÓ(:Ð';¸1ð>ð ô ! “oÐ%Ù.;˜-¨Ò*ÀˆKð ×!Ñ! YÒ.Ü! %Ó(�Ü'¨Ó4�ä E°kÀtÔLÐLà˜tÑ#Ð(9¸TÑ(AÜ—j‘jÐ!FÈÌbÏiÉiÓXˆGÜ�7‹|˜qÒ ð>ð ô ! “oÐ%Ø˜Q‘ZˆFà×!Ñ! YÒ.Ü" 6Ó*�Ü¨h¸Ð-?ÀTÔJÐJð/ð 	ô ˜‹oÐr   c                 ó   — t         ‚)N)ÚNotImplementedError©r(   s    r   Úget_format_instructionsz,XMLAgentOutputParser.get_format_instructionsv   s   € Ü!Ð!r   c                  ó   — y)Nz	xml-agent© r3   s    r   Ú_typezXMLAgentOutputParser._typey   s   € àr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Ú__annotations__Ústrr   r   r   r0   r4   Úpropertyr7   r6   r   r   r   r      sm   … ññB 38À	Ô2J€M�8˜G IÑ.Ñ/ÓJðð0˜#ð 0 %¨°[Ð(@Ñ"Aó 0ðd"¨ó "ð ð�sò ó ñr   r   )r#   Útypingr   r   r   Úlangchain_core.agentsr   r   Úpydanticr   Úlangchain.agentsr	   r=   r   r   r6   r   r   Ú<module>rC      s9   ðÛ 	ß +Ñ +ç :Ý å .ð�Cð ˜Có ôbÐ,õ br   