Skip to content

Commit bc5c5d0

Browse files
feat: add attachments support for coded conversational agents
1 parent d85a752 commit bc5c5d0

14 files changed

Lines changed: 231 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-langchain"
3-
version = "0.7.7"
3+
version = "0.7.8"
44
description = "Python SDK that enables developers to build and deploy LangGraph agents to the UiPath Cloud Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

samples/chat-hitl-agent/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from langchain_anthropic import ChatAnthropic
22
from langchain_tavily import TavilySearch
33
from langchain.agents import create_agent
4-
from uipath_langchain.chat import requires_approval
4+
from uipath_langchain.chat.tools import requires_approval
55

66
tavily_tool = TavilySearch(max_results=5)
77

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
UIPATH_ACCESS_TOKEN=YOUR TOKEN HERE
2+
UIPATH_URL=https://alpha.uipath.com/<organization>/<tenant>
3+
OPENAI_API_KEY=your_openai_api_key
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# File Attachments Chat Agent
2+
3+
An AI assistant that reads and analyzes file attachments shared in the conversation.
4+
5+
## Requirements
6+
7+
- Python 3.11+
8+
- OpenAI API key
9+
10+
## Installation
11+
12+
```bash
13+
uv venv -p 3.11 .venv
14+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
15+
uv sync
16+
```
17+
18+
Set your API key as an environment variable in .env
19+
20+
```bash
21+
OPENAI_API_KEY=your_openai_api_key
22+
```
23+
24+
## Usage
25+
26+
**1.** Upload the file to Orchestrator using the [attachments API](https://uipath.github.io/uipath-python/core/attachments/).
27+
28+
**2.** Run the agent, passing the attachment ID and file metadata returned by the upload:
29+
30+
```bash
31+
uipath run agent '{
32+
"messages": [
33+
{
34+
"type": "human",
35+
"content": [
36+
{ "type": "text", "text": "Summarize this document." },
37+
{ "type": "text", "text": "<uip:attachments>[{\"id\": \"{orchestrator_attachment_id}\", \"full_name\": \"{file_name}\", \"mime_type\": \"{file_mime_type}\"}]</uip:attachments>" }
38+
]
39+
}
40+
]
41+
}'
42+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
flowchart TB
2+
__start__(__start__)
3+
model(model)
4+
tools(tools)
5+
__end__(__end__)
6+
__start__ --> model
7+
model --> __end__
8+
model --> tools
9+
tools --> model
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"graphs": {
3+
"agent": "./main.py:graph"
4+
}
5+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from langchain.agents import create_agent
2+
from langchain_openai import ChatOpenAI
3+
4+
from uipath_langchain.chat.tools import AnalyzeAttachmentsTool
5+
6+
system_prompt = """
7+
You are an AI assistant specialized in analyzing user-provided files using the available file analysis tool.
8+
Always use the provided tool to read and analyze any uploaded or referenced file. Never guess or fabricate file contents. If a file is missing or inaccessible, ask the user to upload it again.
9+
10+
When a file is received:
11+
1.Identify the file type.
12+
2.Provide a clear, concise summary.
13+
3.Extract key information relevant to the user’s request.
14+
4.Highlight important patterns, issues, or insights when applicable.
15+
5.If the user’s request is unclear, ask a focused clarification question before proceeding.
16+
17+
For follow-up questions:
18+
1.Base all answers strictly on the file contents.
19+
2.Maintain context across the conversation.
20+
3.Perform deeper analysis, comparisons, transformations, or extractions as requested.
21+
4.Clearly distinguish between observed facts and inferred insights. If something cannot be determined from the file, state that explicitly.
22+
23+
Keep responses structured, concise, and professional. Treat all file data as sensitive and do not retain or reuse it outside the current conversation.
24+
"""
25+
26+
llm = ChatOpenAI(model="gpt-4.1")
27+
28+
graph = create_agent(
29+
llm,
30+
tools=[AnalyzeAttachmentsTool(llm=llm)],
31+
system_prompt=system_prompt,
32+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "file-attachments-chat-agent"
3+
version = "0.0.1"
4+
description = "file-attachments-chat-agent"
5+
authors = [{ name = "John Doe", email = "john.doe@myemail.com" }]
6+
dependencies = [
7+
"langchain-openai>=1.1.9",
8+
"uipath-langchain",
9+
]
10+
requires-python = ">=3.11"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://cloud.uipath.com/draft/2024-12/uipath",
3+
"runtimeOptions": {
4+
"isConversational": true
5+
},
6+
"packOptions": {
7+
"fileExtensionsIncluded": [],
8+
"filesIncluded": [],
9+
"filesExcluded": [],
10+
"directoriesExcluded": [],
11+
"includeUvLock": true
12+
},
13+
"functions": {}
14+
}

src/uipath_langchain/chat/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ def __getattr__(name):
2626

2727
return UiPathChatOpenAI
2828
if name == "requires_approval":
29-
from .hitl import requires_approval
29+
from .tools.hitl import requires_approval
3030

3131
return requires_approval
32+
if name == "AnalyzeAttachmentsTool":
33+
from .tools.attachments import AnalyzeAttachmentsTool
34+
35+
return AnalyzeAttachmentsTool
3236
if name in ("OpenAIModels", "BedrockModels", "GeminiModels"):
3337
from . import supported_models
3438

@@ -50,4 +54,6 @@ def __getattr__(name):
5054
"requires_approval",
5155
"LLMProvider",
5256
"APIFlavor",
57+
"requires_approval",
58+
"AnalyzeAttachmentsTool",
5359
]

0 commit comments

Comments
 (0)