0
0
LangChainframework~10 mins

Why agents add autonomy to LLM apps in LangChain - Test Your Understanding

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

Complete the code to create an agent that uses a language model and tools.

LangChain
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
from langchain.tools import Tool

llm = OpenAI(temperature=0)
tools = [Tool(name="Search", func=search_function)]
agent = initialize_agent(tools, llm, agent_type=[1])
Drag options to blanks, or click blank then click option'
A"zero-shot-react-description"
B"simple-agent"
C"chat-agent"
D"tool-agent"
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid or unsupported agent_type string.
Confusing agent_type with tool names.
2fill in blank
medium

Complete the code to add a tool that the agent can use to fetch current weather.

LangChain
def get_weather(location: str) -> str:
    # Imagine this calls a weather API
    return f"Weather in {location} is sunny"

weather_tool = Tool(name="Weather", func=[1], description="Get current weather")
Drag options to blanks, or click blank then click option'
Aweather_api_call
Bfetch_weather
Cget_weather
Dget_temperature
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that is not defined.
Confusing the tool's name with the function name.
3fill in blank
hard

Fix the error in the agent call to run a query with tool usage.

LangChain
response = agent.run(input=[1])
Drag options to blanks, or click blank then click option'
Aquery about weather
B"query about weather"
Cinput_text
Dagent_input
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a bare word without quotes causing a NameError.
Confusing variable names with string literals.
4fill in blank
hard

Fill both blanks to create a tool that calls a calculator function and add it to the tools list.

LangChain
def calculator(query: str) -> str:
    # Simple calculator logic
    return str(eval(query))

calc_tool = Tool(name=[1], func=[2], description="Perform calculations")
tools = [calc_tool]
Drag options to blanks, or click blank then click option'
A"Calculator"
Bcalculator
C"Calc"
Dcalc_function
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name as a string.
Using a name without quotes.
5fill in blank
hard

Fill all three blanks to create an agent that uses both weather and calculator tools with zero-shot reasoning.

LangChain
weather_tool = Tool(name=[1], func=get_weather, description="Get current weather")
calc_tool = Tool(name=[2], func=calculator, description="Perform calculations")
tools = [weather_tool, calc_tool]
agent = initialize_agent(tools, llm, agent_type=[3])
Drag options to blanks, or click blank then click option'
A"Weather"
B"Calculator"
C"zero-shot-react-description"
D"simple-agent"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up tool names or agent types.
Using unsupported agent types.