
    m
i                    &   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlm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m Z m!Z! ddl"m#Z# ddl$m%Z%  eded           G d de                      Z&dS )zDAn agent designed to hold a conversation in addition to using tools.    )annotations)Sequence)Any)
deprecated)BaseCallbackManager)BaseLanguageModel)PromptTemplate)BaseTool)Field)override)AGENT_DEPRECATION_WARNING)AgentAgentOutputParser)	AgentTypeConvoOutputParser)FORMAT_INSTRUCTIONSPREFIXSUFFIX)validate_tools_single_input)LLMChainz0.1.0z1.0)messageremovalc            	      .    e Zd ZU dZdZded<   	  ee          Zded<   	 e	e
	 d$d%d                        Zed&d            Zed&d            Zed&d            Ze	eeedddfd'd            Ze	d( fd            Ze	ddeeedddfd)d#            Z xZS )*ConversationalAgentz>An agent that holds a conversation in addition to using tools.AIstr	ai_prefix)default_factoryr   output_parserkwargsr   returnc                "    t          |          S )Nr   r   )clsr   r!   s      C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langchain_classic/agents/conversational/base.py_get_default_output_parserz.ConversationalAgent._get_default_output_parser*   s     !95555    c                    t           j        S )z Return Identifier of agent type.)r    CONVERSATIONAL_REACT_DESCRIPTIONselfs    r&   _agent_typezConversationalAgent._agent_type3   s     99r(   c                    dS )z]Prefix to append the observation with.

        Returns:
            "Observation: "
        zObservation:  r+   s    r&   observation_prefixz&ConversationalAgent.observation_prefix8   s	     r(   c                    dS )zVPrefix to append the llm call with.

        Returns:
            "Thought: "
        zThought:r/   r+   s    r&   
llm_prefixzConversationalAgent.llm_prefixA   s	     zr(   HumanNtoolsSequence[BaseTool]prefixsuffixformat_instructionshuman_prefixinput_variableslist[str] | Noner	   c                    d                     d |D                       }d                     d |D                       }	|                    |	||          }| d| d| d| }
|g d}t          |
|	          S )
a  Create prompt in the style of the zero-shot agent.

        Args:
            tools: List of tools the agent will have access to, used to format the
                prompt.
            prefix: String to put before the list of tools.
            suffix: String to put after the list of tools.
            format_instructions: Instructions on how to use the tools.
            ai_prefix: String to use before AI output.
            human_prefix: String to use before human output.
            input_variables: List of input variables the final prompt will expect.
                Defaults to `["input", "chat_history", "agent_scratchpad"]`.

        Returns:
            A PromptTemplate with the template assembled from the pieces here.
        
c                2    g | ]}d |j          d|j         S )z> z: )namedescription.0tools     r&   
<listcomp>z5ConversationalAgent.create_prompt.<locals>.<listcomp>f   s.    DDDd1$)11t/11DDDr(   z, c                    g | ]	}|j         
S r/   r?   rA   s     r&   rD   z5ConversationalAgent.create_prompt.<locals>.<listcomp>h   s    <<<d	<<<r(   )
tool_namesr   r9   z

N)inputchat_historyagent_scratchpad)templater:   )joinformatr	   )r%   r4   r6   r7   r8   r   r9   r:   tool_stringsrG   rK   s              r&   create_promptz!ConversationalAgent.create_promptJ   s    6 yyDDeDDD
 
 YY<<e<<<==
188!% 9 
 

 UU,UU4GUUVUU"KKKOxQQQQr(   Nonec                t    t                                          |           t          | j        |           d S )N)super_validate_toolsr   __name__)r%   r4   	__class__s     r&   rS   z#ConversationalAgent._validate_toolss   s3    &&&#CL%88888r(   llmr   callback_managerBaseCallbackManager | NoneAgentOutputParser | Noner   c           	         |                      |           |                     |||	||||
          }t          |||          }d |D             }|p|                     |          } | d||||d|S )a  Construct an agent from an LLM and tools.

        Args:
            llm: The language model to use.
            tools: A list of tools to use.
            callback_manager: The callback manager to use.
            output_parser: The output parser to use.
            prefix: The prefix to use in the prompt.
            suffix: The suffix to use in the prompt.
            format_instructions: The format instructions to use.
            ai_prefix: The prefix to use before AI output.
            human_prefix: The prefix to use before human output.
            input_variables: The input variables to use.
            **kwargs: Any additional keyword arguments to pass to the agent.

        Returns:
            An agent.
        )r   r9   r6   r7   r8   r:   )rV   promptrW   c                    g | ]	}|j         
S r/   rF   rA   s     r&   rD   z:ConversationalAgent.from_llm_and_tools.<locals>.<listcomp>   s    222Ddi222r(   r$   )	llm_chainallowed_toolsr   r    r/   )rS   rO   r   r'   )r%   rV   r4   rW   r    r6   r7   r8   r   r9   r:   r!   r[   r]   rG   _output_parsers                   r&   from_llm_and_toolsz&ConversationalAgent.from_llm_and_toolsx   s    B 	E"""""% 3+ # 
 
 -
 
 
	
 32E222
& 
#*H*H +I +
 +
 s 
$(	
 

 
 
 	
r(   )r   )r   r   r!   r   r"   r   )r"   r   )r4   r5   r6   r   r7   r   r8   r   r   r   r9   r   r:   r;   r"   r	   )r4   r5   r"   rP   )rV   r   r4   r5   rW   rX   r    rY   r6   r   r7   r   r8   r   r   r   r9   r   r:   r;   r!   r   r"   r   )rT   
__module____qualname____doc__r   __annotations__r   r   r    classmethodr   r'   propertyr-   r0   r2   r   r   r   rO   rS   r`   __classcell__)rU   s   @r&   r   r      s         IHI)',u=N'O'O'OMOOOO& 6 6 6 6 X [6 : : : X:    X    X  #6#,0&R &R &R &R [&RP 9 9 9 9 9 [9 
 8<26#6#,09
 9
 9
 9
 [9
 9
 9
 9
 9
r(   r   N)'rc   
__future__r   collections.abcr   typingr   langchain_core._apir   langchain_core.callbacksr   langchain_core.language_modelsr   langchain_core.promptsr	   langchain_core.toolsr
   pydanticr   typing_extensionsr   "langchain_classic._api.deprecationr   langchain_classic.agents.agentr   r   $langchain_classic.agents.agent_typesr   5langchain_classic.agents.conversational.output_parserr   .langchain_classic.agents.conversational.promptr   r   r   langchain_classic.agents.utilsr   langchain_classic.chainsr   r   r/   r(   r&   <module>ry      s   J J " " " " " " $ $ $ $ $ $       * * * * * * 8 8 8 8 8 8 < < < < < < 1 1 1 1 1 1 ) ) ) ) ) )       & & & & & & H H H H H H C C C C C C C C : : : : : : S S S S S S         
 G F F F F F - - - - - - %  
P
 P
 P
 P
 P
% P
 P
 
P
 P
 P
r(   