Challenge - 5 Problems
AgentExecutor Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this AgentExecutor run?
Given this LangChain AgentExecutor setup, what will be the printed output?
LangChain
from langchain.agents import initialize_agent, AgentType from langchain.llms import OpenAI llm = OpenAI(temperature=0) agent = initialize_agent([], llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) result = agent.run("What is 2 plus 2?") print(result)
Attempts:
2 left
💡 Hint
Think about what the agent does when no tools are provided but the LLM can answer simple questions.
✗ Incorrect
The AgentExecutor with ZERO_SHOT_REACT_DESCRIPTION and no tools still uses the LLM to answer direct questions. So it returns '4' as the answer to 'What is 2 plus 2?'.
📝 Syntax
intermediate2:00remaining
Which option correctly initializes AgentExecutor with tools?
Select the code snippet that correctly creates an AgentExecutor with a tool list and an OpenAI LLM.
Attempts:
2 left
💡 Hint
Check the order of arguments and the use of AgentType in initialize_agent.
✗ Incorrect
Option D correctly imports initialize_agent and AgentType, passes tools first, then llm, and specifies the agent type and verbosity. Other options have wrong argument orders or missing parameters.
🔧 Debug
advanced2:00remaining
Why does this AgentExecutor raise a TypeError?
Consider this code snippet:
from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI
llm = OpenAI(temperature=0)
agent = initialize_agent([], llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
result = agent.run(12345)
print(result)
Why does it raise a TypeError?
Attempts:
2 left
💡 Hint
Check the type expected by the run method of AgentExecutor.
✗ Incorrect
AgentExecutor expects a string input to process. Passing an integer causes a TypeError because the LLM cannot process non-string inputs.
❓ state_output
advanced2:00remaining
What is the value of agent.tools after initialization?
Given this code:
from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI
class DummyTool:
def run(self, input):
return "done"
llm = OpenAI(temperature=0)
tools = [DummyTool()]
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=False)
What is the value of agent.tools?
Attempts:
2 left
💡 Hint
Think about what initialize_agent does with the tools list.
✗ Incorrect
The agent stores the list of tool objects passed during initialization. So agent.tools contains the DummyTool instance.
🧠 Conceptual
expert2:00remaining
Which statement best describes AgentExecutor's role in LangChain?
Choose the most accurate description of what AgentExecutor does in LangChain.
Attempts:
2 left
💡 Hint
Think about how LangChain agents combine language models and tools.
✗ Incorrect
AgentExecutor coordinates the LLM and tools, deciding when to call tools based on the query to provide intelligent answers.