Get startedGet started for free

Integrating custom tools and queries

You now have a custom math tool for calculating roof length. You can integrate it with an agentic workflow by creating a variable called query that accepts the user's natural language question as a string. Your tool is already loaded as hypotenuse_length, as well as your model.

This exercise is part of the course

Designing Agentic Systems with LangChain

View Course

Exercise instructions

  • Create a list variable called tools and include your tool, hypotenuse_length, inside the list.
  • Create a variable called query that accepts questions as natural language strings.
  • Use the create_react_agent() function to create the agent, passing in the model and tools.
  • Invoke the agent app, passing in your query labeled "human", before storing and printing the agent's response.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create a list variable and pass in your tool
____ = [____]

# Create a query using natural language
____ = "What is the hypotenuse length of a triangle with side lengths of 10 and 12?"

# Pass in the hypotenuse length tool and create the agent
app = ____(____, ____)

# Invoke the agent and print the response
response = ____.____({"messages": [("____", ____)]})
print(____['messages'][-1].content)
Edit and Run Code