Challenge - 5 Problems
OpenAI Functions Agent Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this LangChain OpenAI functions agent call?
Given the following code snippet using LangChain's OpenAI functions agent, what will be the printed output?
LangChain
from langchain.agents import create_openai_functions_agent from langchain.chat_models import ChatOpenAI def greet(name: str) -> str: return f"Hello, {name}!" llm = ChatOpenAI(temperature=0) agent = create_openai_functions_agent(llm, [greet]) response = agent.invoke({'name': 'Alice'}) print(response)
Attempts:
2 left
💡 Hint
Think about how the function greet is called with the argument 'name' from the input dictionary.
✗ Incorrect
The agent calls the greet function with the argument 'name' set to 'Alice', so it returns 'Hello, Alice!'.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a function for OpenAI functions agent in LangChain?
You want to define a function to be used by LangChain's OpenAI functions agent. Which of the following function definitions is syntactically correct and compatible?
Attempts:
2 left
💡 Hint
Check for proper indentation, type annotations, and function syntax.
✗ Incorrect
Option A is correctly indented, has proper type annotations, and returns the sum as an int. Option A lacks indentation. Option A returns None because it prints instead of returning. Option A misses a colon after the function signature.
❓ state_output
advanced2:30remaining
What is the value of 'result' after invoking the agent with nested function calls?
Consider this code using LangChain's OpenAI functions agent with two functions. What is the value of 'result' after calling agent.invoke({'x': 3, 'y': 4})?
LangChain
from langchain.agents import create_openai_functions_agent from langchain.chat_models import ChatOpenAI def multiply(a: int, b: int) -> int: return a * b def add_and_multiply(x: int, y: int) -> int: sum_val = x + y return multiply(sum_val, 2) llm = ChatOpenAI(temperature=0) agent = create_openai_functions_agent(llm, [add_and_multiply, multiply]) result = agent.invoke({'x': 3, 'y': 4})
Attempts:
2 left
💡 Hint
Trace the calls: add_and_multiply adds x and y, then calls multiply with sum_val and 2.
✗ Incorrect
add_and_multiply(3,4) computes sum_val=7, then calls multiply(7,2) which returns 14. So result is 14.
🔧 Debug
advanced2:00remaining
Which option causes a runtime error when invoking the OpenAI functions agent?
Given these function definitions for an OpenAI functions agent, which option will cause a runtime error when calling agent.invoke({'name': 'Bob'})?
LangChain
from langchain.agents import create_openai_functions_agent from langchain.chat_models import ChatOpenAI def say_hello(name: str) -> str: return f"Hello, {name}!" def say_goodbye() -> str: return "Goodbye!" llm = ChatOpenAI(temperature=0) agent = create_openai_functions_agent(llm, [say_hello, say_goodbye])
Attempts:
2 left
💡 Hint
Check which function requires arguments and what happens if they are missing.
✗ Incorrect
Option A calls agent.invoke with an empty dict, so say_hello(name) is called without 'name', causing a TypeError.
🧠 Conceptual
expert2:30remaining
Which statement best describes how LangChain's OpenAI functions agent handles function calls?
Select the most accurate description of how LangChain's OpenAI functions agent processes function calls when given multiple functions.
Attempts:
2 left
💡 Hint
Think about how the agent uses the language model to route calls.
✗ Incorrect
LangChain's OpenAI functions agent uses the language model to interpret input and decide which function to call with appropriate arguments automatically.