Bird
0
0

Which approach correctly sets up the OpenAI functions agent to handle this?

hard📝 Application Q15 of 15
LangChain - Agents
You want to build a Langchain app that answers user questions by calling either get_weather or get_news functions based on input. Which approach correctly sets up the OpenAI functions agent to handle this?
ACreate two separate agents, one for weather and one for news, and switch manually
BPass both functions in a list to OpenAIFunctionsAgent and let it decide which to call
CUse only get_weather function and ignore get_news for simplicity
DCall functions directly without using an agent
Step-by-Step Solution
Solution:
  1. Step 1: Understand agent's function selection

    The OpenAI functions agent can receive multiple functions and uses AI to pick the right one based on input.
  2. Step 2: Evaluate options for best design

    Passing both functions in a list lets the agent decide automatically, which is the intended use.
  3. Final Answer:

    Pass both functions in a list to OpenAIFunctionsAgent and let it decide which to call -> Option B
  4. Quick Check:

    Agent selects function from list automatically [OK]
Quick Trick: Give all functions to agent; it picks based on input [OK]
Common Mistakes:
MISTAKES
  • Manually switching between agents instead of one agent
  • Ignoring needed functions for simplicity
  • Bypassing agent and losing AI routing benefits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes