Challenge - 5 Problems
Structured Chat 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 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)
Attempts:
2 left
💡 Hint
Think about how StructuredChatAgent uses the LLM and tools. If no tools are needed, it can still answer.
✗ Incorrect
The StructuredChatAgent uses the LLM to generate a response. Even with an empty tools list, it can answer questions that don't require external tools. Hence, it returns the answer about the 2020 World Series winner.
📝 Syntax
intermediate2: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:
Attempts:
2 left
💡 Hint
Check the method name and parameter names carefully.
✗ Incorrect
The correct method is from_llm_and_tools, and tools must be a list. llm must be an instance, so ChatOpenAI() is correct. Option A matches all these requirements.
🔧 Debug
advanced2: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)
Attempts:
2 left
💡 Hint
Check the type of the tools argument passed.
✗ Incorrect
The tools argument must be a list of Tool instances. Passing a string causes the ValueError.
❓ state_output
advanced2: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
Attempts:
2 left
💡 Hint
The tools list passed to the agent is stored in agent.tools.
✗ Incorrect
The agent stores the list of Tool instances passed during creation in its tools attribute.
🧠 Conceptual
expert2:00remaining
Which statement best describes the role of StructuredChatAgent in LangChain?
Choose the best description of what StructuredChatAgent does in LangChain.
Attempts:
2 left
💡 Hint
Think about how StructuredChatAgent connects language models and tools.
✗ Incorrect
StructuredChatAgent is designed to combine an LLM with tools in a structured way to manage chat-based agent workflows.