Notice that we put this ABOVE the new user input (to follow the conversation flow).from langchain.prompts import MessagesPlaceholderMEMORY_KEY = "chat_history"prompt = ChatPromptTemplate.from_messages([    ("system", "You are very powerful assistant, but bad at calculating lengths of words."),    MessagesPlaceholder(variable_name=MEMORY_KEY),    ("user", "{input}"),    MessagesPlaceholder(variable_name="agent_scratchpad"),])We can then set up a list to track the chat historyfrom langchain.schema.messages import HumanMessage, AIMessagechat_history = []We can then put it all together!agent = {    "input": lambda x: x["input"],    "agent_scratchpad": lambda x: format_to_openai_functions(x['intermediate_steps']),    "chat_history": lambda x: x["chat_history"]} | prompt | llm_with_tools | OpenAIFunctionsAgentOutputParser()agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)When running, we now need to track the inputs and outputs as chat historyinput1 = "how many letters in the word educa?"result = agent_executor.invoke({"input": input1, "chat_history": chat_history})chat_history.append(HumanMessage(content=input1))chat_history.append(AIMessage(content=result['output']))agent_executor.invoke({"input": "is that a real word?", "chat_history": chat_history})Next Steps‚ÄãAwesome! You've now run your first end-to-end agent.
To dive deeper, you can:Check out all the different agent types supportedLearn all the controls for AgentExecutorSee a full list of all the off-the-shelf toolkits we provideExplore all the individual tools supportedPreviousMultiple Memory classesNextAgent TypesAgentToolsToolkitsAgentExecutorOther types of agent runtimesGet startedSet up the agentNext StepsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
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. ->: Notice that we put this ABOVE the new user input (to follow the conversation flow).from langchain.prompts import MessagesPlaceholderMEMORY_KEY = "chat_history"prompt = ChatPromptTemplate.from_messages([    ("system", "You are very powerful assistant, but bad at calculating lengths of words."),    MessagesPlaceholder(variable_name=MEMORY_KEY),    ("user", "{input}"),    MessagesPlaceholder(variable_name="agent_scratchpad"),])We can then set up a list to track the chat historyfrom langchain.schema.messages import HumanMessage, AIMessagechat_history = []We can then put it all together!agent = {    "input": lambda x: x["input"],    "agent_scratchpad": lambda x: format_to_openai_functions(x['intermediate_steps']),    "chat_history": lambda x: x["chat_history"]} | prompt | llm_with_tools | OpenAIFunctionsAgentOutputParser()agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)When running, we now need to track the inputs and outputs as chat historyinput1 = "how many letters in the word educa?"result = agent_executor.invoke({"input": input1, "chat_history": chat_history})chat_history.append(HumanMessage(content=input1))chat_history.append(AIMessage(content=result['output']))agent_executor.invoke({"input": "is that a real word?", "chat_history": chat_history})Next Steps‚ÄãAwesome! You've now run your first end-to-end agent.
To dive deeper, you can:Check out all the different agent types supportedLearn all the controls for AgentExecutorSee a full list of all the off-the-shelf toolkits we provideExplore all the individual tools supportedPreviousMultiple Memory classesNextAgent TypesAgentToolsToolkitsAgentExecutorOther types of agent runtimesGet startedSet up the agentNext StepsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.