UiPath Documentation
getting-started
latest
false
入门开发者指南
  • 简介
    • 概述
    • 环境已设置
  • UiPath 智能体入门
  • 开始使用 UiPath 智能体(采用 LangGraph)
    • 简介
    • 设置您的环境
    • 构建智能体
    • 添加工具
    • 评估智能体
    • 连接到 Studio Web
  • 在 Studio Web 中构建低代码智能体
  • 向 UiPath 智能体添加工具
  • Getting Started with UiPath Maestro Flow
重要 :
请注意,此内容已使用机器翻译进行了本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

添加工具

使用您的编码智能体和 UiPath 技能向 LangGraph 智能体添加工具。

步骤 7 - 添加实时查找工具​

现在,智能体正在根据感知进行猜测:系统不会将智能体所说的任何关于追踪者或地精的内容与真实信息进行核对。为了提高分类器的准确性,让我们添加一个工具,用于在最终确定层级建议之前验证任务信息。为此,该工具将使用Open5e API搜索在 5e 系统参考文档 (SRD) 下发布的生物。

这是标准 LangGraph,而不是特定于 UiPath 的技巧:这是一个用 @tool 修饰的纯 Python 函数绑定到模型,模型在运行时决定是否值得调用该函数。您的编码智能体已为您连接该绑定语法。

询问您的编码智能体:

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.
备注:

此提示词为何如此具体。与步骤 5 中一样,文件作用域以及不运行或验证任何内容的指令是有意而为之的:本实验室中的后续命令将直接运用该工具,因此您将需要进行验证。

在您根据自己的工作调整提示词时,再次建议您删除最后两句话,以完全使编码智能体能够执行您的代码。

重要提示:

编码智能体是非确定性的。您生成的工具代码将与此处显示的任何示例代码不同;这是预期的。重要的是 main.py 仍然可以正常运行,并且仅在命名生物时调用该工具。

此工具不会添加或更改任何输入或输出字段,因此这次无需重新运行 uip codedagent init。仅在输入/输出模型发生变化时重新运行。

重新运行步骤 6 中的 long 示例:

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"}'

观察这次的追踪记录:智能体调用 SRD 查找,获取真实的挑战评分,并在其推理中引用该评分,而不仅仅是断言“Legendary”。这就是文本分类器与可以验证自身的智能体之间的区别。


连接工具后,您就可以测试智能体是否正确使用该工具,以及在一系列输入中获得良好分数。

  • 步骤 7 - 添加实时查找工具​

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新