Bird
Raised Fist0
LangChainframework~20 mins

AgentExecutor setup and configuration in LangChain - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
AgentExecutor Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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)
A"4"
B"What is 2 plus 2?"
CSyntaxError due to missing tools
DRuntimeError: No tools provided
Attempts:
2 left
💡 Hint
Think about what the agent does when no tools are provided but the LLM can answer simple questions.
📝 Syntax
intermediate
2: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.
A
from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
tools = [MyTool()]
agent = initialize_agent(tools, llm, verbose=True)
B
from langchain.agents import AgentExecutor
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
agent = AgentExecutor(llm=llm, tools=[MyTool()])
C
from langchain.agents import initialize_agent
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
tools = [MyTool()]
agent = initialize_agent(llm, tools, verbose=True)
D
from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
tools = [MyTool()]
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
Attempts:
2 left
💡 Hint
Check the order of arguments and the use of AgentType in initialize_agent.
🔧 Debug
advanced
2: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?
ABecause OpenAI LLM does not accept numeric inputs
BBecause the tools list is empty, causing a TypeError
CBecause the input to agent.run must be a string, not an integer
DBecause verbose=True causes a conflict with integer inputs
Attempts:
2 left
💡 Hint
Check the type expected by the run method of AgentExecutor.
state_output
advanced
2: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?
A[<__main__.DummyTool object at memory_address>]
B[]
CNone
D["done"]
Attempts:
2 left
💡 Hint
Think about what initialize_agent does with the tools list.
🧠 Conceptual
expert
2:00remaining
Which statement best describes AgentExecutor's role in LangChain?
Choose the most accurate description of what AgentExecutor does in LangChain.
AAgentExecutor is a simple wrapper that only runs an LLM without any tool integration.
BAgentExecutor manages the interaction between an LLM and a set of tools to answer complex queries by deciding when and how to use each tool.
CAgentExecutor is responsible for training the LLM models used in LangChain.
DAgentExecutor only handles input validation and does not execute any logic.
Attempts:
2 left
💡 Hint
Think about how LangChain agents combine language models and tools.

Practice

(1/5)
1. What is the primary purpose of AgentExecutor in Langchain?
easy
A. To connect language models with tools to automate tasks
B. To train new language models from scratch
C. To store data in a database
D. To create user interfaces for chatbots

Solution

  1. Step 1: Understand AgentExecutor role

    AgentExecutor acts as a bridge between language models and external tools to perform tasks automatically.
  2. Step 2: Compare options with this role

    Only To connect language models with tools to automate tasks describes connecting models and tools to automate tasks, which matches AgentExecutor's purpose.
  3. Final Answer:

    To connect language models with tools to automate tasks -> Option A
  4. Quick Check:

    AgentExecutor = Connect models and tools [OK]
Hint: AgentExecutor links models and tools for automation [OK]
Common Mistakes:
  • Confusing AgentExecutor with model training
  • Thinking it manages databases
  • Assuming it builds user interfaces
2. Which of the following is the correct way to initialize an agent with tools in Langchain?
easy
A. agent = initialize_agent(agent='zero-shot-react-description', tools, llm)
B. agent = initialize_agent(tools, llm, agent='zero-shot-react-description', verbose=True)
C. agent = initialize_agent(tools, llm, verbose=False, agent='react-zero-shot')
D. agent = initialize_agent(llm, tools, agent='zero-shot-react-description')

Solution

  1. Step 1: Recall initialize_agent parameter order

    The correct order is llm first, then tools, followed by named parameters like agent type.
  2. Step 2: Check each option's order and parameters

    agent = initialize_agent(llm, tools, agent='zero-shot-react-description') correctly uses llm, tools, agent type string. Others have wrong order or wrong agent name.
  3. Final Answer:

    agent = initialize_agent(llm, tools, agent='zero-shot-react-description') -> Option D
  4. Quick Check:

    initialize_agent(llm, tools, ...) correct order [OK]
Hint: Remember: llm first, then tools in initialize_agent [OK]
Common Mistakes:
  • Swapping llm and tools arguments
  • Using incorrect agent type strings
  • Omitting agent type parameter
3. Given this code snippet, what will be printed?
from langchain.agents import initialize_agent
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
tools = []
agent = initialize_agent(llm, tools, agent='zero-shot-react-description', verbose=False)
response = agent.run('What is the capital of France?')
print(response)
medium
A. The agent returns an empty string
B. Error: No tools available
C. Paris
D. The agent returns the question text

Solution

  1. Step 1: Understand agent with empty tools

    Even with no tools, the agent uses the language model to answer questions directly.
  2. Step 2: Analyze the question and model behavior

    The question is simple and factual; the OpenAI model with temperature=0 returns a deterministic answer "Paris".
  3. Final Answer:

    Paris -> Option C
  4. Quick Check:

    Agent with no tools uses LLM answer [OK]
Hint: Agent uses LLM answer if no tools provided [OK]
Common Mistakes:
  • Assuming error if tools list is empty
  • Expecting empty or repeated question output
  • Confusing verbose with output content
4. Identify the error in this agent initialization code:
from langchain.agents import initialize_agent
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
tools = [Tool(name='Search', func=search_function)]
agent = initialize_agent(llm, tools, agent='zero-shot-react-description', verbose=True)
medium
A. The Tool class is not imported
B. The order of arguments in initialize_agent is incorrect
C. temperature parameter is invalid for OpenAI
D. verbose parameter cannot be True

Solution

  1. Step 1: Check imports for Tool usage

    The code uses Tool but does not import it from langchain.tools.
  2. Step 2: Verify other parameters

    Argument order llm then tools is correct; temperature=0 is valid; verbose=True is allowed.
  3. Final Answer:

    The Tool class is not imported -> Option A
  4. Quick Check:

    import Tool from langchain.tools required [OK]
Hint: Import Tool from langchain.tools before using [OK]
Common Mistakes:
  • Misidentifying argument order as error
  • Overlooking missing Tool import
  • Misunderstanding verbose usage
5. You want to create an AgentExecutor that uses two tools: a calculator and a search tool. Which setup correctly configures the agent to use both tools and logs detailed steps?
hard
A. tools = [CalculatorTool(), SearchTool()] agent = initialize_agent(tools, llm, agent='zero-shot-react-description', verbose=True)
B. tools = [CalculatorTool(), SearchTool()] agent = initialize_agent(llm, tools, agent='zero-shot-react-description', verbose=True)
C. tools = [CalculatorTool(), SearchTool()] agent = initialize_agent(tools, llm, verbose=False, agent='zero-shot-react-description')
D. tools = [CalculatorTool(), SearchTool()] agent = initialize_agent(tools, llm, agent='react-zero-shot', verbose=True)

Solution

  1. Step 1: Confirm tools list and order

    Both CalculatorTool and SearchTool are included in a list assigned to tools, which is correct.
  2. Step 2: Check initialize_agent parameters

    tools = [CalculatorTool(), SearchTool()] agent = initialize_agent(llm, tools, agent='zero-shot-react-description', verbose=True) uses correct order (llm, tools), correct agent type string, and verbose=True for detailed logs.
  3. Final Answer:

    tools = [CalculatorTool(), SearchTool()] agent = initialize_agent(llm, tools, agent='zero-shot-react-description', verbose=True) -> Option B
  4. Quick Check:

    Correct tools, order, agent type, and verbose [OK]
Hint: Use llm first then tools list, verbose=True for detailed logs [OK]
Common Mistakes:
  • Swapping llm and tools arguments
  • Using wrong agent type string
  • Setting verbose to False when detailed logs needed