Skip to content

Commit bea930e

Browse files
fix: tests
1 parent 1f60694 commit bea930e

6 files changed

Lines changed: 891 additions & 49 deletions

File tree

src/uipath_langchain/agent/tools/internal_tools/batch_transform_tool.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
from uipath_langchain.agent.react.jsonschema_pydantic_converter import create_model
2727
from uipath_langchain.agent.react.types import AgentGraphState
28+
from uipath_langchain.agent.tools.internal_tools.schema_utils import (
29+
add_query_field_to_schema,
30+
)
2831
from uipath_langchain.agent.tools.static_args import handle_static_args
2932
from uipath_langchain.agent.tools.structured_tool_with_argument_properties import (
3033
StructuredToolWithArgumentProperties,
@@ -53,11 +56,9 @@ def create_batch_transform_tool(
5356
output_columns_setting = settings.output_columns
5457
web_search_grounding_setting = settings.web_search_grounding
5558

56-
# Check if query is dynamic or static
5759
is_query_static = query_setting and query_setting.variant == "static"
5860
static_query = query_setting.value if is_query_static else None
5961

60-
# Get static values for other settings
6162
static_folder_path_prefix = None
6263
if folder_path_prefix_setting:
6364
static_folder_path_prefix = getattr(folder_path_prefix_setting, "value", None)
@@ -67,7 +68,6 @@ def create_batch_transform_tool(
6768
value = getattr(web_search_grounding_setting, "value", None)
6869
static_web_search = value == "Enabled" if value else False
6970

70-
# Convert output columns to BatchTransformOutputColumn
7171
batch_transform_output_columns = [
7272
BatchTransformOutputColumn(name=col.name, description=col.description or "")
7373
for col in output_columns_setting
@@ -76,18 +76,11 @@ def create_batch_transform_tool(
7676
# Use resource input schema and add query field if dynamic
7777
input_schema = dict(resource.input_schema)
7878
if not is_query_static:
79-
if "properties" not in input_schema:
80-
input_schema["properties"] = {}
81-
input_schema["properties"]["query"] = {
82-
"type": "string",
83-
"description": query_setting.description
84-
if query_setting and query_setting.description
85-
else "The query to create a batch transform off of",
86-
}
87-
if "required" not in input_schema:
88-
input_schema["required"] = []
89-
if "query" not in input_schema["required"]:
90-
input_schema["required"].append("query")
79+
add_query_field_to_schema(
80+
input_schema,
81+
query_description=query_setting.description if query_setting else None,
82+
default_description="Describe the task: what to research, what to synthesize.",
83+
)
9184

9285
# Create input model from modified schema
9386
input_model = create_model(input_schema)
@@ -101,7 +94,6 @@ def create_batch_transform_tool(
10194
example_calls=[], # Examples cannot be provided for internal tools
10295
)
10396
async def batch_transform_tool_fn(**kwargs: Any) -> dict[str, Any]:
104-
# Get query - dynamic from kwargs or static from settings
10597
query = kwargs.get("query") if not is_query_static else static_query
10698
if not query:
10799
raise ValueError("Query is required for Batch Transform tool")
@@ -113,27 +105,22 @@ async def batch_transform_tool_fn(**kwargs: Any) -> dict[str, Any]:
113105
if not attachment:
114106
raise ValueError("Attachment is required for Batch Transform tool")
115107

116-
# Extract attachment ID using getattr (works for Pydantic models)
117108
attachment_id = getattr(attachment, "ID", None)
118109
if not attachment_id:
119110
raise ValueError("Attachment ID is required")
120111

121-
# Get destination path, default to output.csv if not provided
122112
destination_path = kwargs.get("destination_path", "output.csv")
123113

124-
# Create ephemeral index directly via SDK
125114
uipath = UiPath()
126115
ephemeral_index = await uipath.context_grounding.create_ephemeral_index_async(
127116
usage=EphemeralIndexUsage.BATCH_RAG,
128117
attachments=[attachment_id],
129118
)
130119

131-
# Wait for index ingestion only if in progress
132120
if ephemeral_index.in_progress_ingestion():
133121
ephemeral_index_dict = interrupt(WaitEphemeralIndex(index=ephemeral_index))
134122
ephemeral_index = ContextGroundingIndex(**ephemeral_index_dict)
135123

136-
# Create Batch Transform request using interrupt
137124
return interrupt(
138125
CreateBatchTransform(
139126
name=f"task-{uuid.uuid4()}",
@@ -144,7 +131,7 @@ async def batch_transform_tool_fn(**kwargs: Any) -> dict[str, Any]:
144131
storage_bucket_folder_path_prefix=static_folder_path_prefix,
145132
enable_web_search_grounding=static_web_search,
146133
destination_path=destination_path,
147-
is_ephemeral=True,
134+
is_ephemeral_index=True,
148135
)
149136
)
150137

src/uipath_langchain/agent/tools/internal_tools/deeprag_tool.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
from uipath_langchain.agent.react.jsonschema_pydantic_converter import create_model
2727
from uipath_langchain.agent.react.types import AgentGraphState
28+
from uipath_langchain.agent.tools.internal_tools.schema_utils import (
29+
add_query_field_to_schema,
30+
)
2831
from uipath_langchain.agent.tools.static_args import handle_static_args
2932
from uipath_langchain.agent.tools.structured_tool_with_argument_properties import (
3033
StructuredToolWithArgumentProperties,
@@ -51,36 +54,23 @@ def create_deeprag_tool(
5154
query_setting = settings.query
5255
citation_mode_setting = settings.citation_mode
5356

54-
# Determine citation mode
5557
citation_mode = (
5658
CitationMode(citation_mode_setting.value)
5759
if citation_mode_setting
5860
else CitationMode.INLINE
5961
)
6062

61-
# Check if query is dynamic or static
6263
is_query_static = query_setting and query_setting.variant == "static"
6364
static_query = query_setting.value if is_query_static else None
6465

65-
# Use resource input schema and add query field if dynamic
6666
input_schema = dict(resource.input_schema)
6767
if not is_query_static:
68-
# Add query field to the schema
69-
if "properties" not in input_schema:
70-
input_schema["properties"] = {}
71-
input_schema["properties"]["query"] = {
72-
"type": "string",
73-
"description": query_setting.description
74-
if query_setting and query_setting.description
75-
else "The query to create a deeprag off of",
76-
}
77-
# Add query to required fields
78-
if "required" not in input_schema:
79-
input_schema["required"] = []
80-
if "query" not in input_schema["required"]:
81-
input_schema["required"].append("query")
82-
83-
# Create input model from modified schema
68+
add_query_field_to_schema(
69+
input_schema,
70+
query_description=query_setting.description if query_setting else None,
71+
default_description="Describe the task: what to research across documents, what to synthesize and how to cite sources.",
72+
)
73+
8474
input_model = create_model(input_schema)
8575
output_model = create_model(resource.output_schema)
8676

@@ -92,7 +82,6 @@ def create_deeprag_tool(
9282
example_calls=[], # Examples cannot be provided for internal tools
9383
)
9484
async def deeprag_tool_fn(**kwargs: Any) -> dict[str, Any]:
95-
# Get query - dynamic from kwargs or static from settings
9685
query = kwargs.get("query") if not is_query_static else static_query
9786
if not query:
9887
raise ValueError("Query is required for DeepRAG tool")
@@ -104,32 +93,28 @@ async def deeprag_tool_fn(**kwargs: Any) -> dict[str, Any]:
10493
if not attachment:
10594
raise ValueError("Attachment is required for DeepRAG tool")
10695

107-
# Extract attachment ID using getattr (works for Pydantic models)
10896
attachment_id = getattr(attachment, "ID", None)
10997
if not attachment_id:
11098
raise ValueError("Attachment ID is required")
11199

112-
# Create ephemeral index directly via SDK
113100
uipath = UiPath()
114101
ephemeral_index = await uipath.context_grounding.create_ephemeral_index_async(
115102
usage=EphemeralIndexUsage.DEEP_RAG,
116103
attachments=[attachment_id],
117104
)
118105

119-
# Wait for index ingestion only if in progress
120106
if ephemeral_index.in_progress_ingestion():
121107
ephemeral_index_dict = interrupt(WaitEphemeralIndex(index=ephemeral_index))
122108
ephemeral_index = ContextGroundingIndex(**ephemeral_index_dict)
123109

124-
# Create DeepRAG request using interrupt
125110
return interrupt(
126111
CreateDeepRag(
127112
name=f"task-{uuid.uuid4()}",
128113
index_name=ephemeral_index.name,
129114
index_id=ephemeral_index.id,
130115
prompt=query,
131116
citation_mode=citation_mode,
132-
is_ephemeral=True,
117+
is_ephemeral_index=True,
133118
)
134119
)
135120

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Utility functions for internal tool schema manipulation."""
2+
3+
4+
def add_query_field_to_schema(
5+
input_schema: dict,
6+
query_description: str | None = None,
7+
default_description: str = "Query or prompt for the operation.",
8+
) -> None:
9+
"""Add a dynamic query field to an input schema.
10+
11+
This modifies the input schema in-place by adding a 'query' property
12+
and marking it as required.
13+
14+
Args:
15+
input_schema: The JSON schema dict to modify
16+
query_description: Custom description for the query field
17+
default_description: Default description if query_description is not provided
18+
"""
19+
if "properties" not in input_schema:
20+
input_schema["properties"] = {}
21+
22+
input_schema["properties"]["query"] = {
23+
"type": "string",
24+
"description": query_description if query_description else default_description,
25+
}
26+
27+
if "required" not in input_schema:
28+
input_schema["required"] = []
29+
30+
if "query" not in input_schema["required"]:
31+
input_schema["required"].append("query")

tests/agent/tools/internal_tools/test_analyze_files_tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from langchain_core.messages import AIMessage, HumanMessage
88
from pydantic import BaseModel, ConfigDict, Field
99
from uipath.agent.models.agent import (
10-
AgentInternalToolProperties,
10+
AgentInternalAnalyzeFilesToolProperties,
1111
AgentInternalToolResourceConfig,
1212
AgentInternalToolType,
1313
)
@@ -60,7 +60,7 @@ def resource_config(self):
6060
}
6161
output_schema = {"type": "object", "properties": {"result": {"type": "string"}}}
6262

63-
properties = AgentInternalToolProperties(
63+
properties = AgentInternalAnalyzeFilesToolProperties(
6464
tool_type=AgentInternalToolType.ANALYZE_FILES
6565
)
6666

0 commit comments

Comments
 (0)