0
0
LangChainframework~10 mins

Creating tools for agents in LangChain - Interactive Practice

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

Complete the code to import the Tool class from langchain.tools.

LangChain
from langchain.tools import [1]
Drag options to blanks, or click blank then click option'
ATool
BAgent
CChain
DPrompt
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Agent instead of Tool
Using Chain which is unrelated here
Forgetting to import anything
2fill in blank
medium

Complete the code to define a simple tool function that returns a greeting.

LangChain
def greet(name: str) -> str:
    return f"Hello, [1]!"
Drag options to blanks, or click blank then click option'
Ainput
Buser
Cname
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not defined in the function
Using the function name inside the string
3fill in blank
hard

Fix the error in the tool creation by filling the missing argument for the Tool constructor.

LangChain
my_tool = Tool(name="GreetTool", func=greet, description=[1])
Drag options to blanks, or click blank then click option'
A123
Bgreet
CNone
D"A tool that greets users"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function instead of a description string
Passing None or a number instead of a string
4fill in blank
hard

Fill both blanks to create a tool list and initialize an agent with it.

LangChain
tools = [[1]]
agent = initialize_agent(tools=[2], agent_type="zero-shot-react-description")
Drag options to blanks, or click blank then click option'
Amy_tool
B[my_tool]
Ctools
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using [my_tool] for the first blank (creates nested list)
Using my_tool for the second blank (instead of tools)
5fill in blank
hard

Fill all three blanks to define a tool function, create the tool, and add it to the tools list.

LangChain
def [1](query: str) -> str:
    return f"Searching for: {query}"

search_tool = Tool(name="Search", func=[2], description="Searches the web")
tools = [[3]]
Drag options to blanks, or click blank then click option'
Asearch
Csearch_tool
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the function and func argument
Adding the function instead of the tool to the list