Проєктування агентних систем з LangChain
Dilini K. Sumanapala, PhD
Founder & AI Engineer, Genverv, Ltd.


Внутрішня обробка запиту в LangChain
"What is the area of a rectangle with sides 5 and 7?"input = " 5, 7"
Визначте функцію інструменту
@tooldef rectangle_area(input: str) -> float:"""Calculates the area of a rectangle given the lengths of sides a and b."""sides = input.split(',')a = float(sides[0].strip()) b = float(sides[1].strip())return a * b
@tool.split().strip() і перетворіть на floata і b та поверніть результат# Визначте інструменти, доступні агенту tools = [rectangle_area]# Створіть запит природною мовою query = "What is the area of a rectangle with sides 5 and 7?"# Передайте інструмент для гіпотенузи та викличте агента app = create_react_agent(model, tools)
# Викличте агента і виведіть відповідь
response = app.invoke({"messages": [("human", query)]})
print(response['messages'][-1].content)
Площа прямокутника зі сторонами 5 і 7 дорівнює 35 квадратних одиниць.
![]()
Проєктування агентних систем з LangChain