Integrar herramientas personalizadas y consultas
Ahora tienes una herramienta matemática personalizada para calcular la longitud del tejado. Puedes integrarla en un flujo de trabajo agentic creando una variable llamada query que acepte la pregunta del usuario en lenguaje natural como una cadena. Tu herramienta ya está cargada como hypotenuse_length, al igual que tu model.
Este ejercicio forma parte del curso
Diseño de sistemas agénticos con LangChain
Instrucciones del ejercicio
- Crea una variable de tipo lista llamada
toolse incluye tu herramienta,hypotenuse_length, dentro de la lista. - Crea una variable llamada
queryque acepte preguntas en lenguaje natural como cadenas. - Usa la función
create_react_agent()para crear el agente, pasandomodelytools. - Invoca la app del agente, pasando tu
queryetiquetada como"human", antes de guardar e imprimir laresponsedel agente.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Create a list variable and pass in your tool
____ = [____]
# Create a query using natural language
____ = "What is the hypotenuse length of a triangle with side lengths of 10 and 12?"
# Pass in the hypotenuse length tool and create the agent
app = ____(____, ____)
# Invoke the agent and print the response
response = ____.____({"messages": [("____", ____)]})
print(____['messages'][-1].content)