Progettare sistemi agentici con LangChain
Dilini K. Sumanapala, PhD
Founder & AI Engineer, Genverv, Ltd.


Gestione interna delle query in LangChain
"What is the area of a rectangle with sides 5 and 7?"input = " 5, 7"
Definisci la funzione dello strumento
@tooldef rectangle_area(input: str) -> float:"""Calcola l'area di un rettangolo date le lunghezze dei lati a e b."""sides = input.split(',')a = float(sides[0].strip()) b = float(sides[1].strip())return a * b
@tool.split().strip() e converti in floata e b e restituisci il risultato# Definisci gli strumenti a cui l'agente può accedere tools = [rectangle_area]# Crea una query in linguaggio naturale query = "What is the area of a rectangle with sides 5 and 7?"# Passa lo strumento per la lunghezza dell'ipotenusa e avvia l'agente app = create_react_agent(model, tools)
# Esegui l'agente e stampa la risposta
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.
![]()
Progettare sistemi agentici con LangChain