0
0
Agentic AIml~10 mins

LangChain agents overview in Agentic AI - Interactive Code Practice

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

Complete the code to create a basic LangChain agent using an LLM.

Agentic AI
from langchain.agents import initialize_agent
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
agent = initialize_agent(llm, tools=[], agent= [1] )
Drag options to blanks, or click blank then click option'
A"toolkit-agent"
B"chat-completion"
C"simple-agent"
D"zero-shot-react-description"
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid or unsupported agent type string.
Passing the agent type without quotes.
2fill in blank
medium

Complete the code to add a tool to the LangChain agent.

Agentic AI
from langchain.agents import Tool

tool = Tool(name="Search", func=lambda x: "Searching..." + x, description="Search tool")
agent = initialize_agent(llm, tools=[[1]], agent="zero-shot-react-description")
Drag options to blanks, or click blank then click option'
Atool
Btools
Csearch_tool
DSearch
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the string name of the tool instead of the Tool object.
Passing an undefined variable.
3fill in blank
hard

Fix the error in the code to run the LangChain agent on an input.

Agentic AI
response = agent.run([1])
print(response)
Drag options to blanks, or click blank then click option'
Ainput("What is the weather today?")
BWhat is the weather today?
C"What is the weather today?"
Dagent("What is the weather today?")
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the question without quotes causing syntax errors.
Using input() function inside run() which is not needed here.
4fill in blank
hard

Fill both blanks to create a custom tool and add it to the agent.

Agentic AI
def custom_func(input_text):
    return f"Processed: {input_text}"

custom_tool = Tool(name=[1], func=[2], description="Custom processing tool")
agent = initialize_agent(llm, tools=[custom_tool], agent="zero-shot-react-description")
Drag options to blanks, or click blank then click option'
A"CustomTool"
Bcustom_func
C"custom_func"
DcustomTool
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function name as a string instead of a function object.
Not quoting the tool name string.
5fill in blank
hard

Fill all three blanks to create an agent that uses multiple tools and runs a query.

Agentic AI
tool1 = Tool(name=[1], func=lambda x: f"Tool1: {x}", description="First tool")
tool2 = Tool(name=[2], func=lambda x: f"Tool2: {x}", description="Second tool")
agent = initialize_agent(llm, tools=[tool1, tool2], agent="zero-shot-react-description")
response = agent.run([3])
print(response)
Drag options to blanks, or click blank then click option'
A"ToolOne"
B"ToolTwo"
C"How do I use these tools?"
D"Tool1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name for both tools causing confusion.
Passing the query without quotes.