
    h                    
   d 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 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%y)zDAn agent designed to hold a conversation in addition to using tools.    )annotations)Sequence)AnyOptional)
deprecated)BaseCallbackManager)BaseLanguageModel)PromptTemplate)BaseTool)Field)AGENT_DEPRECATION_WARNING)AgentAgentOutputParser)	AgentTypeConvoOutputParser)FORMAT_INSTRUCTIONSPREFIXSUFFIX)validate_tools_single_input)LLMChainz0.1.0z1.0)messageremovalc            	      D    e Zd ZU dZdZded<   	  ee      Zded<   	 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_parserc                    t        |      S )Nr   r   )clsr   kwargss      b/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain/agents/conversational/base.py_get_default_output_parserz.ConversationalAgent._get_default_output_parser%   s     !955    c                "    t         j                  S )z Return Identifier of agent type.)r    CONVERSATIONAL_REACT_DESCRIPTIONselfs    r%   _agent_typezConversationalAgent._agent_type-   s     999r'   c                     y)z]Prefix to append the observation with.

        Returns:
            "Observation: "
        zObservation:  r*   s    r%   observation_prefixz&ConversationalAgent.observation_prefix2   s     r'   c                     y)zVPrefix to append the llm call with.

        Returns:
            "Thought: "
        zThought:r.   r*   s    r%   
llm_prefixzConversationalAgent.llm_prefix;   s     r'   HumanNc           	     B   dj                  |D cg c]  }d|j                   d|j                     c}      }	dj                  |D cg c]  }|j                   c}      }
|j                  |
||      }| d|	 d| d| }|g d}t	        ||      S c c}w c c}w )	au  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. Defaults to PREFIX.
            suffix: String to put after the list of tools. Defaults to SUFFIX.
            format_instructions: Instructions on how to use the tools. Defaults to
                FORMAT_INSTRUCTIONS
            ai_prefix: String to use before AI output. Defaults to "AI".
            human_prefix: String to use before human output.
                Defaults to "Human".
            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.
        
z> z: z, )
tool_namesr   human_prefixz

)inputchat_historyagent_scratchpad)templateinput_variables)joinnamedescriptionformatr
   )r#   toolsprefixsuffixformat_instructionsr   r6   r;   tooltool_stringsr5   r:   s               r%   create_promptz!ConversationalAgent.create_promptD   s    : yy>CDdr$))Bt//01D
 YYe<d		<=
188!% 9 

 XT,t4G3HVHU"KOxQQ E<s   #B	Bc                P    t         |   |       t        | j                  |       y )N)super_validate_toolsr   __name__)r#   r@   	__class__s     r%   rI   z#ConversationalAgent._validate_toolso   s    &#CLL%8r'   c           	         | j                  |       | j                  |||	||||
      }t        |||      }|D cg c]  }|j                   }}|xs | j	                  |      } | d||||d|S c c}w )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. Default is None.
            output_parser: The output parser to use. Default is None.
            prefix: The prefix to use in the prompt. Default is PREFIX.
            suffix: The suffix to use in the prompt. Default is SUFFIX.
            format_instructions: The format instructions to use.
                Default is FORMAT_INSTRUCTIONS.
            ai_prefix: The prefix to use before AI output. Default is "AI".
            human_prefix: The prefix to use before human output.
                Default is "Human".
            input_variables: The input variables to use. Default is None.
            **kwargs: Any additional keyword arguments to pass to the agent.

        Returns:
            An agent.
        )r   r6   rA   rB   rC   r;   )llmpromptcallback_managerr"   )	llm_chainallowed_toolsr   r    r.   )rI   rF   r   r=   r&   )r#   rM   r@   rO   r    rA   rB   rC   r   r6   r;   r$   rN   rP   rD   r5   _output_parsers                    r%   from_llm_and_toolsz&ConversationalAgent.from_llm_and_toolst   s    F 	E"""% 3+ # 
 -
	
 -22Ddii2
2& 
#*H*H +I +
  
$(	

 
 	
	 3s   A4)r   )r   r   r$   r   returnr   )rT   r   )r@   Sequence[BaseTool]rA   r   rB   r   rC   r   r   r   r6   r   r;   Optional[list[str]]rT   r
   )r@   rU   rT   None)rM   r	   r@   rU   rO   zOptional[BaseCallbackManager]r    zOptional[AgentOutputParser]rA   r   rB   r   rC   r   r   r   r6   r   r;   rV   r$   r   rT   r   )rJ   
__module____qualname____doc__r   __annotations__r   r   r    classmethodr&   propertyr,   r/   r1   r   r   r   rF   rI   rS   __classcell__)rK   s   @r%   r   r      s    IIs)',=N'OM$O& 66 6 
	6 6 : :      #6#/3(R!(R (R 	(R
 !(R (R (R -(R 
(R (RT 9 9 
 ;?59#6#/3;
;
 ";
 8	;

 3;
 ;
 ;
 !;
 ;
 ;
 -;
 ;
 
;
 ;
r'   r   N)&rZ   
__future__r   collections.abcr   typingr   r   langchain_core._apir   langchain_core.callbacksr   langchain_core.language_modelsr	   langchain_core.promptsr
   langchain_core.toolsr   pydanticr   langchain._api.deprecationr   langchain.agents.agentr   r   langchain.agents.agent_typesr   -langchain.agents.conversational.output_parserr   &langchain.agents.conversational.promptr   r   r   langchain.agents.utilsr   langchain.chainsr   r   r.   r'   r%   <module>ro      sg    J " $   * 8 < 1 )  @ ; 2 K V V > % %
S
% S

S
r'   