uipath-langchain 0.0.133__py3-none-any.whl → 0.1.28__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uipath_langchain/_cli/cli_init.py +130 -191
- uipath_langchain/_cli/cli_new.py +2 -3
- uipath_langchain/_resources/AGENTS.md +21 -0
- uipath_langchain/_resources/REQUIRED_STRUCTURE.md +92 -0
- uipath_langchain/_tracing/__init__.py +3 -2
- uipath_langchain/_tracing/_instrument_traceable.py +11 -12
- uipath_langchain/_utils/_request_mixin.py +327 -51
- uipath_langchain/_utils/_settings.py +2 -2
- uipath_langchain/agent/exceptions/__init__.py +6 -0
- uipath_langchain/agent/exceptions/exceptions.py +11 -0
- uipath_langchain/agent/guardrails/__init__.py +21 -0
- uipath_langchain/agent/guardrails/actions/__init__.py +11 -0
- uipath_langchain/agent/guardrails/actions/base_action.py +24 -0
- uipath_langchain/agent/guardrails/actions/block_action.py +42 -0
- uipath_langchain/agent/guardrails/actions/escalate_action.py +499 -0
- uipath_langchain/agent/guardrails/actions/log_action.py +58 -0
- uipath_langchain/agent/guardrails/guardrail_nodes.py +173 -0
- uipath_langchain/agent/guardrails/guardrails_factory.py +70 -0
- uipath_langchain/agent/guardrails/guardrails_subgraph.py +283 -0
- uipath_langchain/agent/guardrails/types.py +20 -0
- uipath_langchain/agent/react/__init__.py +14 -0
- uipath_langchain/agent/react/agent.py +117 -0
- uipath_langchain/agent/react/constants.py +2 -0
- uipath_langchain/agent/react/init_node.py +20 -0
- uipath_langchain/agent/react/llm_node.py +43 -0
- uipath_langchain/agent/react/router.py +97 -0
- uipath_langchain/agent/react/terminate_node.py +82 -0
- uipath_langchain/agent/react/tools/__init__.py +7 -0
- uipath_langchain/agent/react/tools/tools.py +50 -0
- uipath_langchain/agent/react/types.py +39 -0
- uipath_langchain/agent/react/utils.py +49 -0
- uipath_langchain/agent/tools/__init__.py +17 -0
- uipath_langchain/agent/tools/context_tool.py +53 -0
- uipath_langchain/agent/tools/escalation_tool.py +111 -0
- uipath_langchain/agent/tools/integration_tool.py +181 -0
- uipath_langchain/agent/tools/process_tool.py +49 -0
- uipath_langchain/agent/tools/static_args.py +138 -0
- uipath_langchain/agent/tools/structured_tool_with_output_type.py +14 -0
- uipath_langchain/agent/tools/tool_factory.py +45 -0
- uipath_langchain/agent/tools/tool_node.py +22 -0
- uipath_langchain/agent/tools/utils.py +11 -0
- uipath_langchain/chat/__init__.py +4 -0
- uipath_langchain/chat/bedrock.py +187 -0
- uipath_langchain/chat/mapper.py +309 -0
- uipath_langchain/chat/models.py +248 -35
- uipath_langchain/chat/openai.py +133 -0
- uipath_langchain/chat/supported_models.py +42 -0
- uipath_langchain/chat/vertex.py +255 -0
- uipath_langchain/embeddings/embeddings.py +131 -34
- uipath_langchain/middlewares.py +0 -6
- uipath_langchain/retrievers/context_grounding_retriever.py +7 -9
- uipath_langchain/runtime/__init__.py +36 -0
- uipath_langchain/runtime/_serialize.py +46 -0
- uipath_langchain/runtime/config.py +61 -0
- uipath_langchain/runtime/errors.py +43 -0
- uipath_langchain/runtime/factory.py +315 -0
- uipath_langchain/runtime/graph.py +159 -0
- uipath_langchain/runtime/runtime.py +453 -0
- uipath_langchain/runtime/schema.py +386 -0
- uipath_langchain/runtime/storage.py +115 -0
- uipath_langchain/vectorstores/context_grounding_vectorstore.py +90 -110
- {uipath_langchain-0.0.133.dist-info → uipath_langchain-0.1.28.dist-info}/METADATA +44 -23
- uipath_langchain-0.1.28.dist-info/RECORD +76 -0
- {uipath_langchain-0.0.133.dist-info → uipath_langchain-0.1.28.dist-info}/WHEEL +1 -1
- uipath_langchain-0.1.28.dist-info/entry_points.txt +5 -0
- uipath_langchain/_cli/_runtime/_context.py +0 -21
- uipath_langchain/_cli/_runtime/_conversation.py +0 -298
- uipath_langchain/_cli/_runtime/_exception.py +0 -17
- uipath_langchain/_cli/_runtime/_input.py +0 -139
- uipath_langchain/_cli/_runtime/_output.py +0 -234
- uipath_langchain/_cli/_runtime/_runtime.py +0 -379
- uipath_langchain/_cli/_utils/_graph.py +0 -199
- uipath_langchain/_cli/cli_dev.py +0 -44
- uipath_langchain/_cli/cli_eval.py +0 -78
- uipath_langchain/_cli/cli_run.py +0 -82
- uipath_langchain/_tracing/_oteladapter.py +0 -222
- uipath_langchain/_tracing/_utils.py +0 -28
- uipath_langchain/builder/agent_config.py +0 -191
- uipath_langchain/tools/preconfigured.py +0 -191
- uipath_langchain-0.0.133.dist-info/RECORD +0 -41
- uipath_langchain-0.0.133.dist-info/entry_points.txt +0 -2
- /uipath_langchain/{tools/__init__.py → py.typed} +0 -0
- {uipath_langchain-0.0.133.dist-info → uipath_langchain-0.1.28.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,105 +1,144 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
import
|
|
2
|
+
import importlib.resources
|
|
3
3
|
import os
|
|
4
|
-
import
|
|
5
|
-
from
|
|
4
|
+
import shutil
|
|
5
|
+
from collections.abc import Generator
|
|
6
|
+
from enum import Enum
|
|
7
|
+
from typing import Any
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
import click
|
|
8
10
|
from uipath._cli._utils._console import ConsoleLogger
|
|
9
|
-
from uipath._cli._utils._parse_ast import generate_bindings_json # type: ignore
|
|
10
11
|
from uipath._cli.middlewares import MiddlewareResult
|
|
11
12
|
|
|
12
|
-
from .
|
|
13
|
+
from uipath_langchain.runtime.config import LangGraphConfig
|
|
13
14
|
|
|
14
15
|
console = ConsoleLogger()
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
18
|
+
class FileOperationStatus(str, Enum):
|
|
19
|
+
"""Status of a file operation."""
|
|
20
|
+
|
|
21
|
+
CREATED = "created"
|
|
22
|
+
UPDATED = "updated"
|
|
23
|
+
SKIPPED = "skipped"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def generate_agent_md_file(
|
|
27
|
+
target_directory: str,
|
|
28
|
+
file_name: str,
|
|
29
|
+
resource_name: str,
|
|
30
|
+
no_agents_md_override: bool,
|
|
31
|
+
) -> tuple[str, FileOperationStatus] | None:
|
|
32
|
+
"""Generate an agent-specific file from the packaged resource.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
target_directory: The directory where the file should be created.
|
|
36
|
+
file_name: The name of the file should be created.
|
|
37
|
+
resource_name: The name of the resource folder where should be the file.
|
|
38
|
+
no_agents_md_override: Whether to override existing files.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
A tuple of (file_name, status) where status is a FileOperationStatus:
|
|
42
|
+
- CREATED: File was created
|
|
43
|
+
- UPDATED: File was overwritten
|
|
44
|
+
- SKIPPED: File exists and no_agents_md_override is True
|
|
45
|
+
Returns None if an error occurred.
|
|
46
|
+
"""
|
|
47
|
+
target_path = os.path.join(target_directory, file_name)
|
|
48
|
+
will_override = os.path.exists(target_path)
|
|
49
|
+
|
|
50
|
+
if will_override and no_agents_md_override:
|
|
51
|
+
return file_name, FileOperationStatus.SKIPPED
|
|
52
|
+
try:
|
|
53
|
+
source_path = importlib.resources.files(resource_name).joinpath(file_name)
|
|
54
|
+
|
|
55
|
+
with importlib.resources.as_file(source_path) as s_path:
|
|
56
|
+
shutil.copy(s_path, target_path)
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
file_name,
|
|
60
|
+
FileOperationStatus.UPDATED
|
|
61
|
+
if will_override
|
|
62
|
+
else FileOperationStatus.CREATED,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
except Exception as e:
|
|
66
|
+
console.warning(f"Could not create {file_name}: {e}")
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def generate_specific_agents_md_files(
|
|
71
|
+
target_directory: str, no_agents_md_override: bool
|
|
72
|
+
) -> Generator[tuple[str, FileOperationStatus], None, None]:
|
|
73
|
+
"""Generate agent-specific files from the packaged resource.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
target_directory: The directory where the files should be created.
|
|
77
|
+
no_agents_md_override: Whether to override existing files.
|
|
78
|
+
|
|
79
|
+
Yields:
|
|
80
|
+
Tuple of (file_name, status) for each file operation, where status is a FileOperationStatus:
|
|
81
|
+
- CREATED: File was created
|
|
82
|
+
- UPDATED: File was overwritten
|
|
83
|
+
- SKIPPED: File exists and was not overwritten
|
|
84
|
+
"""
|
|
85
|
+
agent_dir = os.path.join(target_directory, ".agent")
|
|
86
|
+
os.makedirs(agent_dir, exist_ok=True)
|
|
87
|
+
|
|
88
|
+
file_configs = [
|
|
89
|
+
(target_directory, "CLAUDE.md", "uipath._resources"),
|
|
90
|
+
(agent_dir, "CLI_REFERENCE.md", "uipath._resources"),
|
|
91
|
+
(agent_dir, "SDK_REFERENCE.md", "uipath._resources"),
|
|
92
|
+
(target_directory, "AGENTS.md", "uipath_langchain._resources"),
|
|
93
|
+
(agent_dir, "REQUIRED_STRUCTURE.md", "uipath_langchain._resources"),
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
for directory, file_name, resource_name in file_configs:
|
|
97
|
+
result = generate_agent_md_file(
|
|
98
|
+
directory, file_name, resource_name, no_agents_md_override
|
|
99
|
+
)
|
|
100
|
+
if result:
|
|
101
|
+
yield result
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def generate_agents_md_files(options: dict[str, Any]) -> None:
|
|
105
|
+
"""Generate agent MD files and log categorized summary.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
options: Options dictionary
|
|
109
|
+
"""
|
|
110
|
+
current_directory = os.getcwd()
|
|
111
|
+
no_agents_md_override = options.get("no_agents_md_override", False)
|
|
112
|
+
|
|
113
|
+
created_files = []
|
|
114
|
+
updated_files = []
|
|
115
|
+
skipped_files = []
|
|
116
|
+
|
|
117
|
+
for file_name, status in generate_specific_agents_md_files(
|
|
118
|
+
current_directory, no_agents_md_override
|
|
119
|
+
):
|
|
120
|
+
if status == FileOperationStatus.CREATED:
|
|
121
|
+
created_files.append(file_name)
|
|
122
|
+
elif status == FileOperationStatus.UPDATED:
|
|
123
|
+
updated_files.append(file_name)
|
|
124
|
+
elif status == FileOperationStatus.SKIPPED:
|
|
125
|
+
skipped_files.append(file_name)
|
|
126
|
+
|
|
127
|
+
if created_files:
|
|
128
|
+
files_str = ", ".join(click.style(f, fg="cyan") for f in created_files)
|
|
129
|
+
console.success(f"Created: {files_str}")
|
|
130
|
+
|
|
131
|
+
if updated_files:
|
|
132
|
+
files_str = ", ".join(click.style(f, fg="cyan") for f in updated_files)
|
|
133
|
+
console.success(f"Updated: {files_str}")
|
|
134
|
+
|
|
135
|
+
if skipped_files:
|
|
136
|
+
files_str = ", ".join(click.style(f, fg="yellow") for f in skipped_files)
|
|
137
|
+
console.info(f"Skipped (already exist): {files_str}")
|
|
97
138
|
|
|
98
139
|
|
|
99
140
|
async def langgraph_init_middleware_async(
|
|
100
|
-
entrypoint: str,
|
|
101
141
|
options: dict[str, Any] | None = None,
|
|
102
|
-
write_config: Callable[[Any], str] | None = None,
|
|
103
142
|
) -> MiddlewareResult:
|
|
104
143
|
"""Middleware to check for langgraph.json and create uipath.json with schemas"""
|
|
105
144
|
options = options or {}
|
|
@@ -111,90 +150,8 @@ async def langgraph_init_middleware_async(
|
|
|
111
150
|
) # Continue with normal flow if no langgraph.json
|
|
112
151
|
|
|
113
152
|
try:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
all_bindings = {"version": "2.0", "resources": []}
|
|
117
|
-
mermaids = {}
|
|
118
|
-
|
|
119
|
-
for graph in config.graphs:
|
|
120
|
-
if entrypoint and graph.name != entrypoint:
|
|
121
|
-
continue
|
|
122
|
-
|
|
123
|
-
try:
|
|
124
|
-
loaded_graph = await graph.load_graph()
|
|
125
|
-
state_graph = (
|
|
126
|
-
loaded_graph.builder
|
|
127
|
-
if isinstance(loaded_graph, CompiledStateGraph)
|
|
128
|
-
else loaded_graph
|
|
129
|
-
)
|
|
130
|
-
compiled_graph = state_graph.compile()
|
|
131
|
-
graph_schema = generate_schema_from_graph(compiled_graph)
|
|
132
|
-
|
|
133
|
-
mermaids[graph.name] = compiled_graph.get_graph(xray=1).draw_mermaid()
|
|
134
|
-
|
|
135
|
-
try:
|
|
136
|
-
should_infer_bindings = options.get("infer_bindings", True)
|
|
137
|
-
# Make sure the file path exists
|
|
138
|
-
if os.path.exists(graph.file_path) and should_infer_bindings:
|
|
139
|
-
file_bindings = generate_bindings_json(graph.file_path)
|
|
140
|
-
|
|
141
|
-
# Merge bindings
|
|
142
|
-
if "resources" in file_bindings:
|
|
143
|
-
all_bindings["resources"] = file_bindings["resources"]
|
|
144
|
-
except Exception as e:
|
|
145
|
-
console.warning(
|
|
146
|
-
f"Warning: Could not generate bindings for {graph.file_path}: {str(e)}"
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
new_entrypoint: dict[str, Any] = {
|
|
150
|
-
"filePath": graph.name,
|
|
151
|
-
"uniqueId": str(uuid.uuid4()),
|
|
152
|
-
"type": "agent",
|
|
153
|
-
"input": graph_schema["input"],
|
|
154
|
-
"output": graph_schema["output"],
|
|
155
|
-
}
|
|
156
|
-
entrypoints.append(new_entrypoint)
|
|
157
|
-
|
|
158
|
-
except Exception as e:
|
|
159
|
-
console.error(f"Error during graph load: {e}")
|
|
160
|
-
return MiddlewareResult(
|
|
161
|
-
should_continue=False,
|
|
162
|
-
should_include_stacktrace=True,
|
|
163
|
-
)
|
|
164
|
-
finally:
|
|
165
|
-
await graph.cleanup()
|
|
166
|
-
|
|
167
|
-
if entrypoint and not entrypoints:
|
|
168
|
-
console.error(f"Error: No graph found with name '{entrypoint}'")
|
|
169
|
-
return MiddlewareResult(
|
|
170
|
-
should_continue=False,
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
uipath_config = {"entryPoints": entrypoints, "bindings": all_bindings}
|
|
174
|
-
|
|
175
|
-
if write_config:
|
|
176
|
-
config_path = write_config(uipath_config)
|
|
177
|
-
else:
|
|
178
|
-
# Save the uipath.json file
|
|
179
|
-
config_path = "uipath.json"
|
|
180
|
-
with open(config_path, "w") as f:
|
|
181
|
-
json.dump(uipath_config, f, indent=4)
|
|
182
|
-
|
|
183
|
-
for graph_name, mermaid_content in mermaids.items():
|
|
184
|
-
mermaid_file_path = f"{graph_name}.mermaid"
|
|
185
|
-
try:
|
|
186
|
-
with open(mermaid_file_path, "w") as f:
|
|
187
|
-
f.write(mermaid_content)
|
|
188
|
-
console.success(f" Created '{mermaid_file_path}' file.")
|
|
189
|
-
except Exception as write_error:
|
|
190
|
-
console.error(
|
|
191
|
-
f"Error writing mermaid file for '{graph_name}': {str(write_error)}"
|
|
192
|
-
)
|
|
193
|
-
return MiddlewareResult(
|
|
194
|
-
should_continue=False,
|
|
195
|
-
should_include_stacktrace=True,
|
|
196
|
-
)
|
|
197
|
-
console.success(f" Created '{config_path}' file.")
|
|
153
|
+
generate_agents_md_files(options)
|
|
154
|
+
|
|
198
155
|
return MiddlewareResult(should_continue=False)
|
|
199
156
|
|
|
200
157
|
except Exception as e:
|
|
@@ -205,26 +162,8 @@ async def langgraph_init_middleware_async(
|
|
|
205
162
|
)
|
|
206
163
|
|
|
207
164
|
|
|
208
|
-
@overload
|
|
209
|
-
def langgraph_init_middleware(
|
|
210
|
-
entrypoint: str,
|
|
211
|
-
) -> MiddlewareResult: ...
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
@overload
|
|
215
|
-
def langgraph_init_middleware(
|
|
216
|
-
entrypoint: str,
|
|
217
|
-
options: dict[str, Any],
|
|
218
|
-
write_config: Callable[[Any], str],
|
|
219
|
-
) -> MiddlewareResult: ...
|
|
220
|
-
|
|
221
|
-
|
|
222
165
|
def langgraph_init_middleware(
|
|
223
|
-
entrypoint: str,
|
|
224
166
|
options: dict[str, Any] | None = None,
|
|
225
|
-
write_config: Callable[[Any], str] | None = None,
|
|
226
167
|
) -> MiddlewareResult:
|
|
227
168
|
"""Middleware to check for langgraph.json and create uipath.json with schemas"""
|
|
228
|
-
return asyncio.run(
|
|
229
|
-
langgraph_init_middleware_async(entrypoint, options, write_config)
|
|
230
|
-
)
|
|
169
|
+
return asyncio.run(langgraph_init_middleware_async(options))
|
uipath_langchain/_cli/cli_new.py
CHANGED
|
@@ -31,10 +31,9 @@ version = "0.0.1"
|
|
|
31
31
|
description = "{project_name}"
|
|
32
32
|
authors = [{{ name = "John Doe", email = "john.doe@myemail.com" }}]
|
|
33
33
|
dependencies = [
|
|
34
|
-
"uipath-langchain>=0.0
|
|
35
|
-
"langchain-anthropic>=0.3.8",
|
|
34
|
+
"uipath-langchain>=0.1.0",
|
|
36
35
|
]
|
|
37
|
-
requires-python = ">=3.
|
|
36
|
+
requires-python = ">=3.11"
|
|
38
37
|
"""
|
|
39
38
|
|
|
40
39
|
with open(project_toml_path, "w") as f:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Agent Code Patterns Reference
|
|
2
|
+
|
|
3
|
+
This document provides practical code patterns for building UiPath coded agents using LangGraph and the UiPath Python SDK.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Documentation Structure
|
|
8
|
+
|
|
9
|
+
This documentation is split into multiple files for efficient context loading. Load only the files you need:
|
|
10
|
+
|
|
11
|
+
1. **@.agent/REQUIRED_STRUCTURE.md** - Agent structure patterns and templates
|
|
12
|
+
- **When to load:** Creating a new agent or understanding required patterns
|
|
13
|
+
- **Contains:** Required Pydantic models (Input, State, Output), LLM initialization patterns, standard agent template
|
|
14
|
+
|
|
15
|
+
2. **@.agent/SDK_REFERENCE.md** - Complete SDK API reference
|
|
16
|
+
- **When to load:** Calling UiPath SDK methods, working with services (actions, assets, jobs, etc.)
|
|
17
|
+
- **Contains:** All SDK services and methods with full signatures and type annotations
|
|
18
|
+
|
|
19
|
+
3. **@.agent/CLI_REFERENCE.md** - CLI commands documentation
|
|
20
|
+
- **When to load:** Working with `uipath init`, `uipath run`, or `uipath eval` commands
|
|
21
|
+
- **Contains:** Command syntax, options, usage examples, and workflows
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
## Required Agent Structure
|
|
2
|
+
|
|
3
|
+
**IMPORTANT**: All UiPath coded agents MUST follow this standard structure unless explicitly specified otherwise by the user.
|
|
4
|
+
|
|
5
|
+
### Required Components
|
|
6
|
+
|
|
7
|
+
Every agent implementation MUST include these three Pydantic models:
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pydantic import BaseModel
|
|
11
|
+
|
|
12
|
+
class Input(BaseModel):
|
|
13
|
+
"""Define input fields that the agent accepts"""
|
|
14
|
+
# Add your input fields here
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
class State(BaseModel):
|
|
18
|
+
"""Define the agent's internal state that flows between nodes"""
|
|
19
|
+
# Add your state fields here
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
class Output(BaseModel):
|
|
23
|
+
"""Define output fields that the agent returns"""
|
|
24
|
+
# Add your output fields here
|
|
25
|
+
pass
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Required LLM Initialization
|
|
29
|
+
|
|
30
|
+
Unless the user explicitly requests a different LLM provider, always use `UiPathChat`:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from uipath_langchain.chat import UiPathChat
|
|
34
|
+
|
|
35
|
+
llm = UiPathChat(model="gpt-4o-2024-08-06", temperature=0.7)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Alternative LLMs** (only use if explicitly requested):
|
|
39
|
+
- `ChatOpenAI` from `langchain_openai`
|
|
40
|
+
- `ChatAnthropic` from `langchain_anthropic`
|
|
41
|
+
- Other LangChain-compatible LLMs
|
|
42
|
+
|
|
43
|
+
### Standard Agent Template
|
|
44
|
+
|
|
45
|
+
Every agent should follow this basic structure:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from langchain_core.messages import SystemMessage, HumanMessage
|
|
49
|
+
from langgraph.graph import START, StateGraph, END
|
|
50
|
+
from uipath_langchain.chat import UiPathChat
|
|
51
|
+
from pydantic import BaseModel
|
|
52
|
+
|
|
53
|
+
# 1. Define Input, State, and Output models
|
|
54
|
+
class Input(BaseModel):
|
|
55
|
+
field: str
|
|
56
|
+
|
|
57
|
+
class State(BaseModel):
|
|
58
|
+
field: str
|
|
59
|
+
result: str = ""
|
|
60
|
+
|
|
61
|
+
class Output(BaseModel):
|
|
62
|
+
result: str
|
|
63
|
+
|
|
64
|
+
# 2. Initialize UiPathChat LLM
|
|
65
|
+
llm = UiPathChat(model="gpt-4o-2024-08-06", temperature=0.7)
|
|
66
|
+
|
|
67
|
+
# 3. Define agent nodes (async functions)
|
|
68
|
+
async def process_node(state: State) -> State:
|
|
69
|
+
response = await llm.ainvoke([HumanMessage(state.field)])
|
|
70
|
+
return State(field=state.field, result=response.content)
|
|
71
|
+
|
|
72
|
+
async def output_node(state: State) -> Output:
|
|
73
|
+
return Output(result=state.result)
|
|
74
|
+
|
|
75
|
+
# 4. Build the graph
|
|
76
|
+
builder = StateGraph(State, input=Input, output=Output)
|
|
77
|
+
builder.add_node("process", process_node)
|
|
78
|
+
builder.add_node("output", output_node)
|
|
79
|
+
builder.add_edge(START, "process")
|
|
80
|
+
builder.add_edge("process", "output")
|
|
81
|
+
builder.add_edge("output", END)
|
|
82
|
+
|
|
83
|
+
# 5. Compile the graph
|
|
84
|
+
graph = builder.compile()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Key Rules**:
|
|
88
|
+
1. Always use async/await for all node functions
|
|
89
|
+
2. All nodes (except output) must accept and return `State`
|
|
90
|
+
3. The final output node must return `Output`
|
|
91
|
+
4. Use `StateGraph(State, input=Input, output=Output)` for initialization
|
|
92
|
+
5. Always compile with `graph = builder.compile()`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import importlib
|
|
2
2
|
import logging
|
|
3
3
|
import sys
|
|
4
|
-
from typing import Any, Callable
|
|
4
|
+
from typing import Any, Callable
|
|
5
5
|
|
|
6
6
|
from uipath.tracing import traced
|
|
7
7
|
|
|
@@ -12,14 +12,13 @@ original_traceable: Any = None
|
|
|
12
12
|
logger = logging.getLogger(__name__)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
# Apply the patch
|
|
16
15
|
def _map_traceable_to_traced_args(
|
|
17
|
-
run_type:
|
|
18
|
-
name:
|
|
19
|
-
tags:
|
|
20
|
-
metadata:
|
|
16
|
+
run_type: str | None = None,
|
|
17
|
+
name: str | None = None,
|
|
18
|
+
tags: list[str] | None = None,
|
|
19
|
+
metadata: dict[str, Any] | None = None,
|
|
21
20
|
**kwargs: Any,
|
|
22
|
-
) ->
|
|
21
|
+
) -> dict[str, Any]:
|
|
23
22
|
"""
|
|
24
23
|
Map LangSmith @traceable arguments to UiPath @traced() arguments.
|
|
25
24
|
|
|
@@ -65,12 +64,12 @@ def _map_traceable_to_traced_args(
|
|
|
65
64
|
|
|
66
65
|
|
|
67
66
|
def otel_traceable_adapter(
|
|
68
|
-
func:
|
|
67
|
+
func: Callable[..., Any] | None = None,
|
|
69
68
|
*,
|
|
70
|
-
run_type:
|
|
71
|
-
name:
|
|
72
|
-
tags:
|
|
73
|
-
metadata:
|
|
69
|
+
run_type: str | None = None,
|
|
70
|
+
name: str | None = None,
|
|
71
|
+
tags: list[str] | None = None,
|
|
72
|
+
metadata: dict[str, Any] | None = None,
|
|
74
73
|
**kwargs: Any,
|
|
75
74
|
):
|
|
76
75
|
"""
|