
    3fi                    >   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mZmZ dd
lmZ ddlmZ ddlmZmZmZ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(m)Z)m*Z* ddl+m,Z, ddl-m.Z.  eddd       G d de#             Z/y)DAn agent designed to hold a conversation in addition to using tools.    )annotations)Sequence)Any)
deprecated)AgentAction)BaseCallbackManager)BaseLanguageModel)	AIMessageBaseMessageHumanMessage)BaseOutputParser)BasePromptTemplate)ChatPromptTemplateHumanMessagePromptTemplateMessagesPlaceholderSystemMessagePromptTemplate)BaseTool)Field)override)AgentAgentOutputParserConvoOutputParser)PREFIXSUFFIXTEMPLATE_TOOL_RESPONSE)validate_tools_single_input)LLMChainz0.1.0create_json_chat_agentz1.0)alternativeremovalc                  2    e Zd ZU dZ ee      Zded<   	 eZ	ded<   	 e
edd              Zedd       Zedd	       Zedd
       Ze
d fd       Ze
eeddf	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 ddZe
ddeedf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z xZS )ConversationalChatAgentr   )default_factoryr   output_parserstrtemplate_tool_responsec                    t               S Nr   )clskwargss     o/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/agents/conversational_chat/base.py_get_default_output_parserz2ConversationalChatAgent._get_default_output_parser-   s     !""    c                    t         r*   )NotImplementedErrorselfs    r-   _agent_typez#ConversationalChatAgent._agent_type2   s    !!r/   c                     y)z]Prefix to append the observation with.

        Returns:
            "Observation: "
        zObservation:  r2   s    r-   observation_prefixz*ConversationalChatAgent.observation_prefix6   s     r/   c                     y)zVPrefix to append the llm call with.

        Returns:
            "Thought: "
        zThought:r6   r2   s    r-   
llm_prefixz"ConversationalChatAgent.llm_prefix?   s     r/   c                P    t         |   |       t        | j                  |       y r*   )super_validate_toolsr   __name__)r+   tools	__class__s     r-   r<   z'ConversationalChatAgent._validate_toolsH   s    &#CLL%8r/   Nc           	        dj                  |D cg c]  }d|j                   d|j                     c}      }dj                  |D cg c]  }|j                   c}      }|xs | j                         }	|j	                  |	j                               }
|
j	                  ||      }|g d}t        j                  |      t        d	      t        j                  |      t        d
	      g}t        ||      S c c}w c c}w )ai  Create a prompt for the agent.

        Args:
            tools: The tools to use.
            system_message: The `SystemMessage` to use.
            human_message: The `HumanMessage` to use.
            input_variables: The input variables to use.
            output_parser: The output parser to use.

        Returns:
            A `PromptTemplate`.
        
z> z: z, )format_instructions)
tool_namesr>   )inputchat_historyagent_scratchpadrE   )variable_namerF   )input_variablesmessages)joinnamedescriptionr.   formatget_format_instructionsr   from_templater   r   r   )r+   r>   system_messagehuman_messagerH   r&   tooltool_stringsrC   _output_parserrB   final_promptrI   s                r-   create_promptz%ConversationalChatAgent.create_promptM   s   * yy>CDdr$))Bt//01D
 YYe<d		<=
&J#*H*H*J+22 . F F H 3 
 +11! 2 
 "KO'55nEn=&44\B.@A	
 "/HUU' E<s   #C=	Dc                    g }|D ]a  \  }}|j                  t        |j                               t        | j                  j                  |            }|j                  |       c |S )zJConstruct the scratchpad that lets the agent continue its thought process.)content)observation)appendr   logr   r(   rM   )r3   intermediate_stepsthoughtsactionrY   rQ   s         r-   _construct_scratchpadz-ConversationalChatAgent._construct_scratchpadx   sh    
 ')#5 	+FKOOIfjj9:(33::{:SM OOM*	+ r/   c                    | j                  |       |xs | j                         }	| j                  |||||	      }
t        ||
|      }|D cg c]  }|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.
            output_parser: The output parser to use.
            system_message: The `SystemMessage` to use.
            human_message: The `HumanMessage` to use.
            input_variables: The input variables to use.
            **kwargs: Any additional arguments.

        Returns:
            An agent.
        )rP   rQ   rH   r&   )llmpromptcallback_manager)	llm_chainallowed_toolsr&   r6   )r<   r.   rV   r   rK   )r+   ra   r>   rc   r&   rP   rQ   rH   r,   rT   rb   rd   rR   rC   s                 r-   from_llm_and_toolsz*ConversationalChatAgent.from_llm_and_tools   s    6 	E"&J#*H*H*J"")'+( # 
 -
	
 -22Ddii2
2 
$(
 	
 	
 3s   A/)r,   r   returnr   )rg   r'   )r>   Sequence[BaseTool]rg   None)r>   rh   rP   r'   rQ   r'   rH   list[str] | Noner&   zBaseOutputParser | Nonerg   r   )r\   zlist[tuple[AgentAction, str]]rg   zlist[BaseMessage])ra   r
   r>   rh   rc   zBaseCallbackManager | Noner&   zAgentOutputParser | NonerP   r'   rQ   r'   rH   rj   r,   r   rg   r   )r=   
__module____qualname____doc__r   r   r&   __annotations__r   r(   classmethodr   r.   propertyr4   r7   r9   r<   r   r   rV   r_   rf   __classcell__)r?   s   @r-   r$   r$   $   s   N',=N'OM$O&"8C8)#  # " "     9 9  %#,015(V!(V (V 	(V
 *(V /(V 
(V (VT9 
 
 8<26$#,0.
.
 ".
 5	.

 0.
 .
 .
 *.
 .
 
.
 .
r/   r$   N)0rm   
__future__r   collections.abcr   typingr   langchain_core._apir   langchain_core.agentsr   langchain_core.callbacksr	   langchain_core.language_modelsr
   langchain_core.messagesr   r   r   langchain_core.output_parsersr   langchain_core.promptsr   langchain_core.prompts.chatr   r   r   r   langchain_core.toolsr   pydanticr   typing_extensionsr   langchain_classic.agents.agentr   r   :langchain_classic.agents.conversational_chat.output_parserr   3langchain_classic.agents.conversational_chat.promptr   r   r   langchain_classic.agents.utilsr   langchain_classic.chainsr   r$   r6   r/   r-   <module>r      s    J " $  * - 8 < H H : 5  *  & C X 
 G - G!95IP
e P
 JP
r/   