0
0
LangChainframework~10 mins

Structured chat agent in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the StructuredChatAgent class from langchain.agents.

LangChain
from langchain.agents import [1]
Drag options to blanks, or click blank then click option'
AConversationAgent
BChatAgent
CAgentExecutor
DStructuredChatAgent
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a wrong class name like ChatAgent or AgentExecutor.
Forgetting to import from langchain.agents.
2fill in blank
medium

Complete the code to create a StructuredChatAgent instance using an llm and a prompt.

LangChain
agent = StructuredChatAgent.from_llm([1], prompt=prompt)
Drag options to blanks, or click blank then click option'
Amodel
Bllm
Cclient
Dchatbot
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a variable named 'model' or 'client' which may not exist.
Passing the prompt instead of the llm.
3fill in blank
hard

Fix the error in the code to run the agent with input 'Hello'.

LangChain
response = agent.run([1])
Drag options to blanks, or click blank then click option'
A'Hello'
BHello
Cagent_input
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Passing Hello without quotes causes a NameError.
Passing variables that are undefined.
4fill in blank
hard

Fill both blanks to create a prompt template and initialize the agent with it.

LangChain
from langchain.prompts import [1]
prompt = [2].from_template(template=template_str)
Drag options to blanks, or click blank then click option'
AChatPromptTemplate
BPromptTemplate
CStructuredPromptTemplate
DAgentPromptTemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using PromptTemplate instead of ChatPromptTemplate causes incompatibility.
Importing one class but instantiating another.
5fill in blank
hard

Fill all three blanks to create a StructuredChatAgent, wrap it in an AgentExecutor, and run it with input 'Hi'.

LangChain
agent = StructuredChatAgent.from_llm([1], prompt=prompt)
executor = AgentExecutor.from_agent_and_tools(agent, [2])
result = executor.run([3])
Drag options to blanks, or click blank then click option'
Allm
Btools
C'Hi'
Dprompt
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the prompt instead of llm in the first blank.
Passing prompt instead of tools in the second blank.
Passing input without quotes in the third blank.