Performance: OpenAI functions agent
This concept affects the responsiveness and latency of AI-driven interactions by managing how function calls are integrated and executed within the agent workflow.
Jump into concepts and practice - no test required
agent = OpenAIFunctionsAgent(llm=llm, functions=selected_functions, verbose=True) response = await agent.arun(user_input) # Functions are filtered and loaded asynchronously only when needed
agent = OpenAIFunctionsAgent(llm=llm, functions=all_functions, verbose=True) response = agent.run(user_input) # All functions loaded and checked on every call synchronously
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous function calls on every input | Minimal | 0 | Low | [X] Bad |
| Asynchronous selective function calls | Minimal | 0 | Low | [OK] Good |
OpenAI functions agent in Langchain?from langchain.agents import OpenAIFunctionsAgent
model = OpenAI()
functions = [get_weather, get_news]
agent = OpenAIFunctionsAgent(llm=model, tools=functions)
response = agent.invoke({'input': 'What is the weather today?'})
print(response)print(response) most likely output?model = OpenAI()
functions = [get_time]
agent = OpenAIFunctionsAgent(functions, model)
response = agent.invoke({'input': 'What time is it?'})get_weather or get_news functions based on input. Which approach correctly sets up the OpenAI functions agent to handle this?