|
| 1 | +# Quickstart Guide: UiPath LLamaIndex Agents |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This guide provides step-by-step instructions for setting up, creating, publishing, and running your first UiPath-LLamaIndex Agent. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +Before proceeding, ensure you have the following installed: |
| 10 | + |
| 11 | +- Python 3.10 or higher |
| 12 | +- `pip` or `uv` package manager |
| 13 | +- A UiPath Automation Cloud account with appropriate permissions |
| 14 | +- An OpenAI API key |
| 15 | + |
| 16 | +/// info |
| 17 | + **OpenAI** - Generate an OpenAI API key [here](https://platform.openai.com). |
| 18 | + /// |
| 19 | + |
| 20 | +## Creating a New Project |
| 21 | + |
| 22 | +We recommend using `uv` for package management. To create a new project: |
| 23 | + |
| 24 | +//// tab | Linux, macOS, Windows Bash |
| 25 | + |
| 26 | +<!-- termynal --> |
| 27 | + |
| 28 | +```shell |
| 29 | +> mkdir example |
| 30 | +> cd example |
| 31 | +``` |
| 32 | + |
| 33 | +//// |
| 34 | + |
| 35 | +//// tab | Windows PowerShell |
| 36 | + |
| 37 | +<!-- termynal --> |
| 38 | + |
| 39 | +```powershell |
| 40 | +> New-Item -ItemType Directory -Path example |
| 41 | +> Set-Location example |
| 42 | +``` |
| 43 | + |
| 44 | +//// |
| 45 | + |
| 46 | +//// tab | uv |
| 47 | + new: true |
| 48 | + |
| 49 | +<!-- termynal --> |
| 50 | + |
| 51 | +```shell |
| 52 | +# Initialize a new uv project in the current directory |
| 53 | +> uv init . --python 3.10 |
| 54 | + |
| 55 | +# Create a new virtual environment |
| 56 | +# By default, uv creates a virtual environment in a directory called .venv |
| 57 | +> uv venv |
| 58 | +Using CPython 3.10.16 interpreter at: [PATH] |
| 59 | +Creating virtual environment at: .venv |
| 60 | +Activate with: source .venv/bin/activate |
| 61 | + |
| 62 | +# Activate the virtual environment |
| 63 | +# For Windows PowerShell/ Windows CMD: .venv\Scripts\activate |
| 64 | +# For Windows Bash: source .venv/Scripts/activate |
| 65 | +> source .venv/bin/activate |
| 66 | + |
| 67 | +# Install the uipath package |
| 68 | +> uv add uipath-llamaindex |
| 69 | +``` |
| 70 | + |
| 71 | +//// |
| 72 | + |
| 73 | +//// tab | pip |
| 74 | + |
| 75 | +<!-- termynal --> |
| 76 | + |
| 77 | +```shell |
| 78 | +# Create a new virtual environment |
| 79 | +> python -m venv .venv |
| 80 | + |
| 81 | +# Activate the virtual environment |
| 82 | +# For Windows PowerShell: .venv\Scripts\Activate.ps1 |
| 83 | +# For Windows Bash: source .venv/Scripts/activate |
| 84 | +> source .venv/bin/activate |
| 85 | + |
| 86 | +# Upgrade pip to the latest version |
| 87 | +> python -m pip install --upgrade pip |
| 88 | + |
| 89 | +# Install the uipath package |
| 90 | +> pip install uipath-llamaindex |
| 91 | +``` |
| 92 | + |
| 93 | +//// |
| 94 | + |
| 95 | +## Create Your First UiPath Agent |
| 96 | + |
| 97 | +Generate your first UiPath LLamaIndex agent: |
| 98 | + |
| 99 | +<!-- termynal --> |
| 100 | + |
| 101 | +```shell |
| 102 | +> uipath new my-agent |
| 103 | +⠋ Creating new agent my-agent in current directory ... |
| 104 | +✓ Created 'main.py' file. |
| 105 | +✓ Created 'llama_index.json' file. |
| 106 | +✓ Created 'pyproject.toml' file. |
| 107 | +🔧 Please ensure to define OPENAI_API_KEY in your .env file. |
| 108 | +💡 Initialize project: uipath init |
| 109 | +💡 Run agent: uipath run agent '{"topic": "UiPath"}' |
| 110 | +``` |
| 111 | + |
| 112 | +This command creates the following files: |
| 113 | + |
| 114 | +| File Name | Description | |
| 115 | +|------------------|----------------------------------------------------------------------------------------------------------------------------------| |
| 116 | +| `main.py` | LLamaIndex agent code. | |
| 117 | +| `llama_index.json` | LLamaIndex specific configuration file. | |
| 118 | +| `pyproject.toml` | Project metadata and dependencies as per [PEP 518](https://peps.python.org/pep-0518/). | |
| 119 | + |
| 120 | + |
| 121 | +## Initialize Project |
| 122 | + |
| 123 | +<!-- termynal --> |
| 124 | + |
| 125 | +```shell |
| 126 | +> uipath init |
| 127 | +⠋ Initializing UiPath project ... |
| 128 | +✓ Created '.env' file. |
| 129 | +✓ Created 'agent.mermaid' file. |
| 130 | +✓ Created 'uipath.json' file. |
| 131 | +``` |
| 132 | + |
| 133 | +This command creates the following files: |
| 134 | + |
| 135 | +| File Name | Description | |
| 136 | +| ---------------- | --------------------------------------------------------------------------------------------------------------------------------- | |
| 137 | +| `.env` | Environment variables and secrets (this file will not be packed & published). | |
| 138 | +| `uipath.json` | Input/output JSON schemas and bindings. | |
| 139 | +| `agent.mermaid` | Graph visual representation. | |
| 140 | + |
| 141 | +## Set Up Environment Variables |
| 142 | + |
| 143 | +Before running the agent, configure `OPENAI_API_KEY` in the `.env` file: |
| 144 | + |
| 145 | +//// tab | Open AI |
| 146 | + |
| 147 | +``` |
| 148 | +OPENAI_API_KEY=sk-proj-...... |
| 149 | +``` |
| 150 | + |
| 151 | +//// |
| 152 | + |
| 153 | +## Authenticate With UiPath |
| 154 | + |
| 155 | +<!-- termynal --> |
| 156 | + |
| 157 | +```shell |
| 158 | +> uipath auth |
| 159 | +⠋ Authenticating with UiPath ... |
| 160 | +🔗 If a browser window did not open, please open the following URL in your browser: [LINK] |
| 161 | +👇 Select tenant: |
| 162 | + 0: Tenant1 |
| 163 | + 1: Tenant2 |
| 164 | +Select tenant number: 0 |
| 165 | +Selected tenant: Tenant1 |
| 166 | +✓ Authentication successful. |
| 167 | +``` |
| 168 | + |
| 169 | +## Run The Agent Locally |
| 170 | + |
| 171 | +Execute the agent with a sample input: |
| 172 | + |
| 173 | +<!-- termynal --> |
| 174 | + |
| 175 | +```shell |
| 176 | +> uipath run agent '{"topic": "UiPath"}' |
| 177 | +{'joke': 'Why did the UiPath robot go to therapy? \nBecause it had too many unresolved workflows!', 'critique': "Analysis:\nThis joke plays on the concept of therapy and unresolved issues, but applies it to a UiPath robot, which is a software automation tool used in businesses. The joke cleverly incorporates the idea of workflows, which are sequences of automated tasks that the robot performs, as the source of the robot's need for therapy.\n\nCritique:\n- Clever wordplay: The joke is clever in its use of wordplay, as it takes a common phrase related to therapy and applies it in a humorous way to a robot and its workflows. This adds an element of surprise and wit to the joke.\n- Relevant to the audience: The joke is likely to resonate with those familiar with UiPath or other automation tools, as they will understand the reference to workflows and the challenges that can arise from managing them.\n- Lack of depth: While the joke is amusing on the surface, it may lack depth or complexity compared to more nuanced humor. Some may find it to be a simple play on words rather than a joke with deeper layers of meaning.\n- Limited appeal: The joke's humor may be limited to a specific audience who are familiar with automation tools and workflows, potentially excluding those who are not familiar with these concepts.\n\nOverall, the joke is a clever play on words that will likely resonate with those in the automation industry, but may not have broad appeal beyond that specific audience."} |
| 178 | +✓ Successful execution. |
| 179 | +``` |
| 180 | + |
| 181 | +This command runs your agent locally and displays the report in the standard output. |
| 182 | + |
| 183 | +/// warning |
| 184 | +Depending on the shell you are using, it may be necessary to escape the input json: |
| 185 | + |
| 186 | +/// tab | Bash/ZSH/PowerShell |
| 187 | +```console |
| 188 | +uipath run agent '{"topic": "UiPath"}' |
| 189 | +``` |
| 190 | +/// |
| 191 | + |
| 192 | +/// tab | Windows CMD |
| 193 | +```console |
| 194 | +uipath run agent "{""topic"": ""UiPath""}" |
| 195 | +``` |
| 196 | +/// |
| 197 | + |
| 198 | +/// tab | Windows PowerShell |
| 199 | +```console |
| 200 | +uipath run agent '{\"topic\":\"uipath\"}' |
| 201 | +``` |
| 202 | +/// |
| 203 | + |
| 204 | +/// |
| 205 | + |
| 206 | +/// attention |
| 207 | + |
| 208 | +For a shell agnostic option, please refer to the next section. |
| 209 | + |
| 210 | +/// |
| 211 | + |
| 212 | +### (Optional) Run The Agent with a json File as Input |
| 213 | + |
| 214 | +The `run` command can also take a .json file as an input. You can create a file named `input.json` having the following content: |
| 215 | + |
| 216 | +```json |
| 217 | +{ |
| 218 | + "topic": "UiPath" |
| 219 | +} |
| 220 | +``` |
| 221 | + |
| 222 | +Use this file as agent input: |
| 223 | + |
| 224 | +```shell |
| 225 | +> uipath run agent --file input.json |
| 226 | +``` |
| 227 | + |
| 228 | +## Deploy the Agent to UiPath Automation Cloud |
| 229 | + |
| 230 | +Follow these steps to publish and run your agent to UiPath Automation Cloud: |
| 231 | + |
| 232 | +### (Optional) Customize the Package |
| 233 | + |
| 234 | +Update author details in `pyproject.toml`: |
| 235 | + |
| 236 | +```toml |
| 237 | +authors = [{ name = "Your Name", email = "your.name@example.com" }] |
| 238 | +``` |
| 239 | + |
| 240 | +### Package Your Project |
| 241 | + |
| 242 | +<!-- termynal --> |
| 243 | + |
| 244 | +```shell |
| 245 | +> uipath pack |
| 246 | +⠋ Packaging project ... |
| 247 | +Name : test |
| 248 | +Version : 0.1.0 |
| 249 | +Description: Add your description here |
| 250 | +Authors : Your Name |
| 251 | +✓ Project successfully packaged. |
| 252 | +``` |
| 253 | + |
| 254 | +### Publish To My Workspace |
| 255 | + |
| 256 | +<!-- termynal --> |
| 257 | + |
| 258 | +```shell |
| 259 | +> uipath publish --my-workspace |
| 260 | +⠙ Publishing most recent package: my-agent.0.0.1.nupkg ... |
| 261 | +✓ Package published successfully! |
| 262 | +⠦ Getting process information ... |
| 263 | +🔗 Process configuration link: [LINK] |
| 264 | +💡 Use the link above to configure any environment variables |
| 265 | +``` |
| 266 | + |
| 267 | +/// info |
| 268 | +Please note that a process will be auto-created only upon publishing to **my-workspace** package feed. |
| 269 | + /// |
| 270 | + |
| 271 | +Set the environment variables using the provided link: |
| 272 | + |
| 273 | +<picture data-light="quick_start_images/cloud_env_var_light.png" data-dark="quick_start_images/cloud_env_var_dark.png"> |
| 274 | + <source |
| 275 | + media="(prefers-color-scheme: dark)" |
| 276 | + srcset="quick_start_images/cloud_env_var_dark.png" |
| 277 | + /> |
| 278 | + <img |
| 279 | + src="quick_start_images/cloud_env_var_light.png" |
| 280 | + /> |
| 281 | +</picture> |
| 282 | + |
| 283 | +## Invoke the Agent on UiPath Automation Cloud |
| 284 | + |
| 285 | +<!-- termynal --> |
| 286 | + |
| 287 | +```shell |
| 288 | +> uipath invoke agent '{"topic": "UiPath"}' |
| 289 | +⠴ Loading configuration ... |
| 290 | +⠴ Starting job ... |
| 291 | +✨ Job started successfully! |
| 292 | +🔗 Monitor your job here: [LINK] |
| 293 | +``` |
| 294 | + |
| 295 | +Use the provided link to monitor your job and view detailed traces. |
| 296 | + |
| 297 | +<picture data-light="quick_start_images/invoke_output_light.png" data-dark="quick_start_images/invoke_output_dark.png"> |
| 298 | + <source |
| 299 | + media="(prefers-color-scheme: dark)" |
| 300 | + srcset="quick_start_images/invoke_output_dark.png" |
| 301 | + /> |
| 302 | + <img |
| 303 | + src="quick_start_images/invoke_output_light.png" |
| 304 | + /> |
| 305 | +</picture> |
| 306 | + |
| 307 | +### (Optional) Invoke The Agent with a json File as Input |
| 308 | + |
| 309 | +The `invoke` command operates similarly to the `run` command, allowing you to use the same .json file defined |
| 310 | +in the [(Optional) Run the agent with a .json file as input](#optional-run-the-agent-with-a-json-file-as-input) |
| 311 | +section, as agent input: |
| 312 | + |
| 313 | +```shell |
| 314 | +> uipath invoke agent --file input.json |
| 315 | +``` |
| 316 | + |
| 317 | +## Next Steps |
| 318 | + |
| 319 | +Congratulations! You have successfully set up, created, published, and run a UiPath LangChain Agent. 🚀 |
| 320 | + |
| 321 | +For more advanced agents and agent samples, please refer to our [samples section](https://github.com/UiPath/uipath-langchain-python/tree/main/samples) in GitHub. |
0 commit comments