0
0
LangChainframework~20 mins

Structured chat agent in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Structured Chat Agent 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 LangChain structured chat agent code?
Consider this code snippet using LangChain's StructuredChatAgent. What will be printed when the agent runs?
LangChain
from langchain.schema import SystemMessage, HumanMessage
from langchain.chat_models import ChatOpenAI
from langchain.agents import StructuredChatAgent, AgentExecutor

system_message = SystemMessage(content="You are a helpful assistant.")

chat = ChatOpenAI(temperature=0)

agent = StructuredChatAgent.from_llm_and_tools(
    llm=chat,
    tools=[],
    system_message=system_message
)

executor = AgentExecutor(agent=agent, tools=[])

response = executor.run("Hello, who won the world series in 2020?")
print(response)
AThe code raises a RuntimeError due to missing tool implementations.
BThe agent returns a direct answer about the 2020 World Series winner.
CThe code raises a TypeError because tools list is empty.
DThe agent returns an empty string because no tools are provided.
Attempts:
2 left
💡 Hint
Think about how StructuredChatAgent uses the LLM and tools. If no tools are needed, it can still answer.
📝 Syntax
intermediate
2:00remaining
Which option correctly creates a StructuredChatAgent with tools?
You want to create a StructuredChatAgent with a tool named 'calculator'. Which code snippet is syntactically correct?
LangChain
from langchain.agents import StructuredChatAgent
from langchain.chat_models import ChatOpenAI

calculator_tool = ...  # assume this is a valid tool

# Options below:
Aagent = StructuredChatAgent.from_llm_and_tools(llm=ChatOpenAI(), tools=[calculator_tool])
Bagent = StructuredChatAgent(llm=ChatOpenAI(), tools=calculator_tool)
Cagent = StructuredChatAgent.from_llm_and_tools(llm=ChatOpenAI, tools=[calculator_tool])
Dagent = StructuredChatAgent.from_llm_and_tools(llm=ChatOpenAI(), tool=calculator_tool)
Attempts:
2 left
💡 Hint
Check the method name and parameter names carefully.
🔧 Debug
advanced
2:00remaining
Why does this StructuredChatAgent code raise a ValueError?
This code raises a ValueError: 'tools must be a list of Tool instances'. What is the cause?
LangChain
from langchain.agents import StructuredChatAgent
from langchain.chat_models import ChatOpenAI

calculator_tool = 'calculator'

agent = StructuredChatAgent.from_llm_and_tools(llm=ChatOpenAI(), tools=calculator_tool)
AThe tools argument is a string, not a list of Tool objects.
BThe llm argument is not instantiated correctly.
CThe StructuredChatAgent requires a system_message parameter.
DThe calculator_tool variable is not imported from langchain.tools.
Attempts:
2 left
💡 Hint
Check the type of the tools argument passed.
state_output
advanced
2:00remaining
What is the value of 'agent.tools' after this code runs?
Given the following code, what is the content of the agent's tools attribute?
LangChain
from langchain.agents import StructuredChatAgent
from langchain.chat_models import ChatOpenAI
from langchain.tools import Tool

def dummy_func():
    return "dummy"

dummy_tool = Tool(name="dummy", func=dummy_func, description="A dummy tool")

agent = StructuredChatAgent.from_llm_and_tools(llm=ChatOpenAI(), tools=[dummy_tool])

result = agent.tools
ANone
B[]
C[Tool(name='dummy', func=<function dummy_func>, description='A dummy tool')]
D["dummy"]
Attempts:
2 left
💡 Hint
The tools list passed to the agent is stored in agent.tools.
🧠 Conceptual
expert
2:00remaining
Which statement best describes the role of StructuredChatAgent in LangChain?
Choose the best description of what StructuredChatAgent does in LangChain.
AIt is a deprecated class replaced by AgentExecutor in LangChain.
BIt is a low-level API for directly calling OpenAI's chat completions without tool integration.
CIt only handles static prompts without any dynamic tool usage or user input.
DIt manages conversation flow by combining an LLM with external tools using a structured prompt format.
Attempts:
2 left
💡 Hint
Think about how StructuredChatAgent connects language models and tools.