Skip to content

Commit 19913fc

Browse files
committed
feat(PreconfiguredToolImprovements): update the tool definitions
Specifically, 1. Adding mockable support to all tools 2. Adding the right annotations to the tool definitions 3. Ensuring folder paths are removed to enable support for overrides
1 parent 8cff3ef commit 19913fc

File tree

3 files changed

+1735
-1713
lines changed

3 files changed

+1735
-1713
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "UiPath Langchain"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
77
dependencies = [
8-
"uipath>=2.1.76, <2.2.0",
8+
"uipath>=2.1.79, <2.2.0",
99
"langgraph>=0.5.0, <0.7.0",
1010
"langchain-core>=0.3.34",
1111
"langgraph-checkpoint-sqlite>=2.0.3",

src/uipath_langchain/tools/preconfigured.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,36 @@
1919
AgentProcessToolResourceConfig,
2020
AgentResourceConfig,
2121
)
22+
from uipath.eval.mocks import mockable
2223
from uipath.models import CreateAction, InvokeProcess
2324
from uipath.models.connections import ConnectionTokenType
2425

2526
logger = logging.getLogger(__name__)
2627

2728

2829
def create_process_tool(resource: AgentProcessToolResourceConfig) -> Iterable[BaseTool]:
29-
async def process(**kwargs) -> BaseModel:
30+
input_schema: Any = create_model(resource.input_schema)
31+
output_schema: Any = create_model(resource.output_schema)
32+
33+
@mockable(
34+
name=resource.name,
35+
description=resource.description,
36+
input_schema=input_schema.model_json_schema(),
37+
output_schema=output_schema.model_json_schema(),
38+
example_calls=resource.properties.example_calls,
39+
)
40+
async def process(**kwargs) -> output_schema:
3041
return interrupt(
3142
InvokeProcess(
3243
name=resource.name,
3344
input_arguments=kwargs,
34-
process_folder_path=resource.properties.folder_path,
3545
)
3646
)
3747

38-
input_schema = create_model(resource.input_schema)
39-
4048
class ProcessTool(StructuredTool):
4149
@property
4250
def OutputType(self) -> type[Output]:
43-
return create_model(resource.output_schema)
51+
return output_schema
4452

4553
yield ProcessTool(
4654
name=resource.name,
@@ -51,7 +59,17 @@ def OutputType(self) -> type[Output]:
5159

5260

5361
def create_escalation_tool_from_channel(channel: AgentEscalationChannel) -> BaseTool:
54-
async def escalate(**kwargs) -> BaseModel:
62+
input_schema: Any = create_model(channel.input_schema)
63+
output_schema: Any = create_model(channel.output_schema)
64+
65+
@mockable(
66+
name=channel.name,
67+
description=channel.description,
68+
input_schema=input_schema.model_json_schema(),
69+
output_schema=output_schema.model_json_schema(),
70+
example_calls=channel.properties.example_calls,
71+
)
72+
async def escalate(**kwargs) -> output_schema:
5573
recipients = channel.recipients
5674
if len(recipients) > 1:
5775
logger.warning(
@@ -64,19 +82,15 @@ async def escalate(**kwargs) -> BaseModel:
6482
data=kwargs,
6583
assignee=assignee,
6684
app_name=channel.properties.app_name,
67-
app_folder_path=None, # Channels specify folder name but not folder path.
68-
app_folder_key=channel.properties.resource_key,
6985
app_key=channel.properties.resource_key,
7086
app_version=channel.properties.app_version,
7187
)
7288
)
7389

74-
input_schema = create_model(channel.input_schema)
75-
7690
class EscalationTool(StructuredTool):
7791
@property
7892
def OutputType(self) -> type[Output]:
79-
return create_model(channel.output_schema)
93+
return output_schema
8094

8195
return EscalationTool(
8296
name=channel.name,
@@ -117,7 +131,17 @@ def filter_query_params(
117131
def create_integration_tool(
118132
resource: AgentIntegrationToolResourceConfig,
119133
) -> Iterable[BaseTool]:
120-
async def integration(**kwargs) -> BaseModel:
134+
input_schema: Any = create_model(resource.input_schema)
135+
output_schema: Any = create_model({}) # to-fix
136+
137+
@mockable(
138+
name=resource.name,
139+
description=resource.description,
140+
input_schema=input_schema.model_json_schema(),
141+
output_schema=output_schema.model_json_schema(),
142+
example_calls=resource.properties.example_calls,
143+
)
144+
async def integration(**kwargs) -> output_schema:
121145
uipath = UiPath()
122146
remote_connection = await uipath.connections.retrieve_async(
123147
resource.properties.connection.id
@@ -127,7 +151,7 @@ async def integration(**kwargs) -> BaseModel:
127151
)
128152
tool_url = f"{remote_connection.api_base_uri}/v3/element/instances/{remote_connection.element_instance_id}{resource.properties.tool_path}"
129153
tool_url = f"{tool_url}{build_query_params(resource.properties.parameters)}"
130-
tool_url = tool_url.format(**kwargs)
154+
tool_url = tool_url.format(kwargs)
131155

132156
authorization = f"{token.token_type} {token.access_token}"
133157
method = METHOD_MAP.get(resource.properties.method, resource.properties.method)
@@ -141,12 +165,10 @@ async def integration(**kwargs) -> BaseModel:
141165
)
142166
return response.json()
143167

144-
input_schema = create_model(resource.input_schema)
145-
146168
class IntegrationTool(StructuredTool):
147169
@property
148170
def OutputType(self) -> type[Output]:
149-
return create_model({})
171+
return output_schema
150172

151173
yield IntegrationTool(
152174
name=resource.name,

0 commit comments

Comments
 (0)