|
| 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 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +2. **Create two Context Grounding Indexes** |
| 73 | + |
| 74 | +Next, we'll create two Context Grounding Indexes. |
| 75 | + |
| 76 | + |
| 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 | + |
| 83 | + |
| 84 | + |
| 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 | + |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +> ℹ️ Here is how we can easily copy any folder path. |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | +8. **Conclusions** |
| 155 | + |
| 156 | +We can monitor our agent execution from the job info panel. |
| 157 | + |
| 158 | + |
| 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 | + |
| 164 | + |
| 165 | +We can also check the storage bucket content. |
| 166 | + |
| 167 | + |
| 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 | + |
| 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 | + |
0 commit comments