
    3fi&                         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y	)    )Sequence)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.
        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: )r   )r   c                     t        | d         S )Nintermediate_stepsr
   )xs    h/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/agents/openai_tools/base.py<lambda>z+create_openai_tools_agent.<locals>.<lambda>j   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    X ''22f&>&>!??L 3L>BoXXGLMt%d6:M  N
 	""	

 	 	 '
(	)	 Ns   B)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>r0      sh    $ < : B ) H 	`	`H` ` 4K	`
 `r   