- Introduction
- Commencer avec les agents UiPath
- Premiers pas avec les agents UiPath utilisant LangGraph
- Créer un agent low-code dans Studio Web
- Ajouter des outils à votre agent UiPath
- Premiers pas avec UiPath Maestro Flow
Ajouter un outil
Utilisez votre agent de codage et vos compétences UiPath pour ajouter un outil à l'agent LangGraph.
Étape 7: ajoutez un outil de recherche en direct
À l'instant, l'agent devine à partir des valeurs: rien ce qu'il indique sur un robot ou un Goven est vérifié par comparaison avec tout ce qui est réel. Pour améliorer la précision du classifieur, ajoutons un outil pour vérifier les informations de la requête avant de finaliser une recommandation de niveau. Pour ce faire, l'outil utilisera l' API Open5e pour rechercher les créations publiées sous le document de référence système 5e.
Il s'agit de LangGraph standard, et non d'une astuces spécifique à UiPath: une fonction Python simple ornée de @tool, liée au modèle, et le modèle décide au moment de l'exécution si l'appel en vaut la peine. Votre agent de codage génère cette syntaxe de liaison pour vous.
Demandez à votre agent de codage:
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.
Pourquoi cette invite est-elle si spécifique? Comme à l'étape 5, la portée du fichier et l'instruction de ne pas exécuter ou vérifier quoi que ce soit sont délibérées: les commandes suivantes de ce laboratoire appliquent l'outil directement, de sorte que la vérification vous appartient.
Étant donné que vous adaptez l'invite à votre propre travail, il est à nouveau conseillé de supprimer les deux dernières phrases pour permettre à votre agent de codage d'exécuter pleinement votre code.
Les agents de codage sont non déterministes. Le code de votre outil généré sera différent de celui des exemples affichés ici; ce qui est attendu. Ce qui compte, c'est que main.py s'exécute toujours sans erreur et appelle l'outil uniquement lorsqu'une création est nommée.
Cet outil n’ajoute ni ne modifie aucun champ d’entrée ou de sortie, il n’est donc pas nécessaire de réexécuter uip codedagent init pour le moment. Réexécutez-le uniquement lorsque vos modèles d’entrée/sortie changent.
Réexécutez l'exemple du robot de l'étape 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"}'
Regardez la trace cette fois: l'agent appelle la recherche du SRS, récupère une évaluation réelle du défi et la cite dans son raisonnement au lieu d'asserter simplement Légende. C’est la différence entre un classifieur de texte et un agent qui peut se vérifier lui-même.
Une fois l'outil connecté, vous êtes prêt à tester que l'agent l'utilise correctement et à obtenir de bons résultats dans une plage d'entrées.