Skip to content

Commit cc4f919

Browse files
authored
Merge pull request #58 from TuanaCelik/main
LlamaCloud example
2 parents 8169c81 + 5d4c6ea commit cc4f919

10 files changed

Lines changed: 705 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# OpenAI Configuration
2+
OPENAI_API_KEY=your_openai_api_key_here
3+
4+
# LlamaCloud Configuration
5+
LLAMACLOUD_API_KEY=your_llamacloud_api_key
6+
LLAMACLOUD_ORG_ID=your_llamacloud_org_id
7+
LLAMACLOUD_PROJECT_NAME=your_llamacloud_project_name
8+
9+
# LlamaCloud Index Configuration
10+
# Index 1: Company Travel Policies and Rates
11+
LLAMACLOUD_INDEX_1_NAME=company-policies
12+
LLAMACLOUD_INDEX_1_DESCRIPTION="Information about company travel rates per states/cities and general company policy"
13+
14+
# Index 2: Personal Travel Preferences
15+
LLAMACLOUD_INDEX_2_NAME=personal-preferences
16+
LLAMACLOUD_INDEX_2_DESCRIPTION="Information about user's personal preferences"
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Quickstart LlamaCloud Agent
2+
3+
This project demonstrates how to integrate UiPath with LlamaIndex and LlamaCloud for document search and travel assistance workflows using a FunctionAgent.
4+
5+
## Overview
6+
7+
The Quickstart LlamaCloud Agent provides a FunctionAgent that can:
8+
1. Search company travel policies and rates from the `company-policy` index
9+
2. Search user's personal travel preferences from the `personal-preferences` index
10+
3. Generate comprehensive travel recommendations combining both sources
11+
4. Deploy as a UiPath agent for automation workflows
12+
13+
## Features
14+
15+
- **FunctionAgent Architecture**: Uses LlamaIndex's FunctionAgent for intelligent tool selection
16+
- **Dual Index Search**: Searches both company policies and personal preferences
17+
- **Smart Tool Selection**: Automatically chooses the right tools based on user queries
18+
- **Comprehensive Travel Guidance**: Combines policy and preference information
19+
- **UiPath Integration**: Ready for deployment to UiPath Cloud
20+
21+
## Prerequisites
22+
23+
- Python 3.10+
24+
- UiPath Cloud account
25+
- OpenAI API key
26+
- LlamaCloud account with API access
27+
28+
## Setup
29+
30+
31+
### 1. Set Up Virtual Environment
32+
33+
We recommend using `uv` for package management:
34+
35+
```bash
36+
# Initialize a new uv project
37+
uv init .
38+
39+
# Create and activate virtual environment
40+
uv venv
41+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
42+
```
43+
44+
Alternatively, use `pip`:
45+
46+
```bash
47+
# Create virtual environment
48+
python -m venv .venv
49+
50+
# Activate virtual environment
51+
# On Windows PowerShell: .venv\Scripts\Activate.ps1
52+
# On Windows CMD: .venv\Scripts\activate
53+
# On macOS/Linux: source .venv/bin/activate
54+
source .venv/bin/activate
55+
56+
# Upgrade pip
57+
python -m pip install --upgrade pip
58+
```
59+
60+
### 2. Install Dependencies
61+
62+
```bash
63+
# Install the project dependencies
64+
pip install -e .
65+
```
66+
67+
### 3. Configure Environment Variables
68+
69+
```bash
70+
# Copy the example environment file
71+
cp .env.example .env
72+
73+
# Edit .env with your actual API keys and configuration
74+
```
75+
76+
Required environment variables:
77+
- `OPENAI_API_KEY`: Your OpenAI API key
78+
- `LLAMACLOUD_API_KEY`: Your LlamaCloud API key
79+
- `LLAMACLOUD_ORG_ID`: Your LlamaCloud organization ID
80+
- `LLAMACLOUD_PROJECT_NAME`: Your LlamaCloud project name
81+
- `LLAMACLOUD_INDEX_1_NAME`: First index name (e.g., "company_policy")
82+
- `LLAMACLOUD_INDEX_2_NAME`: Second index name (e.g., "personal_preferences")
83+
84+
### 4. Configure LlamaCloud Indexes
85+
86+
- Set up your indexes in LlamaCloud with the names specified in your `.env` file
87+
- You can drag and drop the files in `/sample_data` into the relevant indexes
88+
- Update the project name and organization ID in your `.env` file
89+
- Ensure your API key has access to the specified indexes
90+
91+
## Available Functions
92+
93+
The agent has access to three main functions:
94+
95+
### 1. `search_company_policy(query: str)`
96+
Searches the company policy index for travel rates, guidelines, and company policies.
97+
- **Use case**: "What are the travel rates for New York?"
98+
- **Returns**: Company policy information with source files and relevance scores
99+
100+
### 2. `search_personal_preferences(query: str)`
101+
Searches the personal preferences index for user's travel preferences and requirements.
102+
- **Use case**: "What are my travel preferences?"
103+
- **Returns**: Personal preference information with source files and relevance scores
104+
105+
### 3. `get_travel_recommendation(query: str)`
106+
Generates comprehensive travel recommendations combining both company policies and personal preferences.
107+
- **Use case**: "Give me travel recommendations for a business trip"
108+
- **Returns**: Combined analysis from both indexes
109+
110+
## Usage
111+
112+
### Local Testing
113+
114+
115+
#### Using UiPath CLI (Recommended)
116+
117+
```bash
118+
# Run the agent with a query
119+
uipath run agent '{"query": "What are the travel rates for New York?"}'
120+
```
121+
122+
#### Option 3: Using Input File
123+
124+
Create an `input.json` file:
125+
126+
```json
127+
{
128+
"user_msg": "What are the travel rates for California?"
129+
}
130+
```
131+
132+
133+
### UiPath Deployment
134+
135+
1. **Authenticate with UiPath:**
136+
```bash
137+
uipath auth
138+
```
139+
140+
2. **Package your project:**
141+
```bash
142+
uipath pack
143+
```
144+
145+
3. **Publish to UiPath Cloud:**
146+
```bash
147+
uipath publish --my-workspace
148+
```
149+
150+
4. **Invoke the agent:**
151+
```bash
152+
uipath invoke agent '{"user_msg": "What are the travel rates for New York?"}'
153+
```
154+
155+
156+
## Example Queries
157+
158+
- "What are the travel rates for California?"
159+
- "What are my travel preferences?"
160+
- "Give me travel recommendations for a business trip to New York"
161+
- "What are the company travel guidelines?"
162+
- "What are my personal travel requirements?"
163+
164+
## Dependencies
165+
166+
- `uipath-llamaindex`: UiPath LlamaIndex integration
167+
- `llama-index-llms-openai`: OpenAI LLM integration
168+
- `llama-cloud-services`: LlamaCloud integration
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"dependencies": ["."],
3+
"workflows": {
4+
"agent": "main.py:agent"
5+
},
6+
"env": ".env"
7+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import os
2+
from typing import List
3+
from dotenv import load_dotenv
4+
5+
from llama_index.core.agent.workflow import FunctionAgent
6+
from llama_index.llms.openai import OpenAI
7+
from llama_index.indices.managed.llama_cloud import LlamaCloudIndex
8+
9+
load_dotenv()
10+
11+
# Initialize LlamaCloud Index connections
12+
company_policy_index = LlamaCloudIndex(
13+
name=os.getenv("LLAMACLOUD_INDEX_1_NAME"),
14+
project_name=os.getenv("LLAMACLOUD_PROJECT_NAME"),
15+
organization_id=os.getenv("LLAMACLOUD_ORG_ID"),
16+
api_key=os.getenv("LLAMACLOUD_API_KEY")
17+
)
18+
19+
personal_preferences_index = LlamaCloudIndex(
20+
name=os.getenv("LLAMACLOUD_INDEX_2_NAME"),
21+
project_name=os.getenv("LLAMACLOUD_PROJECT_NAME"),
22+
organization_id=os.getenv("LLAMACLOUD_ORG_ID"),
23+
api_key=os.getenv("LLAMACLOUD_API_KEY")
24+
)
25+
26+
llm = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
27+
28+
29+
def search_company_policy(query: str) -> str:
30+
"""
31+
Search the company policy index for travel rates, guidelines, and company policies.
32+
33+
Args:
34+
query (str): The search query about company travel policies, rates, or guidelines
35+
36+
Returns:
37+
str: Relevant information from company policy documents
38+
"""
39+
try:
40+
retriever = company_policy_index.as_retriever()
41+
retrieved_nodes = retriever.retrieve(query)
42+
43+
if not retrieved_nodes:
44+
return "No relevant company policy information found for your query."
45+
46+
# Format the search results
47+
results = []
48+
for i, node in enumerate(retrieved_nodes[:3], 1): # Limit to top 3 results
49+
results.append(f"Result {i}:")
50+
results.append(f" Content: {node.text[:300]}...")
51+
results.append(f" Relevance Score: {node.score:.4f}")
52+
if hasattr(node.node, 'metadata'):
53+
metadata = node.node.metadata
54+
if 'file_name' in metadata:
55+
results.append(f" Source: {metadata['file_name']}")
56+
if 'page_label' in metadata:
57+
results.append(f" Page: {metadata['page_label']}")
58+
results.append("")
59+
60+
return "\n".join(results)
61+
except Exception as e:
62+
return f"Error searching company policy index: {str(e)}"
63+
64+
65+
def search_personal_preferences(query: str) -> str:
66+
"""
67+
Search the personal preferences index for user's travel preferences and requirements.
68+
69+
Args:
70+
query (str): The search query about personal travel preferences or requirements
71+
72+
Returns:
73+
str: Relevant information from personal preference documents
74+
"""
75+
try:
76+
retriever = personal_preferences_index.as_retriever()
77+
retrieved_nodes = retriever.retrieve(query)
78+
79+
if not retrieved_nodes:
80+
return "No relevant personal preference information found for your query."
81+
82+
# Format the search results
83+
results = []
84+
for i, node in enumerate(retrieved_nodes[:3], 1): # Limit to top 3 results
85+
results.append(f"Result {i}:")
86+
results.append(f" Content: {node.text[:300]}...")
87+
results.append(f" Relevance Score: {node.score:.4f}")
88+
if hasattr(node.node, 'metadata'):
89+
metadata = node.node.metadata
90+
if 'file_name' in metadata:
91+
results.append(f" Source: {metadata['file_name']}")
92+
if 'page_label' in metadata:
93+
results.append(f" Page: {metadata['page_label']}")
94+
results.append("")
95+
96+
return "\n".join(results)
97+
except Exception as e:
98+
return f"Error searching personal preferences index: {str(e)}"
99+
100+
101+
def get_travel_recommendation(query: str) -> str:
102+
"""
103+
Get travel recommendations based on company policies and personal preferences.
104+
105+
Args:
106+
query (str): The travel-related query or request for recommendations
107+
108+
Returns:
109+
str: Travel recommendations combining policy and preference information
110+
"""
111+
try:
112+
# Search both indexes for comprehensive information
113+
policy_info = search_company_policy(query)
114+
preference_info = search_personal_preferences(query)
115+
116+
recommendation = f"""
117+
Travel Recommendation Analysis:
118+
119+
Company Policy Information:
120+
{policy_info}
121+
122+
Personal Preference Information:
123+
{preference_info}
124+
125+
Based on the above information, here are the key considerations for your travel request.
126+
"""
127+
128+
return recommendation.strip()
129+
except Exception as e:
130+
return f"Error generating travel recommendation: {str(e)}"
131+
132+
133+
# Create the FunctionAgent with our tools
134+
agent = FunctionAgent(
135+
tools=[search_company_policy, search_personal_preferences, get_travel_recommendation],
136+
llm=llm,
137+
system_prompt="""You are a helpful travel assistant that can search through company travel policies and personal preferences to provide comprehensive travel guidance.
138+
139+
You have access to three main functions:
140+
1. search_company_policy - Search for company travel rates, guidelines, and policies
141+
2. search_personal_preferences - Search for user's personal travel preferences and requirements
142+
3. get_travel_recommendation - Get comprehensive travel recommendations combining both sources
143+
144+
Use these tools to help users with travel-related queries, ensuring you provide accurate information from both company policies and personal preferences when relevant."""
145+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "quickstart-llamacloud"
3+
version = "0.0.2"
4+
description = "UiPath LlamaIndex Quickstart with LlamaCloud Integration"
5+
authors = [{ name = "Tuana Celik", email = "tuana@runllama.ai" }]
6+
readme = { file = "README.md", content-type = "text/markdown" }
7+
requires-python = ">=3.10"
8+
dependencies = [
9+
"uipath-llamaindex>=0.0.11",
10+
"llama-index-llms-openai>=0.2.2",
11+
"llama-cloud-services"
12+
]
Binary file not shown.

0 commit comments

Comments
 (0)