§
    ™Štj&  ã                   óœ   — 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 d dlmZ 	 dd
edee
         deded	z  def
d„Zd	S )é    )ÚSequence)ÚBaseLanguageModel)ÚChatPromptTemplate)ÚRunnableÚRunnablePassthrough)ÚBaseTool©Úconvert_to_openai_tool©Úformat_to_openai_tool_messages)ÚOpenAIToolsAgentOutputParserNÚllmÚtoolsÚpromptÚstrictÚreturnc                 ó*  ‡— dh                      |j        t          |j        ¦  «        z   ¦  «        }|rd|› �}t	          |¦  «        ‚|                      ˆfd„|D ¦   «         ¬¦  «        }t          j        d„ ¬¦  «        |z  |z  t          ¦   «         z  S )a¾  Create an agent that uses OpenAI tools.

    Args:
        llm: LLM to use as the agent.
        tools: Tools this agent has access to.
        prompt: The prompt to use. See Prompt section below for more on the expected
            input variables.
        strict: Whether strict mode should be used for OpenAI tools.

    Returns:
        A Runnable sequence representing an agent. It takes as input all the same input
        variables as the prompt passed in does. It returns as output either an
        AgentAction or AgentFinish.

    Raises:
        ValueError: If the prompt is missing required variables.

    Example:
        ```python
        from langchain_classic import hub
        from langchain_openai import ChatOpenAI
        from langchain_classic.agents import (
            AgentExecutor,
            create_openai_tools_agent,
        )

        prompt = hub.pull("hwchase17/openai-tools-agent")
        model = ChatOpenAI()
        tools = ...

        agent = create_openai_tools_agent(model, tools, prompt)
        agent_executor = AgentExecutor(agent=agent, tools=tools)

        agent_executor.invoke({"input": "hi"})

        # Using with chat history
        from langchain_core.messages import AIMessage, HumanMessage

        agent_executor.invoke(
            {
                "input": "what's my name?",
                "chat_history": [
                    HumanMessage(content="hi! my name is bob"),
                    AIMessage(content="Hello Bob! How can I assist you today?"),
                ],
            }
        )
        ```

    Prompt:

        The agent prompt must have an `agent_scratchpad` key that is a
            `MessagesPlaceholder`. Intermediate agent actions and tool output
            messages will be passed in here.

        Here's an example:

        ```python
        from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

        prompt = ChatPromptTemplate.from_messages(
            [
                ("system", "You are a helpful assistant"),
                MessagesPlaceholder("chat_history", optional=True),
                ("human", "{input}"),
                MessagesPlaceholder("agent_scratchpad"),
            ]
        )
        ```
    Úagent_scratchpadz#Prompt missing required variables: c                 ó2   •— g | ]}t          |‰¬ ¦  «        ‘ŒS ))r   r	   )Ú.0Útoolr   s     €úh/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_classic/agents/openai_tools/base.pyú
<listcomp>z-create_openai_tools_agent.<locals>.<listcomp>e   s'   ø€ ÐMÐMÐM¸tÕ% d°6Ð:Ñ:Ô:ÐMÐMÐMó    )r   c                 ó,   — t          | d         ¦  «        S )NÚintermediate_stepsr   )Úxs    r   ú<lambda>z+create_openai_tools_agent.<locals>.<lambda>j   s   € Õ'EØÐ&Ô'ñ(ô (€ r   )r   )	Ú
differenceÚinput_variablesÚlistÚpartial_variablesÚ
ValueErrorÚbindr   Úassignr   )r   r   r   r   Úmissing_varsÚmsgÚllm_with_toolss      `   r   Úcreate_openai_tools_agentr)      sÐ   ø€ ðX 'Ð'×2Ò2ØÔ¥ fÔ&>Ñ!?Ô!?Ñ?ñô €Lð ð ØB°LÐBÐBˆÝ˜‰oŒoÐà—X’XØMÐMÐMÐMÀuÐMÑMÔMð ñ ô €Nõ
 	Ô"ðð ð	
ñ 	
ô 	
ð
 ñ	ð ñ	õ 'Ñ
(Ô
(ñ	)ð	r   )N)Úcollections.abcr   Úlangchain_core.language_modelsr   Úlangchain_core.prompts.chatr   Úlangchain_core.runnablesr   r   Úlangchain_core.toolsr   Ú%langchain_core.utils.function_callingr
   Ú7langchain_classic.agents.format_scratchpad.openai_toolsr   Ú4langchain_classic.agents.output_parsers.openai_toolsr   Úboolr)   © r   r   ú<module>r4      s  ðØ $Ð $Ð $Ð $Ð $Ð $à <Ð <Ð <Ð <Ð <Ð <Ø :Ð :Ð :Ð :Ð :Ð :Ø BÐ BÐ BÐ BÐ BÐ BÐ BÐ BØ )Ð )Ð )Ð )Ð )Ð )Ø HÐ HÐ HÐ HÐ HÐ Hðð ð ð ð ð ðð ð ð ð ð ð ð	`ð `Ø	ð`à�HÔð`ð ð`ð �4‰Kð	`ð
 ð`ð `ð `ð `ð `ð `r   