Skip to content

Commit d07880e

Browse files
committed
chore: add template agent
1 parent 55aec54 commit d07880e

19 files changed

Lines changed: 6129 additions & 0 deletions

template/.agent/CLI_REFERENCE.md

Lines changed: 619 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
## Required Agent Structure
2+
3+
**IMPORTANT**: All UiPath coded agents MUST follow this standard structure unless explicitly specified otherwise by the user.
4+
5+
### Required Components
6+
7+
Every agent implementation MUST include these three Pydantic models:
8+
9+
```python
10+
from pydantic import BaseModel
11+
12+
class Input(BaseModel):
13+
"""Define input fields that the agent accepts"""
14+
# Add your input fields here
15+
pass
16+
17+
class State(BaseModel):
18+
"""Define the agent's internal state that flows between nodes"""
19+
# Add your state fields here
20+
pass
21+
22+
class Output(BaseModel):
23+
"""Define output fields that the agent returns"""
24+
# Add your output fields here
25+
pass
26+
```
27+
28+
### Required LLM Initialization
29+
30+
Unless the user explicitly requests a different LLM provider, always use `UiPathChat`:
31+
32+
```python
33+
from uipath_langchain.chat import UiPathChat
34+
35+
llm = UiPathChat(model="gpt-4.1-mini-2025-04-14", temperature=0.7)
36+
```
37+
38+
**Alternative LLMs** (only use if explicitly requested):
39+
- `ChatOpenAI` from `langchain_openai`
40+
- `ChatAnthropic` from `langchain_anthropic`
41+
- Other LangChain-compatible LLMs
42+
43+
### Standard Agent Template
44+
45+
Every agent should follow this basic structure:
46+
47+
```python
48+
from langchain_core.messages import SystemMessage, HumanMessage
49+
from langgraph.graph import START, StateGraph, END
50+
from uipath_langchain.chat import UiPathChat
51+
from pydantic import BaseModel
52+
53+
# 1. Define Input, State, and Output models
54+
class Input(BaseModel):
55+
field: str
56+
57+
class State(BaseModel):
58+
field: str
59+
result: str = ""
60+
61+
class Output(BaseModel):
62+
result: str
63+
64+
# 2. Initialize UiPathChat LLM
65+
llm = UiPathChat(model="gpt-4.1-mini-2025-04-14", temperature=0.7)
66+
67+
# 3. Define agent nodes (async functions)
68+
async def process_node(state: State) -> State:
69+
response = await llm.ainvoke([HumanMessage(state.field)])
70+
return State(field=state.field, result=response.content)
71+
72+
async def output_node(state: State) -> Output:
73+
return Output(result=state.result)
74+
75+
# 4. Build the graph
76+
builder = StateGraph(State, input=Input, output=Output)
77+
builder.add_node("process", process_node)
78+
builder.add_node("output", output_node)
79+
builder.add_edge(START, "process")
80+
builder.add_edge("process", "output")
81+
builder.add_edge("output", END)
82+
83+
# 5. Compile the graph
84+
graph = builder.compile()
85+
```
86+
87+
**Key Rules**:
88+
1. Always use async/await for all node functions
89+
2. All nodes (except output) must accept and return `State`
90+
3. The final output node must return `Output`
91+
4. Use `StateGraph(State, input=Input, output=Output)` for initialization
92+
5. Always compile with `graph = builder.compile()`

template/.agent/SDK_REFERENCE.md

Lines changed: 779 additions & 0 deletions
Large diffs are not rendered by default.

template/AGENTS.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Agent Code Patterns Reference
2+
3+
This document provides practical code patterns for building UiPath coded agents using LangGraph and the UiPath Python SDK.
4+
5+
---
6+
7+
## Documentation Structure
8+
9+
This documentation is split into multiple files for efficient context loading. Load only the files you need:
10+
11+
1. **@.agent/REQUIRED_STRUCTURE.md** - Agent structure patterns and templates
12+
- **When to load:** Creating a new agent or understanding required patterns
13+
- **Contains:** Required Pydantic models (Input, State, Output), LLM initialization patterns, standard agent template
14+
15+
2. **@.agent/SDK_REFERENCE.md** - Complete SDK API reference
16+
- **When to load:** Calling UiPath SDK methods, working with services (actions, assets, jobs, etc.)
17+
- **Contains:** All SDK services and methods with full signatures and type annotations
18+
19+
3. **@.agent/CLI_REFERENCE.md** - CLI commands documentation
20+
- **When to load:** Working with `uipath init`, `uipath run`, or `uipath eval` commands
21+
- **Contains:** Command syntax, options, usage examples, and workflows

template/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md

template/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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.

template/agent.mermaid

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
flowchart TB
2+
__start__(__start__)
3+
prepare(prepare)
4+
refine(refine)
5+
__end__(__end__)
6+
__start__ --> prepare
7+
prepare --> react_agent
8+
react_agent --> refine
9+
refine --> __end__
10+
refine --> react_agent
11+
subgraph react_agent [react_agent]
12+
direction LR
13+
__start__(__start__)
14+
model(model)
15+
tools(tools)
16+
__end__(__end__)
17+
__start__ --> model
18+
model --> __end__
19+
model --> model
20+
model --> tools
21+
tools --> __end__
22+
tools --> model
23+
end

template/bindings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"version": "2.0",
3+
"resources": []
4+
}

0 commit comments

Comments
 (0)