- Einleitung
- Erste Schritte mit UiPath Agents
- Erste Schritte mit UiPath Agents mit LangGraph
- Erstellen eines Low-Code-Agents in Studio Web
- Hinzufügen von Tools zu Ihrem UiPath Agent
- Erste Schritte mit UiPath Maestro Flow
Fügen Sie ein Tool hinzu
Verwenden Sie Ihre Codierungs-Agent- und UiPath-Fähigkeiten, um dem LangGraph-Agent ein Tool hinzuzufügen.
Schritt 7 – Fügen Sie ein Live-Suchtool hinzu
Im Moment schätzt der Agent anhand von Variablen: Nichts, was er über einen Roboter oder einen Goweisentrigger sagt, wird mit etwas Echter verglichen. Um die Genauigkeit des Klassifizierers zu verbessern, fügen wir ein Tool hinzu, um Anforderungsinformationen zu überprüfen, bevor eine Stufenempfehlung abgeschlossen wird. Dazu verwendet das Tool die Open5e-API , um nach Maschinen zu suchen, die unter dem 5e System Reference Document (SRD) veröffentlicht wurden.
Das ist ein Standard-LangGraph und kein UiPath-spezifischer Trick: eine einfache Python-Funktion, die mit @tool eingerichtet und an das Modell gebunden ist, und das Modell entscheidet zur Laufzeit, ob sich der Aufruf richtet. Ihr Codierungs-Agent verwirft diese Bindungssyntax für Sie.
Fragen Sie Ihren Programmier-Agent:
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.
Warum dieser Prompt so spezifisch ist. Wie in Schritt 5 sind die Datei-Scoping und die Anweisung, nichts auszuführen oder zu überprüfen, bewusst: Die nächsten Befehle in diesem Labor übertragen das Tool direkt, sodass die Überprüfung Ihnen überlassen wird.
Wenn Sie den Prompt an Ihre eigene Arbeit anpassen, wird Ihnen erneut empfohlen, die letzten beiden Sätze zu entfernen, damit Ihr Codierungsagent Ihren Code vollständig ausführen kann.
Codierungs-Agents sind nicht-deterministisch. Ihr generierter Toolcode unterscheidet sich von allen hier gezeigten Beispielen; das erwartet wird. Was wichtig ist, ist, dass main.py immer noch ohne Fehler ausgeführt wird und das Tool nur aufruft, wenn eine Person benannt wird.
Dieses Tool fügt oder ändert keine Eingabe- oder Ausgabefelder, sodass uip codedagent init dieses Mal nicht erneut ausgeführt werden muss. Führen Sie sie nur erneut aus, wenn sich Ihre Eingabe-/Ausgabemodelle ändern.
Führen Sie das Roboterbeispiel aus Schritt 6 erneut aus:
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"}'
Sehen Sie sich dieses Mal die Ablaufverfolgung an: Der Agent ruft die SSD-Suche auf, erhält eine echte Herausforderungsbewertung zurück und zitiert sie in seiner Argumentation, anstatt nur Legendär zu sagen. Das ist der Unterschied zwischen einem Textklassifizierer und einem Agent, der sich selbst überprüfen kann.
Wenn das Tool integriert ist, können Sie testen, ob der Agent es korrekt verwendet und bei einer Reihe von Eingaben gut schneidet.