Challenge - 5 Problems
ReAct Agent 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 ReAct agent snippet?
Consider this simplified ReAct agent code using LangChain. What will be printed when the agent runs?
LangChain
from langchain.agents import ReActAgent from langchain.schema import AgentAction, AgentFinish class SimpleReActAgent(ReActAgent): def plan(self, intermediate_steps, **kwargs): if not intermediate_steps: return AgentAction(tool='search', tool_input='Python', log='Searching for Python') else: return AgentFinish(return_values={'output': 'Found info on Python'}, log='Done') agent = SimpleReActAgent() step1 = agent.plan([]) step2 = agent.plan([step1]) print(step1.log) print(step2.log)
Attempts:
2 left
💡 Hint
Think about what the agent does when there are no intermediate steps versus when there are some.
✗ Incorrect
The agent first plans with no intermediate steps, so it returns an AgentAction with log 'Searching for Python'. On the second call, since there is an intermediate step, it returns AgentFinish with log 'Done'.
❓ state_output
intermediate2:00remaining
What is the value of the agent's memory after these steps?
Given this ReAct agent code snippet, what will be the content of the agent's memory after executing the two steps?
LangChain
from langchain.agents import ReActAgent from langchain.schema import AgentAction, AgentFinish class MemoryReActAgent(ReActAgent): def __init__(self): super().__init__() self.memory = [] def plan(self, intermediate_steps, **kwargs): if not intermediate_steps: self.memory.append('start') return AgentAction(tool='search', tool_input='LangChain', log='Starting search') else: self.memory.append('finish') return AgentFinish(return_values={'output': 'Result found'}, log='Finished') agent = MemoryReActAgent() agent.plan([]) agent.plan([AgentAction(tool='search', tool_input='LangChain', log='Starting search')]) memory_content = agent.memory
Attempts:
2 left
💡 Hint
Look at when the memory list is appended to in the plan method.
✗ Incorrect
The memory list appends 'start' on the first plan call (no intermediate steps) and 'finish' on the second call (with intermediate steps).
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in this ReAct agent plan method?
Identify which plan method implementation will cause a syntax error when used in a ReAct agent subclass.
LangChain
def plan(self, intermediate_steps, **kwargs): # method body varies per option
Attempts:
2 left
💡 Hint
Check the syntax of the if statement carefully.
✗ Incorrect
Option A is missing a colon after the if condition, causing a SyntaxError.
🔧 Debug
advanced2:00remaining
Why does this ReAct agent code raise a TypeError?
This ReAct agent subclass code raises a TypeError when calling plan. What is the cause?
LangChain
from langchain.agents import ReActAgent from langchain.schema import AgentAction class FaultyAgent(ReActAgent): def plan(self, intermediate_steps, **kwargs): return AgentAction(tool='search', tool_input=123, log='Searching') agent = FaultyAgent() agent.plan([])
Attempts:
2 left
💡 Hint
Check the types of arguments passed to AgentAction.
✗ Incorrect
AgentAction's tool_input should be a string describing the input to the tool. Passing an integer causes a TypeError.
🧠 Conceptual
expert2:00remaining
Which option best describes the ReAct agent's reasoning process?
In LangChain's ReAct agent implementation, what is the core idea behind the agent's reasoning and acting cycle?
Attempts:
2 left
💡 Hint
Consider how ReAct combines reasoning and actions iteratively.
✗ Incorrect
ReAct agents interleave reasoning steps with actions, using observations from tools to inform next reasoning steps, enabling dynamic problem solving.