Merancang Sistem Agentic dengan LangChain
Dilini K. Sumanapala, PhD
Founder & AI Engineer, Genverv, Ltd.


Penanganan kueri internal LangChain
"What is the area of a rectangle with sides 5 and 7?"input = " 5, 7"
Definisikan fungsi alat Anda
@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() dan konversi ke floata dan b lalu kembalikan hasilnya# Define the tools that the agent can access tools = [rectangle_area]# Create a query using natural language query = "What is the area of a rectangle with sides 5 and 7?"# Pass in the hypotenuse length tool and invoke the agent app = create_react_agent(model, tools)
# Invoke the agent and print the response
response = app.invoke({"messages": [("human", query)]})
print(response['messages'][-1].content)
Luas persegi panjang dengan sisi 5 dan 7 adalah 35 satuan persegi.
![]()
Merancang Sistem Agentic dengan LangChain