1. Learn
  2. /
  3. Courses
  4. /
  5. Designing Agentic Systems with LangChain

Connected

Exercise

Create a tool for math calculations

It's time to build your tool. Let's imagine you run a small construction company and need to calculate the length of one side of a roof. If you know the lengths of two beams that support the roof at a right angle, you can use their lengths to calculate the length of the roof using the hypotenuse formula below. $$c = \sqrt{a^2 + b^2}$$

Roof beam calculation diagram

Instructions

100 XP
  • Use the necessary decorator to define the function as a tool.
  • To find the hypotenuse, use the .split() method on the input string to extract the two other lengths of a right-sided triangle.
  • Convert each triangle side, a and b, to floats and use .strip() to remove any extra spaces from the values.
  • Use Python's math module to square the lengths a and b, sum their values, and find their square root to reveal the length of the roof.