Start by defining the tools your agent is going to have access to.
Copy
from langchain.tools import tool@tooldef buy_ticket(destination: str): """Use this to buy a ticket""" return "Bought ticket number 270924"@tooldef get_departure(ticket_number: str): """Use this to fetch the departure time of a train""" return "8:25 AM"
Set up your agent and agent executor using Langchain.
Copy
from langchain import hubfrom langchain.agents import AgentExecutor, create_openai_tools_agentprompt = hub.pull("hwchase17/openai-tools-agent")agent = create_openai_tools_agent(model, tools, prompt)agent_executor = AgentExecutor(agent=agent, tools=tools)input = "Can you buy me a ticket to madrid?"# Using with chat historyagent_executor.invoke( { "input": input, })