Thiết kế Hệ thống Agentic với LangChain
Dilini K. Sumanapala, PhD
Founder & AI Engineer, Genverv, Ltd.


Xử lý truy vấn nội bộ của LangChain
"What is the area of a rectangle with sides 5 and 7?"input = " 5, 7"
Định nghĩa hàm công cụ
@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() và đổi sang floata và b rồi trả về kết quả# Định nghĩa các công cụ mà agent có thể truy cập tools = [rectangle_area]# Tạo truy vấn bằng ngôn ngữ tự nhiên query = "What is the area of a rectangle with sides 5 and 7?"# Truyền công cụ tính cạnh huyền và gọi agent app = create_react_agent(model, tools)
# Gọi agent và in phản hồi
response = app.invoke({"messages": [("human", query)]})
print(response['messages'][-1].content)
Diện tích hình chữ nhật có cạnh 5 và 7 là 35 đơn vị vuông.
![]()
Thiết kế Hệ thống Agentic với LangChain