Conversation setup
Now that you have a custom tool to help you calculate the length of a roof, you can set your agent's outputs to respond to your entered query. By slightly modifying your print statements, you can directly compare your query and your agent's response to ensure accuracy. Your tools
and query
have already been set up and your model
is ready to use.
This exercise is part of the course
Designing Agentic Systems with LangChain
Exercise instructions
- Initialize the
create_react_agent
function creating an object calledapp
, passing in the required arguments. - Invoke the agent
app
, passing in yourquery
, before storing and printing the agent'sresponse
. - Define the
"user_input"
asquery
and the"agent_output"
as the last item extracted from"messages"
inresponse
before both are printed.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
tools = [hypotenuse_length]
query = "What is the value of the hypotenuse for a triangle with sides 3 and 5?"
# Create the ReAct agent
app = ____(____, ____)
# Invoke the agent with a query and store the messages
response = ____.____({"messages": [("human", ____)]})
# Define and print the input and output messages
print({
"____": ____,
"____": ____["____"][____].____
})