|
| 1 | +# UiPath Coded Agent: Asset Value Checker |
| 2 | + |
| 3 | +This project demonstrates how to create a Python-based UiPath Coded Agent that connects as an External Application to UiPath Orchestrator, retrieves an asset, and validates its IntValue against custom rules. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The agent uses the UiPath Python SDK to: |
| 8 | + |
| 9 | +* Connect to UiPath Orchestrator as an external application |
| 10 | +* Authenticate via the Client Credentials flow (Client ID + Client Secret) |
| 11 | +* Retrieve a specific asset from a given folder |
| 12 | +* Check whether the asset has an integer value and validate it against a range (100–1000) |
| 13 | +* Return a descriptive message with the validation result |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +* [UV package manager](https://docs.astral.sh/uv/) installed |
| 18 | +* UiPath Orchestrator access |
| 19 | +* An External Application configured in UiPath with the `OR.Assets` scope |
| 20 | + |
| 21 | +You can learn how to create and setup your own External Application from the [UiPath documentation](https://docs.uipath.com/automation-cloud/automation-cloud/latest/admin-guide/managing-external-applications). |
| 22 | + |
| 23 | +## Setup |
| 24 | + |
| 25 | +### Step 1: Create and Activate Virtual Environment |
| 26 | + |
| 27 | +```bash |
| 28 | +uv venv |
| 29 | +``` |
| 30 | + |
| 31 | +Activate the virtual environment: |
| 32 | +- **Windows**: `.venv\Scripts\activate` |
| 33 | +- **Linux/Mac**: `source .venv/bin/activate` |
| 34 | + |
| 35 | +### Step 2: Install Dependencies |
| 36 | + |
| 37 | +```bash |
| 38 | +uv sync |
| 39 | +``` |
| 40 | + |
| 41 | +### Step 3: Configure the Application |
| 42 | + |
| 43 | +1. **Edit `main.py`** (lines 13, 16) and replace the placeholder values: |
| 44 | + - `UIPATH_CLIENT_ID`: Replace `"EXTERNAL_APP_CLIENT_ID_HERE"` with your External Application's Client ID |
| 45 | + - `UIPATH_URL`: Replace `"base_url"` with your Orchestrator URL (e.g., `"https://cloud.uipath.com/your_org/your_tenant"`) |
| 46 | + |
| 47 | +2. **Set Environment Variables** |
| 48 | + |
| 49 | + Create a `.env` file in the project directory or set the environment variable: |
| 50 | + ```bash |
| 51 | + UIPATH_CLIENT_SECRET=your-client-secret-here |
| 52 | + ``` |
| 53 | + |
| 54 | +### Step 4: Initialize the Agent |
| 55 | + |
| 56 | +```bash |
| 57 | +uv run uipath init |
| 58 | +``` |
| 59 | + |
| 60 | +### Step 5: Prepare Input Data |
| 61 | + |
| 62 | +Format your `input.json` file with the following structure: |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "asset_name": "test-asset", |
| 67 | + "folder_path": "TestFolder" |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +**Input Parameters:** |
| 72 | +- `asset_name`: The name of the UiPath asset to validate |
| 73 | +- `folder_path`: The folder path in Orchestrator where the asset is located |
| 74 | + |
| 75 | +### Step 6: Run the Agent |
| 76 | + |
| 77 | +Execute the agent locally: |
| 78 | + |
| 79 | +```bash |
| 80 | +uipath run --input-file input.json |
| 81 | +``` |
| 82 | + |
| 83 | +## How It Works |
| 84 | + |
| 85 | +When this agent runs, it will: |
| 86 | + |
| 87 | +1. Load input values (`asset_name` and `folder_path`) |
| 88 | +2. Connect to Orchestrator using Client Credentials authentication |
| 89 | +3. Retrieve the specified asset from the given folder |
| 90 | +4. Validate the asset's IntValue against the allowed range (100–1000) |
| 91 | +5. Return a descriptive message with the validation result |
| 92 | + |
| 93 | +**Possible Outputs:** |
| 94 | +- "Asset not found." — Asset doesn't exist |
| 95 | +- "Asset does not have an IntValue." — Asset exists but has no integer value |
| 96 | +- "Asset '<name>' has a valid IntValue: <value>" — IntValue is within range |
| 97 | +- "Asset '<name>' has an out-of-range IntValue: <value>" — IntValue is outside range |
| 98 | + |
| 99 | +## Publish Your Coded Agent |
| 100 | + |
| 101 | +Once tested locally, publish your agent to Orchestrator: |
| 102 | + |
| 103 | +1. Pack the agent: |
| 104 | + ```bash |
| 105 | + uipath pack |
| 106 | + ``` |
| 107 | + |
| 108 | +2. Publish to Orchestrator: |
| 109 | + ```bash |
| 110 | + uipath publish |
| 111 | + ``` |
| 112 | + |
0 commit comments