Memory is needed to enable conversation.First, let's load the language model we're going to use to control the agent.from langchain.chat_models import ChatOpenAIllm = ChatOpenAI(temperature=0)Next, let's define some tools to use.
Let's write a really simple Python function to calculate the length of a word that is passed in.from langchain.agents import tool@tooldef get_word_length(word: str) -> int:    """Returns the length of a word."""    return len(word)tools = [get_word_length]Now let us create the prompt.
Because OpenAI Function Calling is finetuned for tool usage, we hardly need any instructions on how to reason, or how to output format.
We will just have two input variables: input (for the user question) and agent_scratchpad (for any previous steps taken)from langchain.prompts import ChatPromptTemplate, MessagesPlaceholderprompt = ChatPromptTemplate.from_messages([    ("system", "You are very powerful assistant, but bad at calculating lengths of words."),    ("user", "{input}"),    MessagesPlaceholder(variable_name="agent_scratchpad"),])How does the agent know what tools it can use?
Those are passed in as a separate argument, so we can bind those as keyword arguments to the LLM.from langchain.tools.render import format_tool_to_openai_functionllm_with_tools = llm.bind(    functions=[format_tool_to_openai_function(t) for t in tools])Putting those pieces together, we can now create the agent.
The core idea of agents is to use an LLM to choose a sequence of actions to take.
The core idea of agents is to use an LLM to choose a sequence of actions to take. ->: Memory is needed to enable conversation.First, let's load the language model we're going to use to control the agent.from langchain.chat_models import ChatOpenAIllm = ChatOpenAI(temperature=0)Next, let's define some tools to use.
Let's write a really simple Python function to calculate the length of a word that is passed in.from langchain.agents import tool@tooldef get_word_length(word: str) -> int:    """Returns the length of a word."""    return len(word)tools = [get_word_length]Now let us create the prompt.
Because OpenAI Function Calling is finetuned for tool usage, we hardly need any instructions on how to reason, or how to output format.
We will just have two input variables: input (for the user question) and agent_scratchpad (for any previous steps taken)from langchain.prompts import ChatPromptTemplate, MessagesPlaceholderprompt = ChatPromptTemplate.from_messages([    ("system", "You are very powerful assistant, but bad at calculating lengths of words."),    ("user", "{input}"),    MessagesPlaceholder(variable_name="agent_scratchpad"),])How does the agent know what tools it can use?
Those are passed in as a separate argument, so we can bind those as keyword arguments to the LLM.from langchain.tools.render import format_tool_to_openai_functionllm_with_tools = llm.bind(    functions=[format_tool_to_openai_function(t) for t in tools])Putting those pieces together, we can now create the agent.