Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "UiPath Langchain"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.10"
dependencies = [
"uipath>=2.1.76, <2.2.0",
"uipath>=2.1.79, <2.2.0",
"langgraph>=0.5.0, <0.7.0",
"langchain-core>=0.3.34",
"langgraph-checkpoint-sqlite>=2.0.3",
Expand Down
54 changes: 38 additions & 16 deletions src/uipath_langchain/tools/preconfigured.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,36 @@
AgentProcessToolResourceConfig,
AgentResourceConfig,
)
from uipath.eval.mocks import mockable
from uipath.models import CreateAction, InvokeProcess
from uipath.models.connections import ConnectionTokenType

logger = logging.getLogger(__name__)


def create_process_tool(resource: AgentProcessToolResourceConfig) -> Iterable[BaseTool]:
async def process(**kwargs) -> BaseModel:
input_schema: Any = create_model(resource.input_schema)
output_schema: Any = create_model(resource.output_schema)

@mockable(
name=resource.name,
description=resource.description,
input_schema=input_schema.model_json_schema(),
output_schema=output_schema.model_json_schema(),
example_calls=resource.properties.example_calls,
)
async def process(**kwargs) -> output_schema:
return interrupt(
InvokeProcess(
name=resource.name,
input_arguments=kwargs,
process_folder_path=resource.properties.folder_path,
)
)

input_schema = create_model(resource.input_schema)

class ProcessTool(StructuredTool):
@property
def OutputType(self) -> type[Output]:
return create_model(resource.output_schema)
return output_schema

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


def create_escalation_tool_from_channel(channel: AgentEscalationChannel) -> BaseTool:
async def escalate(**kwargs) -> BaseModel:
input_schema: Any = create_model(channel.input_schema)
output_schema: Any = create_model(channel.output_schema)

@mockable(
name=channel.name,
description=channel.description,
input_schema=input_schema.model_json_schema(),
output_schema=output_schema.model_json_schema(),
example_calls=channel.properties.example_calls,
)
async def escalate(**kwargs) -> output_schema:
recipients = channel.recipients
if len(recipients) > 1:
logger.warning(
Expand All @@ -64,19 +82,15 @@ async def escalate(**kwargs) -> BaseModel:
data=kwargs,
assignee=assignee,
app_name=channel.properties.app_name,
app_folder_path=None, # Channels specify folder name but not folder path.
app_folder_key=channel.properties.resource_key,
app_key=channel.properties.resource_key,
app_version=channel.properties.app_version,
)
)

input_schema = create_model(channel.input_schema)

class EscalationTool(StructuredTool):
@property
def OutputType(self) -> type[Output]:
return create_model(channel.output_schema)
return output_schema

return EscalationTool(
name=channel.name,
Expand Down Expand Up @@ -117,7 +131,17 @@ def filter_query_params(
def create_integration_tool(
resource: AgentIntegrationToolResourceConfig,
) -> Iterable[BaseTool]:
async def integration(**kwargs) -> BaseModel:
input_schema: Any = create_model(resource.input_schema)
output_schema: Any = create_model({}) # to-fix

@mockable(
name=resource.name,
description=resource.description,
input_schema=input_schema.model_json_schema(),
output_schema=output_schema.model_json_schema(),
example_calls=resource.properties.example_calls,
)
async def integration(**kwargs) -> output_schema:
uipath = UiPath()
remote_connection = await uipath.connections.retrieve_async(
resource.properties.connection.id
Expand All @@ -127,7 +151,7 @@ async def integration(**kwargs) -> BaseModel:
)
tool_url = f"{remote_connection.api_base_uri}/v3/element/instances/{remote_connection.element_instance_id}{resource.properties.tool_path}"
tool_url = f"{tool_url}{build_query_params(resource.properties.parameters)}"
tool_url = tool_url.format(**kwargs)
tool_url = tool_url.format(kwargs)

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

input_schema = create_model(resource.input_schema)

class IntegrationTool(StructuredTool):
@property
def OutputType(self) -> type[Output]:
return create_model({})
return output_schema

yield IntegrationTool(
name=resource.name,
Expand Down
Loading