Challenge - 5 Problems
LangChain Custom 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 custom LangChain agent logic?
Consider this LangChain custom agent code snippet. What will be printed when the agent runs the input 'Hello'?
LangChain
from langchain.agents import AgentExecutor, Tool from langchain.schema import AgentAction, AgentFinish class CustomAgent: def plan(self, intermediate_steps, **kwargs): if len(intermediate_steps): return self.finish(intermediate_steps, **kwargs) return AgentAction(tool="echo", tool_input=kwargs.get("input", ""), log="Echoing input") def finish(self, intermediate_steps, **kwargs): print("Done") return AgentFinish(return_values={"output": "Done"}, log="Finished") class EchoTool: def run(self, input_text): print(f"Echo: {input_text}") return input_text agent = CustomAgent() tool = Tool(name="echo", func=EchoTool().run, description="Echoes input") executor = AgentExecutor(agent=agent, tools=[tool]) executor.run("Hello")
Attempts:
2 left
💡 Hint
Look at what the EchoTool prints and what the agent returns as output.
✗ Incorrect
The EchoTool prints 'Echo: Hello' to the console and returns the input. The agent finishes with output 'Done'. So the printed output includes both lines.
❓ state_output
intermediate2:00remaining
What is the final output value of this LangChain custom agent?
Given this custom agent logic, what is the final output returned by the agent executor?
LangChain
from langchain.agents import AgentExecutor, Tool from langchain.schema import AgentAction, AgentFinish class IncrementAgent: def __init__(self): self.counter = 0 def plan(self, intermediate_steps, **kwargs): self.counter += 1 if self.counter < 3: return AgentAction(tool="increment", tool_input=self.counter, log=f"Increment to {self.counter}") else: return AgentFinish(return_values={"output": self.counter}, log="Done") class IncrementTool: def run(self, input_num): return input_num + 1 agent = IncrementAgent() tool = Tool(name="increment", func=IncrementTool().run, description="Increments number") executor = AgentExecutor(agent=agent, tools=[tool]) result = executor.run(0)
Attempts:
2 left
💡 Hint
Count how many times the agent plans and what it returns at finish.
✗ Incorrect
The agent increments counter each plan call. It plans twice with counter 1 and 2, then finishes at 3. The final output is 3.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in this LangChain custom agent code?
Identify which code snippet will cause a syntax error when defining a custom agent in LangChain.
Attempts:
2 left
💡 Hint
Check the class definition syntax carefully.
✗ Incorrect
Option A is missing the colon ':' after the class name, causing a syntax error.
🔧 Debug
advanced2:00remaining
Which option will cause a runtime error when running this LangChain custom agent?
Given this custom agent and tool setup, which option will cause a runtime error when the agent executor runs?
LangChain
from langchain.agents import AgentExecutor, Tool from langchain.schema import AgentAction, AgentFinish class FaultyAgent: def plan(self, intermediate_steps, **kwargs): return AgentAction(tool="missing_tool", tool_input="test", log="Trying missing tool") agent = FaultyAgent() tool = Tool(name="existing_tool", func=lambda x: x, description="A working tool") executor = AgentExecutor(agent=agent, tools=[tool]) executor.run("input")
Attempts:
2 left
💡 Hint
Check if the tool name used by the agent matches any tool in the executor.
✗ Incorrect
The agent tries to use a tool named 'missing_tool' which is not in the tools list, causing a runtime error.
🧠 Conceptual
expert2:00remaining
How does custom agent logic affect LangChain's decision-making process?
Which statement best describes the role of custom agent logic in LangChain's agent execution?
Attempts:
2 left
💡 Hint
Think about what planning and finishing methods control in an agent.
✗ Incorrect
Custom agent logic controls the agent's planning and finishing steps, deciding which tools to use and when to stop.