Ë
    ´Œj;  ã                   ó    — 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 d d	lmZ 	 ddedee   dedee   de	f
d„Zy
)é    )ÚSequence)ÚOptional)ÚBaseLanguageModel)ÚChatPromptTemplate)ÚRunnableÚRunnablePassthrough)ÚBaseTool)Úconvert_to_openai_tool©Úformat_to_openai_tool_messages)ÚOpenAIToolsAgentOutputParserNÚllmÚtoolsÚpromptÚstrictÚreturnc           	      ó:  — dhj                  |j                  t        |j                  «      z   «      }|rd|› �}t	        |«      ‚| j                  |D �cg c]  }t        ||¬«      ‘Œ c}¬«      }t        j                  d„ ¬«      |z  |z  t        «       z  S c c}w )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.

    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:

        .. code-block:: python

            from langchain import hub
            from langchain_community.chat_models import ChatOpenAI
            from langchain.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:

        .. code-block:: 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: )r   )r   c                 ó   — t        | d   «      S )NÚintermediate_stepsr   )Úxs    úl/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain/agents/openai_tools/base.pyÚ<lambda>z+create_openai_tools_agent.<locals>.<lambda>e   s   € Ô'EØÐ&Ñ'ô(ó    )r   )
Ú
differenceÚinput_variablesÚlistÚpartial_variablesÚ
ValueErrorÚbindr
   r   Úassignr   )r   r   r   r   Úmissing_varsÚmsgÚtoolÚllm_with_toolss           r   Úcreate_openai_tools_agentr&      sº   € ðP 'Ð'×2Ñ2Ø×Ñ¤ f×&>Ñ&>Ó!?Ñ?ó€Lñ Ø3°L°>ÐBˆÜ˜‹oÐà—X‘XÙGLÓMÁu¸tÔ% d°6Ö:ÀuÑMð ó €Nô
 	×"Ñ"ñô	
ð
 ñ	ð ñ	ô 'Ó
(ñ	)ð	ùò Ns   ÁB)N)Úcollections.abcr   Útypingr   Úlangchain_core.language_modelsr   Úlangchain_core.prompts.chatr   Úlangchain_core.runnablesr   r   Úlangchain_core.toolsr	   Ú%langchain_core.utils.function_callingr
   Ú/langchain.agents.format_scratchpad.openai_toolsr   Ú,langchain.agents.output_parsers.openai_toolsr   Úboolr&   © r   r   Ú<module>r2      sl   ðÝ $Ý å <Ý :ß BÝ )Ý Hõõ Vð "ñ	\Ø	ð\à�HÑð\ð ð\ð �T‰Nð	\ð
 ô\r   