- Introducción
- Primeros pasos con los agentes de UiPath
- Primeros pasos con los agentes de UiPath utilizando LangGraph
- Introducción
- Configura tu entorno
- Crear el agente
- Añadir una herramienta
- Evaluar el agente
- Conectar a Studio Web
- Crear un agente de código bajo en Studio Web
- Añadir herramientas a tu agente de UiPath
- Primeros pasos con UiPath Maestro Flow
Añadir una herramienta
Utiliza tus habilidades de agente de codificación y UiPath para añadir una herramienta al agente de LangGraph.
Paso 7: añadir una herramienta de búsqueda activa
En este momento, el agente está adivinando por las vibraciones: nada de lo que dice sobre un dragón o un goblin se compara con algo real. Para mejorar la precisión del clasificador, vamos a añadir una herramienta para verificar la información de la misión antes de finalizar una recomendación de nivel. Para ello, la herramienta utilizará la API de Open5e para buscar criaturas publicadas en el documento de referencia del sistema (SRD) 5e.
Esto es LangGraph estándar, no un truco específico de UiPath: una función de Python simple decorada con @tool, vinculada al modelo, y el modelo decide en tiempo de ejecución si vale la pena llamarla. Tu agente de codificación conecta esa sintaxis de vinculación por ti.
Pregunta a tu agente de codificación:
Update main.py to add one Python tool to the existing LangGraph agent: a function that looks up a monster's challenge rating from the Open5e SRD API and uses it to inform the difficulty tier.
Tool behavior:
- Query GET https://api.open5e.com/v2/creatures/ using the `requests` library (already available as a transitive dependency; add it directly with `uv add requests` only if the import fails), with query parameters: name__icontains=<creature name or type the model supplies>, document__key__in=srd-2024, limit=10, fields=key,name,type,size,challenge_rating,alignment
- Set a 10-second timeout on the request, and call raise_for_status() before reading the response body — this is a live external API call, so it should fail fast with a clear error instead of hanging or raising a confusing KeyError if Open5e is slow or returns a non-200 response.
- If the response has zero results, return that as-is — nothing further to do.
- If the response has more than one result, return the full list and let the agent pick the best match rather than guessing which one is correct.
- Bind the tool with the standard LangChain @tool decorator. Let the model decide when to call it based on the tool's description — don't force a call on every input.
- Name the tool function `get_challenge_rating`.
- In the tool's docstring, describe what counts as a creature in the abstract — don't include a named example creature (e.g., avoid phrasing like "e.g. goblin, young red dragon"). A concrete example name in the docstring can get echoed back by the model as a spurious lookup for a creature that isn't actually in the quest.
Update the system prompt so that:
- The agent calls this tool whenever the quest description names or strongly implies a specific creature.
- Only call the tool for creatures explicitly named or strongly implied in the quest description — never for other creatures used as a comparison or reference point.
- When a `challenge_rating` comes back, the agent uses it to inform the tier classification and cites it explicitly in the `reasoning` output field. Do not fabricate or guess a challenge rating from memory — only cite one that actually came from the tool's response.
- If no tool call happens, or the tool returns zero results, the agent classifies using its existing judgment, same as before.
- Don't add new output fields. The State schema stays `tier` and `reasoning` only — the challenge rating goes into the reasoning text, not a new field.
Only touch main.py.
Don't run any uip codedagent commands or otherwise verify that the agent runs — I will do this myself.
Update main.py to add one Python tool to the existing LangGraph agent: a function that looks up a monster's challenge rating from the Open5e SRD API and uses it to inform the difficulty tier.
Tool behavior:
- Query GET https://api.open5e.com/v2/creatures/ using the `requests` library (already available as a transitive dependency; add it directly with `uv add requests` only if the import fails), with query parameters: name__icontains=<creature name or type the model supplies>, document__key__in=srd-2024, limit=10, fields=key,name,type,size,challenge_rating,alignment
- Set a 10-second timeout on the request, and call raise_for_status() before reading the response body — this is a live external API call, so it should fail fast with a clear error instead of hanging or raising a confusing KeyError if Open5e is slow or returns a non-200 response.
- If the response has zero results, return that as-is — nothing further to do.
- If the response has more than one result, return the full list and let the agent pick the best match rather than guessing which one is correct.
- Bind the tool with the standard LangChain @tool decorator. Let the model decide when to call it based on the tool's description — don't force a call on every input.
- Name the tool function `get_challenge_rating`.
- In the tool's docstring, describe what counts as a creature in the abstract — don't include a named example creature (e.g., avoid phrasing like "e.g. goblin, young red dragon"). A concrete example name in the docstring can get echoed back by the model as a spurious lookup for a creature that isn't actually in the quest.
Update the system prompt so that:
- The agent calls this tool whenever the quest description names or strongly implies a specific creature.
- Only call the tool for creatures explicitly named or strongly implied in the quest description — never for other creatures used as a comparison or reference point.
- When a `challenge_rating` comes back, the agent uses it to inform the tier classification and cites it explicitly in the `reasoning` output field. Do not fabricate or guess a challenge rating from memory — only cite one that actually came from the tool's response.
- If no tool call happens, or the tool returns zero results, the agent classifies using its existing judgment, same as before.
- Don't add new output fields. The State schema stays `tier` and `reasoning` only — the challenge rating goes into the reasoning text, not a new field.
Only touch main.py.
Don't run any uip codedagent commands or otherwise verify that the agent runs — I will do this myself.
Por qué esta solicitud es tan específica. Al igual que en el paso 5, la definición del ámbito del archivo y la instrucción de no ejecutar o verificar nada es deliberada: los siguientes comandos de este lab ejercitan la herramienta directamente, por lo que la verificación te queda a ti.
A medida que adaptas la solicitud a tu propio trabajo, se te recomienda de nuevo eliminar las dos últimas frases para permitir que tu agente de codificación ejerza tu código.
Los agentes de codificación no son deterministas. Tu código de herramienta generado diferirá de cualquier ejemplo mostrado aquí; que se espera. Lo que importa es que main.py aún se ejecuta sin errores y llama a la herramienta solo cuando se nombra una criatura.
Esta herramienta no añade ni cambia ningún campo de entrada o salida, por lo que no es necesario volver a ejecutar uip codedagent init esta vez. Vuelve a ejecutarlo solo cuando cambien tus modelos de entrada/salida.
Vuelve a ejecutar el ejemplo del dragón del paso 6:
uip codedagent run agent '{"description": "Slay the ancient red dragon terrorizing the countryside"}'
uip codedagent run agent '{"description": "Slay the ancient red dragon terrorizing the countryside"}'
Esta vez, mira el seguimiento: el agente llama a la búsqueda de SRD, obtiene una calificación de desafío real y la cita en su razonamiento en lugar de solo afirmar como Legendario. Esa es la diferencia entre un clasificador de texto y un agente que puede ir a verificarse a sí mismo.
Con la herramienta conectada, estás listo para probar que el agente la utiliza correctamente y obtiene una buena puntuación en un rango de entradas.