|
| 1 | +# UiPath LangGraph Template Agent |
| 2 | + |
| 3 | +A quickstart UiPath LangGraph agent. It answers user queries using live tools and optionally runs a second LLM pass to refine its own response. |
| 4 | + |
| 5 | +> **Docs:** [uipath-langchain quick start](https://uipath.github.io/uipath-python/langchain/quick_start/) — **Samples:** [uipath-langchain-python/samples](https://github.com/UiPath/uipath-langchain-python/tree/main/samples) |
| 6 | +
|
| 7 | +## What it does |
| 8 | + |
| 9 | +1. **Prepares** the conversation — injects a system prompt and the user query into state |
| 10 | +2. **Runs a ReAct agent node** (OpenAI `gpt-4.1-mini`) that autonomously decides which tools to call and in what order |
| 11 | +3. **Refines the response** — if `refine=true`, a second LLM (Gemini `gemini-2.5-flash`) acts as a quality reviewer, suggests one concrete improvement, and routes back to the ReAct node for a final pass |
| 12 | + |
| 13 | +### Tools |
| 14 | + |
| 15 | +| Tool | Description | |
| 16 | +| ------------------ | ------------------------------------------------ | |
| 17 | +| `get_current_time` | Returns the current UTC date and time (ISO 8601) | |
| 18 | +| `web_search` | Searches the web via DuckDuckGo | |
| 19 | + |
| 20 | +## Graph |
| 21 | + |
| 22 | +```mermaid |
| 23 | +flowchart TD |
| 24 | + START --> prepare |
| 25 | + prepare --> react_agent |
| 26 | + react_agent --> refine |
| 27 | + refine -->|"refine=true, first pass"| react_agent |
| 28 | + refine -->|done| END |
| 29 | +``` |
| 30 | + |
| 31 | +## Input / Output |
| 32 | + |
| 33 | +```json |
| 34 | +// Input |
| 35 | +{ |
| 36 | + "query": "What is the current UTC time and what are the latest news headlines about agentic AI today?", |
| 37 | + "refine": true |
| 38 | +} |
| 39 | + |
| 40 | +// Output |
| 41 | +{ |
| 42 | + "result": "..." |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +Set `refine: false` (default) to skip the refinement pass. |
| 47 | + |
| 48 | +## Running locally |
| 49 | + |
| 50 | +```bash |
| 51 | +# Run |
| 52 | +uv run uipath run agent --file input.json |
| 53 | + |
| 54 | +# Debug with dynamic node breakpoints |
| 55 | +uv run uipath debug agent --file input.json |
| 56 | +``` |
| 57 | + |
| 58 | +## Evaluation |
| 59 | + |
| 60 | +The agent ships with a tool call order evaluator that verifies the ReAct node calls `get_current_time` **before** `web_search` when given a time-dependent query. |
| 61 | + |
| 62 | +```bash |
| 63 | +uv run uipath eval |
| 64 | +``` |
| 65 | + |
| 66 | +## Actionable improvements |
| 67 | + |
| 68 | +### Add UiPath-native tools |
| 69 | + |
| 70 | +- **Read from an Orchestrator Asset** — use `sdk.assets.retrieve_async(name, folder_path="MyFolder")` to inject dynamic configuration (API keys, base URLs, feature flags) without redeploying |
| 71 | +- **Invoke a process** — use `sdk.processes.invoke_async(name, input_arguments, folder_path="MyFolder")` to trigger downstream RPA workflows from the agent's decision |
| 72 | + |
| 73 | +### Add Human-in-the-Loop |
| 74 | + |
| 75 | +Use the durable interrupt pattern with `CreateTask` to pause the graph mid-execution until a human completes the action in UiPath Action Center: |
| 76 | + |
| 77 | +```python |
| 78 | +from langgraph.types import interrupt |
| 79 | +from uipath.platform.common import CreateTask |
| 80 | + |
| 81 | +task_output = interrupt(CreateTask( |
| 82 | + app_name="AppName", |
| 83 | + app_folder_path="MyFolderPath", |
| 84 | + title="Escalate Issue", |
| 85 | + data={"key": "value"}, |
| 86 | + assignee="user@example.com", |
| 87 | +)) |
| 88 | +``` |
| 89 | + |
| 90 | +The graph suspends at the `interrupt` call and resumes automatically with `task_output` once the assignee completes the task. |
| 91 | + |
| 92 | +### Ground answers in your own documents |
| 93 | + |
| 94 | +Use Deep RAG to search a Context Grounding index with semantic + generative retrieval instead of the public web: |
| 95 | + |
| 96 | +```python |
| 97 | +from langgraph.types import interrupt |
| 98 | +from uipath.platform.common import CreateDeepRag |
| 99 | + |
| 100 | +result = interrupt(CreateDeepRag( |
| 101 | + index_name="my-index", |
| 102 | + prompt="What is the refund policy for enterprise customers?", |
| 103 | + index_folder_path="MyFolderPath", |
| 104 | +)) |
| 105 | +``` |
| 106 | + |
| 107 | +The graph suspends, runs the Deep RAG task on UiPath, and resumes with the grounded answer. |
| 108 | + |
| 109 | +### Add guardrails |
| 110 | + |
| 111 | +Wrap the graph with input/output guardrails from `uipath_langchain.guardrails` to filter harmful prompts and validate responses before they reach the user. |
| 112 | + |
| 113 | +### Swap the web search tool |
| 114 | + |
| 115 | +Replace `DuckDuckGoSearchRun` with a UiPath Integration Service connection (e.g. Bing, Google Search API) via `sdk.connections.invoke_activity_async(...)` for more reliable, rate-limit-controlled search. |
| 116 | + |
| 117 | +### Add memory |
| 118 | + |
| 119 | +Persist conversation history across runs by storing messages in an Orchestrator bucket or Data Service entity, then loading them in the `prepare` node. |
0 commit comments