uipath-langchain 0.0.93__py3-none-any.whl → 0.0.95__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.

Potentially problematic release.


This version of uipath-langchain might be problematic. Click here for more details.

@@ -0,0 +1,7 @@
1
+ {
2
+ "dependencies": ["."],
3
+ "graphs": {
4
+ "agent": "./main.py:graph"
5
+ },
6
+ "env": ".env"
7
+ }
@@ -0,0 +1,33 @@
1
+ from langchain_anthropic import ChatAnthropic
2
+ from langchain_core.messages import HumanMessage, SystemMessage
3
+ from langchain_openai import ChatOpenAI
4
+ from langgraph.graph import START, StateGraph, END
5
+ from pydantic import BaseModel
6
+ import os
7
+
8
+ class GraphInput(BaseModel):
9
+ topic: str
10
+
11
+ class GraphOutput(BaseModel):
12
+ report: str
13
+
14
+ async def generate_report(state: GraphInput) -> GraphOutput:
15
+ if os.getenv("ANTHROPIC_API_KEY"):
16
+ llm_model = ChatAnthropic(model="claude-3-5-sonnet-latest")
17
+ elif os.getenv("OPENAI_API_KEY"):
18
+ llm_model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
19
+ else:
20
+ raise Exception("Error: Missing API Key. Please define either ANTHROPIC_API_KEY or OPENAI_API_KEY.")
21
+
22
+ system_prompt = "You are a report generator. Please provide a brief report based on the given topic."
23
+ output = await llm_model.ainvoke([SystemMessage(system_prompt), HumanMessage(state.topic)])
24
+ return GraphOutput(report=output.content)
25
+
26
+ builder = StateGraph(input=GraphInput, output=GraphOutput)
27
+
28
+ builder.add_node("generate_report", generate_report)
29
+
30
+ builder.add_edge(START, "generate_report")
31
+ builder.add_edge("generate_report", END)
32
+
33
+ graph = builder.compile()
@@ -4,9 +4,11 @@ import os
4
4
  import uuid
5
5
  from typing import Any, Dict
6
6
 
7
+ import click
7
8
  from langgraph.graph.state import CompiledStateGraph
8
9
  from uipath._cli._utils._parse_ast import generate_bindings_json # type: ignore
9
10
  from uipath._cli.middlewares import MiddlewareResult
11
+ from uipath._cli.spinner import Spinner
10
12
 
11
13
  from ._utils._graph import LangGraphConfig
12
14
 
@@ -32,6 +34,25 @@ def resolve_refs(schema, root=None):
32
34
  return schema
33
35
 
34
36
 
37
+ def process_nullable_types(
38
+ schema: Dict[str, Any] | list[Any] | Any,
39
+ ) -> Dict[str, Any] | list[Any]:
40
+ """Process the schema to handle nullable types by removing anyOf with null and keeping the base type."""
41
+ if isinstance(schema, dict):
42
+ if "anyOf" in schema and len(schema["anyOf"]) == 2:
43
+ types = [t.get("type") for t in schema["anyOf"]]
44
+ if "null" in types:
45
+ non_null_type = next(
46
+ t for t in schema["anyOf"] if t.get("type") != "null"
47
+ )
48
+ return non_null_type
49
+
50
+ return {k: process_nullable_types(v) for k, v in schema.items()}
51
+ elif isinstance(schema, list):
52
+ return [process_nullable_types(item) for item in schema]
53
+ return schema
54
+
55
+
35
56
  def generate_schema_from_graph(graph: CompiledStateGraph) -> Dict[str, Any]:
36
57
  """Extract input/output schema from a LangGraph graph"""
37
58
  schema = {
@@ -42,12 +63,14 @@ def generate_schema_from_graph(graph: CompiledStateGraph) -> Dict[str, Any]:
42
63
  if hasattr(graph, "input_schema"):
43
64
  if hasattr(graph.input_schema, "model_json_schema"):
44
65
  input_schema = graph.input_schema.model_json_schema()
45
-
46
66
  unpacked_ref_def_properties = resolve_refs(input_schema)
47
67
 
48
- schema["input"]["properties"] = unpacked_ref_def_properties.get(
49
- "properties", {}
68
+ # Process the schema to handle nullable types
69
+ processed_properties = process_nullable_types(
70
+ unpacked_ref_def_properties.get("properties", {})
50
71
  )
72
+
73
+ schema["input"]["properties"] = processed_properties
51
74
  schema["input"]["required"] = unpacked_ref_def_properties.get(
52
75
  "required", []
53
76
  )
@@ -55,11 +78,14 @@ def generate_schema_from_graph(graph: CompiledStateGraph) -> Dict[str, Any]:
55
78
  if hasattr(graph, "output_schema"):
56
79
  if hasattr(graph.output_schema, "model_json_schema"):
57
80
  output_schema = graph.output_schema.model_json_schema()
58
-
59
81
  unpacked_ref_def_properties = resolve_refs(output_schema)
60
- schema["output"]["properties"] = unpacked_ref_def_properties.get(
61
- "properties", {}
82
+
83
+ # Process the schema to handle nullable types
84
+ processed_properties = process_nullable_types(
85
+ unpacked_ref_def_properties.get("properties", {})
62
86
  )
87
+
88
+ schema["output"]["properties"] = processed_properties
63
89
  schema["output"]["required"] = unpacked_ref_def_properties.get(
64
90
  "required", []
65
91
  )
@@ -69,6 +95,7 @@ def generate_schema_from_graph(graph: CompiledStateGraph) -> Dict[str, Any]:
69
95
 
70
96
  async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
71
97
  """Middleware to check for langgraph.json and create uipath.json with schemas"""
98
+ spinner = Spinner("Initializing UiPath project...")
72
99
  config = LangGraphConfig()
73
100
  if not config.exists:
74
101
  return MiddlewareResult(
@@ -76,6 +103,7 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
76
103
  ) # Continue with normal flow if no langgraph.json
77
104
 
78
105
  try:
106
+ spinner.start()
79
107
  config.load_config()
80
108
  entrypoints = []
81
109
  all_bindings = {"version": "2.0", "resources": []}
@@ -98,7 +126,6 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
98
126
  mermaids[graph.name] = compiled_graph.get_graph(xray=1).draw_mermaid()
99
127
 
100
128
  try:
101
- print("Generating bindings for ", graph.file_path)
102
129
  # Make sure the file path exists
103
130
  if os.path.exists(graph.file_path):
104
131
  file_bindings = generate_bindings_json(graph.file_path)
@@ -108,7 +135,7 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
108
135
  all_bindings["resources"] = file_bindings["resources"]
109
136
  except Exception as e:
110
137
  print(
111
- f"Warning: Could not generate bindings for {graph.file_path}: {str(e)}"
138
+ f"⚠️ Warning: Could not generate bindings for {graph.file_path}: {str(e)}"
112
139
  )
113
140
 
114
141
  new_entrypoint: dict[str, Any] = {
@@ -121,19 +148,21 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
121
148
  entrypoints.append(new_entrypoint)
122
149
 
123
150
  except Exception as e:
151
+ spinner.stop()
124
152
  print(f"Error during graph load: {e}")
125
153
  return MiddlewareResult(
126
154
  should_continue=False,
127
- error_message=f"Failed to load graph '{graph.name}': {str(e)}",
155
+ error_message=f"Failed to load graph '{graph.name}': {str(e)}",
128
156
  should_include_stacktrace=True,
129
157
  )
130
158
  finally:
131
159
  await graph.cleanup()
132
160
 
133
161
  if entrypoint and not entrypoints:
162
+ spinner.stop()
134
163
  return MiddlewareResult(
135
164
  should_continue=False,
136
- error_message=f"Error: No graph found with name '{entrypoint}'",
165
+ error_message=f"Error: No graph found with name '{entrypoint}'",
137
166
  )
138
167
 
139
168
  uipath_config = {"entryPoints": entrypoints, "bindings": all_bindings}
@@ -149,21 +178,24 @@ async def langgraph_init_middleware_async(entrypoint: str) -> MiddlewareResult:
149
178
  with open(mermaid_file_path, "w") as f:
150
179
  f.write(mermaid_content)
151
180
  except Exception as write_error:
181
+ spinner.stop()
152
182
  return MiddlewareResult(
153
183
  should_continue=False,
154
- error_message=f"Error writing mermaid file for '{graph_name}': {str(write_error)}",
184
+ error_message=f"Error writing mermaid file for '{graph_name}': {str(write_error)}",
155
185
  should_include_stacktrace=True,
156
186
  )
157
-
187
+ spinner.stop()
158
188
  return MiddlewareResult(
159
189
  should_continue=False,
160
- info_message=f"Configuration file {config_path} created successfully.",
190
+ info_message=click.style(" ", fg="green", bold=True)
191
+ + f" Configuration file {config_path} created successfully.",
161
192
  )
162
193
 
163
194
  except Exception as e:
195
+ spinner.stop()
164
196
  return MiddlewareResult(
165
197
  should_continue=False,
166
- error_message=f"Error processing langgraph configuration: {str(e)}",
198
+ error_message=f"Error processing langgraph configuration: {str(e)}",
167
199
  should_include_stacktrace=True,
168
200
  )
169
201
 
@@ -0,0 +1,76 @@
1
+ import os
2
+ import shutil
3
+
4
+ import click
5
+ from uipath._cli.middlewares import MiddlewareResult
6
+ from uipath._cli.spinner import Spinner
7
+
8
+
9
+ def generate_script(target_directory):
10
+ template_script_path = os.path.join(
11
+ os.path.dirname(__file__), "_templates/main.py.template"
12
+ )
13
+ target_path = os.path.join(target_directory, "main.py")
14
+
15
+ shutil.copyfile(template_script_path, target_path)
16
+
17
+ template_langgraph_json_path = os.path.join(
18
+ os.path.dirname(__file__), "_templates/langgraph.json.template"
19
+ )
20
+ target_path = os.path.join(target_directory, "langgraph.json")
21
+ shutil.copyfile(template_langgraph_json_path, target_path)
22
+
23
+
24
+ def generate_pyproject(target_directory, project_name):
25
+ project_toml_path = os.path.join(target_directory, "pyproject.toml")
26
+ toml_content = f"""[project]
27
+ name = "{project_name}"
28
+ version = "0.0.1"
29
+ description = "{project_name}"
30
+ authors = [{{ name = "John Doe", email = "john.doe@myemail.com" }}]
31
+ dependencies = [
32
+ "uipath-langchain>=0.0.95",
33
+ "langchain-anthropic>=0.3.8",
34
+ ]
35
+ requires-python = ">=3.10"
36
+ """
37
+
38
+ with open(project_toml_path, "w") as f:
39
+ f.write(toml_content)
40
+
41
+
42
+ def langgraph_new_middleware(name: str) -> MiddlewareResult:
43
+ """Middleware to create demo langchain agent"""
44
+ spinner = Spinner("Creating demo agent...")
45
+ directory = os.getcwd()
46
+
47
+ try:
48
+ generate_script(directory)
49
+ click.echo(click.style("✓ ", fg="green", bold=True) + "Created main.py file")
50
+ click.echo(
51
+ click.style("✓ ", fg="green", bold=True) + "Created langgraph.json file"
52
+ )
53
+ generate_pyproject(directory, name)
54
+ click.echo(
55
+ click.style("✓ ", fg="green", bold=True) + "Created pyproject.toml file"
56
+ )
57
+ os.system("uv sync")
58
+ spinner.start()
59
+ ctx = click.get_current_context()
60
+ init_cmd = ctx.parent.command.get_command(ctx, "init") # type: ignore
61
+ ctx.invoke(init_cmd)
62
+ spinner.stop()
63
+ click.echo(
64
+ click.style("✓ ", fg="green", bold=True) + " Agent created successfully."
65
+ )
66
+ return MiddlewareResult(
67
+ should_continue=False,
68
+ info_message="""Usage example: ` uipath run agent '{"topic": "UiPath"}' `""",
69
+ )
70
+ except Exception as e:
71
+ spinner.stop()
72
+ return MiddlewareResult(
73
+ should_continue=False,
74
+ error_message=f"❌ Error creating demo agent {str(e)}",
75
+ should_include_stacktrace=True,
76
+ )
@@ -1,6 +1,7 @@
1
1
  from uipath._cli.middlewares import Middlewares
2
2
 
3
3
  from ._cli.cli_init import langgraph_init_middleware
4
+ from ._cli.cli_new import langgraph_new_middleware
4
5
  from ._cli.cli_run import langgraph_run_middleware
5
6
 
6
7
 
@@ -8,3 +9,4 @@ def register_middleware():
8
9
  """This function will be called by the entry point system when uipath_langchain is installed"""
9
10
  Middlewares.register("init", langgraph_init_middleware)
10
11
  Middlewares.register("run", langgraph_run_middleware)
12
+ Middlewares.register("new", langgraph_new_middleware)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uipath-langchain
3
- Version: 0.0.93
3
+ Version: 0.0.95
4
4
  Summary: UiPath Langchain
5
5
  Project-URL: Homepage, https://uipath.com
6
6
  Project-URL: Repository, https://github.com/UiPath/uipath-langchain-python
@@ -25,7 +25,7 @@ Requires-Dist: pydantic-settings>=2.6.0
25
25
  Requires-Dist: python-dotenv>=1.0.1
26
26
  Requires-Dist: requests>=2.23.3
27
27
  Requires-Dist: types-requests>=2.32.0.20241016
28
- Requires-Dist: uipath<2.1.0,>=2.0.14
28
+ Requires-Dist: uipath<2.1.0,>=2.0.23
29
29
  Provides-Extra: langchain
30
30
  Description-Content-Type: text/markdown
31
31
 
@@ -1,7 +1,8 @@
1
1
  uipath_langchain/__init__.py,sha256=VBrvQn7d3nuOdN7zEnV2_S-uhmkjgEIlXiFVeZxZakQ,80
2
- uipath_langchain/middlewares.py,sha256=AkGsj-zqyh9u5AyX79MCL0yKL4YArF-hudAHZs_0K0Y,400
2
+ uipath_langchain/middlewares.py,sha256=tre7o9DFMgWk1DJiEEUmT6_wiP-PPkWtKmG0iOyvr9c,509
3
3
  uipath_langchain/_cli/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
4
- uipath_langchain/_cli/cli_init.py,sha256=jsMB9p4-ot23wP04gc-TsRHHnbGMYTw7mjA6r1_SqfA,6383
4
+ uipath_langchain/_cli/cli_init.py,sha256=PKkebO0P4Qh1N-LAx_HdypbffbGq5_JSquJY1OMsK6E,7700
5
+ uipath_langchain/_cli/cli_new.py,sha256=JjnDbns8ok2Bj2M6Tg-FKOfm1YxpTIq6ReLeCAl6vKM,2745
5
6
  uipath_langchain/_cli/cli_run.py,sha256=zMn2P1gB1ogM8_EmZsIhqNpeI9Oc02Z5Gj-oni7eUV4,2915
6
7
  uipath_langchain/_cli/_runtime/_context.py,sha256=wr4aNn06ReIXmetEZ6b6AnpAt64p13anQ2trZ5Bzgio,807
7
8
  uipath_langchain/_cli/_runtime/_escalation.py,sha256=oA5NvZvCo8ngELFJRyhZNM69DxVHrshhMY6CUk_cukQ,8055
@@ -9,6 +10,8 @@ uipath_langchain/_cli/_runtime/_exception.py,sha256=USKkLYkG-dzjX3fEiMMOHnVUpiXJ
9
10
  uipath_langchain/_cli/_runtime/_input.py,sha256=gKzPaGW-EzgeAskWJjbCWnfZRLu_BM7lCXkq0XkVGLU,5614
10
11
  uipath_langchain/_cli/_runtime/_output.py,sha256=WQSrsvGaaclZ6GLWEh6Nk1Mz1iGaIB45PgIX3DS3AN4,16130
11
12
  uipath_langchain/_cli/_runtime/_runtime.py,sha256=wj6e6tQdP2GjuSM-6G6Ug-FMqwOHwfUq-DGbd1gMfIg,11825
13
+ uipath_langchain/_cli/_templates/langgraph.json.template,sha256=eeh391Gta_hoRgaNaZ58nW1LNvCVXA7hlAH6l7Veous,107
14
+ uipath_langchain/_cli/_templates/main.py.template,sha256=FQIldd8PKYAxL9oAS6Y1CB0mKtY4LroXdYW8Hg_ZnHo,1202
12
15
  uipath_langchain/_cli/_utils/_graph.py,sha256=WLBSJfPc3_C07SqJhePRe17JIc5wcBvEqLviMcNOdTA,6950
13
16
  uipath_langchain/_utils/__init__.py,sha256=WoY66enCygRXTh6v5B1UrRcFCnQYuPJ8oqDkwomXzLc,194
14
17
  uipath_langchain/_utils/_request_mixin.py,sha256=t_1HWBxqEl-wsSk9ubmIM-8vs9BlNy4ZVBxtDxktn6U,18489
@@ -33,8 +36,8 @@ uipath_langchain/utils/_request_mixin.py,sha256=WFyTDyAthSci1DRwUwS21I3hLntD7HdV
33
36
  uipath_langchain/utils/_settings.py,sha256=MhwEVj4gVRSar0RBf2w2hTjO-5Qm-HpCuufqN3gSWjA,3390
34
37
  uipath_langchain/utils/_sleep_policy.py,sha256=e9pHdjmcCj4CVoFM1jMyZFelH11YatsgWfpyrfXzKBQ,1251
35
38
  uipath_langchain/vectorstores/context_grounding_vectorstore.py,sha256=eTa5sX43-ydB1pj9VNHUPbB-hC36fZK_CGrNe5U2Nrw,9393
36
- uipath_langchain-0.0.93.dist-info/METADATA,sha256=Y5aA_gbI1TOko5HOHMIFspfJsnSWni2TjSYMucUxVfw,3819
37
- uipath_langchain-0.0.93.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
- uipath_langchain-0.0.93.dist-info/entry_points.txt,sha256=FUtzqGOEntlJKMJIXhQUfT7ZTbQmGhke1iCmDWZaQZI,81
39
- uipath_langchain-0.0.93.dist-info/licenses/LICENSE,sha256=JDpt-uotAkHFmxpwxi6gwx6HQ25e-lG4U_Gzcvgp7JY,1063
40
- uipath_langchain-0.0.93.dist-info/RECORD,,
39
+ uipath_langchain-0.0.95.dist-info/METADATA,sha256=WZEMEDLVkErrg3hoVdG8qdcT97yNSYvWtQO17CK2IHs,3819
40
+ uipath_langchain-0.0.95.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
+ uipath_langchain-0.0.95.dist-info/entry_points.txt,sha256=FUtzqGOEntlJKMJIXhQUfT7ZTbQmGhke1iCmDWZaQZI,81
42
+ uipath_langchain-0.0.95.dist-info/licenses/LICENSE,sha256=JDpt-uotAkHFmxpwxi6gwx6HQ25e-lG4U_Gzcvgp7JY,1063
43
+ uipath_langchain-0.0.95.dist-info/RECORD,,