Skip to content

Commit aa503b8

Browse files
committed
chore: add query_engine sample
1 parent a875154 commit aa503b8

18 files changed

Lines changed: 906 additions & 6 deletions
51.9 KB
Loading
47.9 KB
Loading
51 KB
Loading
44.8 KB
Loading

docs/sample_images/RAG/indexes.png

32.1 KB
Loading
34.6 KB
Loading

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-llamaindex"
3-
version = "0.0.25"
3+
version = "0.0.26"
44
description = "UiPath LlamaIndex SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
@@ -90,3 +90,4 @@ name = "testpypi"
9090
url = "https://test.pypi.org/simple/"
9191
publish-url = "https://test.pypi.org/legacy/"
9292
explicit = true
93+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[project]
2+
name = "travel-helper-RAG-agent"
3+
version = "0.0.4"
4+
description = "UiPath LlamaIndex Simple HITL Agent"
5+
authors = [{ name = "Radu Mocanu", email = "radu.mocanu@uipath.com" }]
6+
readme = { file = "README.md", content-type = "text/markdown" }
7+
requires-python = ">=3.10"
8+
dependencies = [
9+
"uipath-llamaindex>=0.0.26",
10+
"llama-index-llms-openai>=0.2.2"
11+
]
12+
13+
[[tool.uv.index]]
14+
name = "testpypi"
15+
url = "https://test.pypi.org/simple/"
16+
publish-url = "https://test.pypi.org/legacy/"
17+
explicit = true
18+
19+
[tool.uv.sources]
20+
uipath-llamaindex = { index = "testpypi" }
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# Travel helper RAG agent
2+
3+
## Overview
4+
5+
The **Travel helper RAG agent** project demonstrates the implementation of a Retrieval-Augmented Generation (RAG) system using [UiPath Context Grounding](https://docs.uipath.com/automation-cloud/automation-cloud/latest/admin-guide/about-context-grounding).
6+
7+
It consists of a Llama Index agent that utilizes two `ContextGroundingQueryEngines`: one to retrieve relevant data about the company's travel policy and another to assess an individual's personal travel preferences.
8+
9+
## System Architecture
10+
11+
### Agent Graph
12+
13+
```mermaid
14+
flowchart TD
15+
step__done["_done"]:::stepStyle
16+
step_add_data_to_index["add_data_to_index"]:::stepStyle
17+
step_combine_and_interpret_answers["combine_and_interpret_answers"]:::stepStyle
18+
step_create_sub_questions_plan["create_sub_questions_plan"]:::stepStyle
19+
step_handle_sub_question["handle_sub_question"]:::stepStyle
20+
step_wait_for_index_ingestion["wait_for_index_ingestion"]:::stepStyle
21+
step_workflow_entrypoint["workflow_entrypoint"]:::stepStyle
22+
event_AddDataToIndexEvent([<p>AddDataToIndexEvent</p>]):::defaultEventStyle
23+
event_WaitForIndexIngestion([<p>WaitForIndexIngestion</p>]):::defaultEventStyle
24+
event_AnswerEvent([<p>AnswerEvent</p>]):::defaultEventStyle
25+
event_OutputEvent([<p>OutputEvent</p>]):::stopEventStyle
26+
event_QueryEvent([<p>QueryEvent</p>]):::defaultEventStyle
27+
event_SubQuestionEvent([<p>SubQuestionEvent</p>]):::defaultEventStyle
28+
event_CustomStartEvent([<p>CustomStartEvent</p>]):::defaultEventStyle
29+
event_OutputEvent --> step__done
30+
step_add_data_to_index --> event_WaitForIndexIngestion
31+
event_AddDataToIndexEvent --> step_add_data_to_index
32+
step_combine_and_interpret_answers --> event_OutputEvent
33+
event_AnswerEvent --> step_combine_and_interpret_answers
34+
step_create_sub_questions_plan --> event_SubQuestionEvent
35+
event_QueryEvent --> step_create_sub_questions_plan
36+
step_handle_sub_question --> event_AnswerEvent
37+
event_SubQuestionEvent --> step_handle_sub_question
38+
step_wait_for_index_ingestion --> event_QueryEvent
39+
step_wait_for_index_ingestion --> event_OutputEvent
40+
event_WaitForIndexIngestion --> step_wait_for_index_ingestion
41+
step_workflow_entrypoint --> event_QueryEvent
42+
step_workflow_entrypoint --> event_AddDataToIndexEvent
43+
event_CustomStartEvent --> step_workflow_entrypoint
44+
classDef stepStyle fill:#f2f0ff,line-height:1.2
45+
classDef externalStyle fill:#f2f0ff,line-height:1.2
46+
classDef defaultEventStyle fill-opacity:0
47+
classDef stopEventStyle fill:#bfb6fc
48+
classDef inputRequiredStyle fill:#f2f0ff,line-height:1.2
49+
```
50+
51+
## Agent Responsibilities
52+
53+
- Accepts a user query with details about an upcoming business trip.
54+
- Initializes two `QueryEngineTools`, each based on distinct context-grounding indexes.
55+
- Breaks down the initial query into multiple `sub-questions`.
56+
- Assigns ReAct agents to address each `sub-question`.
57+
- Combines the responses to generate a travel summary, including the permitted budget, employee preferences, and recommendations.
58+
59+
## Steps to Execute Project on UiPath Cloud Platform
60+
### Prerequisites
61+
1. **Create two Orchestrator Storage Buckets**
62+
63+
For this demo we'll create them in the _Shared_ folder.
64+
65+
![navigate to Storage Buckets page](../../docs/sample_images/RAG/create-storage-bucket-1.png)
66+
67+
68+
![create storage bucket](../../docs/sample_images/RAG/create-storage-bucket-2.png)
69+
70+
![storage_buckets](../../docs/sample_images/RAG/storage_buckets.png)
71+
72+
2. **Create two Context Grounding Indexes**
73+
74+
Next, we'll create two Context Grounding Indexes.
75+
76+
![navigate to Indexes page](../../docs/sample_images/RAG/create-index-1.png)
77+
78+
When configuring _Index General Details_, we'll select the previously created storage buckets as data sources.
79+
80+
Example for `company_policy` index:
81+
82+
![create index](../../docs/sample_images/RAG/create-index-2.png)
83+
84+
![create index](../../docs/sample_images/RAG/indexes.png)
85+
86+
That's it! Next, we'll deploy the agent.
87+
88+
### Deploy the agents
89+
1. **Clone the Repository**
90+
```bash
91+
git clone https://github.com/UiPath/uipath-llamaindex-python.git
92+
```
93+
94+
2. **Navigate to the Sample Directory**
95+
- **Windows:**
96+
```bash
97+
cd .\uipath-llamaindex-python\samples\travel-helper-RAG-agent
98+
```
99+
100+
- **Unix-like Systems (Linux, macOS):**
101+
```bash
102+
cd ./uipath-llamaindex-python/samples/travel-helper-RAG-agent
103+
```
104+
105+
3. **Create and Activate a Virtual Python Environment**
106+
```bash
107+
pip install uv
108+
uv venv -p 3.11 .venv
109+
.venv\Scripts\activate # Windows
110+
source .venv/bin/activate # Unix-like Systems
111+
uv sync
112+
```
113+
114+
4. **Authenticate with UiPath Cloud Platform**
115+
```bash
116+
uipath auth
117+
```
118+
> **Note:** After successful authentication in the browser, select the tenant for publishing the agent package.
119+
```
120+
👇 Select tenant:
121+
0: DefaultTenant
122+
1: Tenant2
123+
2: Tenant3
124+
...
125+
Select tenant: 2
126+
```
127+
128+
5. **Package and Publish Agents**
129+
```bash
130+
uipath pack
131+
uipath publish --my-workspace
132+
```
133+
```
134+
⠋ Publishing most recent package: travel-helper-RAG-agent.1.0.0.nupkg ...
135+
✓ Package published successfully!
136+
⠇ Getting process information ...
137+
🔗 Process configuration link: [LINK]
138+
💡 Use the link above to configure any environment variables
139+
```
140+
> Note: when publishing to _my-workspace_ a process will be auto-provisioned for you.
141+
142+
6**Run the agent on UiPath Cloud Platform**
143+
144+
We can run the agent from _Processes_ page
145+
146+
![run-process-button](../../docs/sample_images/RAG/run-process-1.png)
147+
148+
![run-process](../../docs/sample_images/RAG/run-process-2.png)
149+
150+
> ℹ️ Here is how we can easily copy any folder path.
151+
152+
![folder-path](../../docs/sample_images/RAG/folder-path.png)
153+
154+
8. **Conclusions**
155+
156+
We can monitor our agent execution from the job info panel.
157+
158+
![job-info](../../docs/sample_images/RAG/job-info.png)
159+
160+
_Quiz-generator-RAG-agent_ may choose to invoke researcher agent
161+
multiple times before creating the quiz. The output should look like this:
162+
163+
![agent-output](../../docs/sample_images/RAG/output.png)
164+
165+
We can also check the storage bucket content.
166+
167+
![click-storage-bucket](../../docs/sample_images/RAG/click-storage-bucket.png)
168+
169+
This is the information fetched by our _researcher agent_ that the _quiz generator_ used to create the quiz using RAG.
170+
We can download this file/files to analyze them.
171+
172+
![storage-bucket-content](../../docs/sample_images/RAG/storage-bucket-content.png)
173+
174+
## Local Debugging
175+
You can locally debug individual agents by invoking them directly:
176+
177+
#### Researcher Agent
178+
Run the researcher agent with:
179+
180+
```bash
181+
uipath run researcher-RAG-agent '{"search_instructions":"Need data about spanish cuisine", "index_name":"sample-RAG-index", "index_folder_path":"<index_folder_path>"}'
182+
# or use .json file input
183+
uipath run researcher-RAG-agent -f input.example/researcher-debug-input.json
184+
```
185+
> **_NOTE:_** This assumes that an index named _sample-RAG-index_ is created in the folder identified by the index_folder_path parameter.
186+
187+
188+
#### Quiz Generator Agent
189+
Run the quiz generator agent with:
190+
191+
```bash
192+
uipath run quiz-generator-RAG-agent '{"quiz_topic":"spanish cuisine", "index_name":"sample-RAG-index", "index_folder_path":"<index_folder_path>"}'
193+
# or use .json file input
194+
uipath run quiz-generator-RAG-agent -f input.example/quiz-generator-debug-input.json
195+
```
196+
> **_NOTE:_** This assumes that an agent named _researcher-RAG-agent_ is created in the folder identified by the folder_path parameter passed to _InvokeProcess_ method.
197+
> <br> ℹ️ check [researcher-RAG-agent.py](src/agents/quiz-generator-RAG-agent.py) file.
198+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
flowchart TD
2+
step__done["_done"]:::stepStyle
3+
step_add_data_to_index["add_data_to_index"]:::stepStyle
4+
step_combine_and_interpret_answers["combine_and_interpret_answers"]:::stepStyle
5+
step_create_sub_questions_plan["create_sub_questions_plan"]:::stepStyle
6+
step_handle_sub_question["handle_sub_question"]:::stepStyle
7+
step_wait_for_index_ingestion["wait_for_index_ingestion"]:::stepStyle
8+
step_workflow_entrypoint["workflow_entrypoint"]:::stepStyle
9+
event_AddDataToIndexEvent([<p>AddDataToIndexEvent</p>]):::defaultEventStyle
10+
event_WaitForIndexIngestion([<p>WaitForIndexIngestion</p>]):::defaultEventStyle
11+
event_AnswerEvent([<p>AnswerEvent</p>]):::defaultEventStyle
12+
event_OutputEvent([<p>OutputEvent</p>]):::stopEventStyle
13+
event_QueryEvent([<p>QueryEvent</p>]):::defaultEventStyle
14+
event_SubQuestionEvent([<p>SubQuestionEvent</p>]):::defaultEventStyle
15+
event_CustomStartEvent([<p>CustomStartEvent</p>]):::defaultEventStyle
16+
event_OutputEvent --> step__done
17+
step_add_data_to_index --> event_WaitForIndexIngestion
18+
event_AddDataToIndexEvent --> step_add_data_to_index
19+
step_combine_and_interpret_answers --> event_OutputEvent
20+
event_AnswerEvent --> step_combine_and_interpret_answers
21+
step_create_sub_questions_plan --> event_SubQuestionEvent
22+
event_QueryEvent --> step_create_sub_questions_plan
23+
step_handle_sub_question --> event_AnswerEvent
24+
event_SubQuestionEvent --> step_handle_sub_question
25+
step_wait_for_index_ingestion --> event_QueryEvent
26+
step_wait_for_index_ingestion --> event_OutputEvent
27+
event_WaitForIndexIngestion --> step_wait_for_index_ingestion
28+
step_workflow_entrypoint --> event_QueryEvent
29+
step_workflow_entrypoint --> event_AddDataToIndexEvent
30+
event_CustomStartEvent --> step_workflow_entrypoint
31+
classDef stepStyle fill:#f2f0ff,line-height:1.2
32+
classDef externalStyle fill:#f2f0ff,line-height:1.2
33+
classDef defaultEventStyle fill-opacity:0
34+
classDef stopEventStyle fill:#bfb6fc
35+
classDef inputRequiredStyle fill:#f2f0ff,line-height:1.2

0 commit comments

Comments
 (0)