UiPath Documentation
getting-started
latest
false
Guia de introdução do desenvolvedor
  • Introdução
    • Visão geral
    • Ambiente configurado
  • Introdução aos agentes da UiPath
  • Introdução aos agentes da UiPath usando o LangGraph
    • Introdução
    • Configure seu ambiente
    • Crie o agente
    • Adicionar uma ferramenta
    • Avaliar o agente
    • Conecte-se ao Studio Web
  • Construção de um agente de pouco código no Studio Web
  • Adicionando ferramentas ao seu agente UiPath
  • Introdução ao fluxo do UiPath Maestro Flow
Importante :
Este conteúdo foi traduzido com auxílio de tradução automática. A localização de um conteúdo recém-publicado pode levar de 1 a 2 semanas para ficar disponível.

Adicionar uma ferramenta

Use seu agente de codificação e as habilidades da UiPath para adicionar uma ferramenta ao agente do LangGraph.

Etapa 7 - Adicione uma ferramenta de pesquisa em tempo real​

No momento, o agente está calculando a partir de trabalho de transmissões: nada do que ele diz sobre um robô ou um Goblin é verificado contra algo real. Para melhorar a precisão do classificador, vamos adicionar uma ferramenta para verificar as informações da tarefa antes de finalizar uma recomendação de nível. Para fazer isso, a ferramenta usará a API Open5e para pesquisar credenciais publicadas no Documento de Referência do Sistema 5e (SRD).

Esse é o LangGraph padrão, não um truque específico da UiPath: uma função simples do Python Executada com @tool, vinculada ao modelo, e o modelo decide no runtime se a chamada vale a pena. Seu agente de codificação conecta essa sintaxe de associação para você.

Pergunte ao seu agente de codificação:

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.
Observação:

Por que essa solicitação é tão específica. Como na etapa 5, o escopo do arquivo e a instrução para não executar ou verificar qualquer coisa são deliberados: os próximos comandos neste laboratório executam a ferramenta diretamente, portanto, a verificação fica para você.

Ao adaptar o prompt para seu próprio trabalho, você é novamente aconselhado a remover as duas últimas frases para habilitar totalmente seu agente de codificação para exercer seu código.

Importante:

Os agentes de codificação não são determinísticos. Seu código de ferramenta gerado será diferente de quaisquer exemplos mostrados aqui; isso é esperado. O que importa é que main.py ainda é executado sem erros e chama a ferramenta apenas quando uma criação é nomeada.

Essa ferramenta não adiciona nem altera quaisquer campos de entrada ou saída, portanto, não há necessidade de executar uip codedagent init novamente desta vez. Execute-o novamente apenas quando seus modelos de entrada/saída mudarem.

Execute novamente o exemplo do robô da etapa 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"}'

Assista ao trace desta vez: o agente chama a pesquisa SRD, recebe uma classificação de desafio real e a menciona em seu raciocínio em vez de apenas afirmando Legendário. Essa é a diferença entre um classificador de texto e um agente que pode verificar a si mesmo.


Com a ferramenta conectada, você está pronto para testar se o agente a usa corretamente e pontua bem em um intervalo de entradas.

  • Etapa 7 - Adicione uma ferramenta de pesquisa em tempo real​

Esta página foi útil?

Conectar

Precisa de ajuda? Suporte

Quer aprender? Academia UiPath

Tem perguntas? Fórum do UiPath

Fique por dentro das novidades