from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_openai import ChatOpenAI
# Setup
llm = ChatOpenAI(temperature=0)
toolkit = FMPDataToolkit(
query="Stock analysis",
num_results=3,
)
tools = toolkit.get_tools()
# Create agent
prompt = "You are a helpful assistant. Answer the user's questions based on the provided context."
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
)
# Run query
# fmt: off
response = agent_executor.invoke({"input": "What's the PE ratio of Microsoft?"})
# fmt: on