Skip to content

Commit acb4ca5

Browse files
authored
fix: chat uipath agent sample (#403)
1 parent a6fcad5 commit acb4ca5

16 files changed

Lines changed: 7126 additions & 0 deletions

samples/chat-uipath-agent/.agent/CLI_REFERENCE.md

Lines changed: 563 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-4o-2024-08-06", 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-4o-2024-08-06", 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()`

samples/chat-uipath-agent/.agent/SDK_REFERENCE.md

Lines changed: 643 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UIPATH_URL=https://alpha.uipath.com/<organization>/<tenant>
2+
UIPATH_ACCESS_TOKEN=YOUR TOKEN HERE
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python-envs.pythonProjects": []
3+
}
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Movie Chat Agent
2+
3+
An AI assistant using LangGraph's built-in react agent with UiPath LLM and DuckDuckGo search for movie research and recommendations.
4+
5+
## Requirements
6+
7+
- Python 3.11+
8+
9+
## Installation
10+
11+
```bash
12+
uv venv -p 3.11 .venv
13+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
14+
uv sync
15+
```
16+
17+
## Usage
18+
19+
```bash
20+
uipath run agent '{"messages": [{"type": "human", "content": "Tell me about the movie Inception"}]}'
21+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
flowchart TB
2+
__start__(__start__)
3+
model(model)
4+
tools(tools)
5+
__end__(__end__)
6+
__start__ --> model
7+
model --> __end__
8+
model --> tools
9+
tools --> model
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)