Agentische Systeme mit LangChain entwerfen
Dilini K. Sumanapala, PhD
Founder & AI Engineer, Genverv, Ltd.


Interne Query-Verarbeitung von LangChain
"What is the area of a rectangle with sides 5 and 7?"input = " 5, 7"
Definiere deine Tool-Funktion
@tooldef rectangle_area(input: str) -> float:"""Berechnet die Fläche eines Rechtecks mit den Seitenlängen a und b."""sides = input.split(',')a = float(sides[0].strip()) b = float(sides[1].strip())return a * b
@tool-Decorator.split() trennen.strip() Leerzeichen entfernen und in float umwandelna und b multiplizieren und Ergebnis zurückgeben# 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)
The area of the rectangle with sides 5 and 7 is 35 square units.
![]()
Agentische Systeme mit LangChain entwerfen