Skip to content

Commit 5a38baf

Browse files
committed
feat(StructuredToolWithOutputType): support dynamic output types
`StructuredTool`s are `Runnable`s, but `OutputType` is always `Any` unless overridden. This commit adds the override since we have strongly typed output types. Additionally, removing asterisks from IS output schemas (bugfix).
1 parent 15fbaae commit 5a38baf

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-langchain"
3-
version = "0.1.14"
3+
version = "0.1.15"
44
description = "UiPath Langchain"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath_langchain/agent/tools/context_tool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from uipath_langchain.retrievers import ContextGroundingRetriever
1212

13+
from .structured_tool_with_output_type import StructuredToolWithOutputType
1314
from .utils import sanitize_tool_name
1415

1516

@@ -43,9 +44,10 @@ class ContextOutputSchemaModel(BaseModel):
4344
async def context_tool_fn(query: str) -> dict[str, Any]:
4445
return {"documents": await retriever.ainvoke(query)}
4546

46-
return StructuredTool(
47+
return StructuredToolWithOutputType(
4748
name=tool_name,
4849
description=resource.description,
4950
args_schema=input_model,
5051
coroutine=context_tool_fn,
52+
output_type=output_model,
5153
)

src/uipath_langchain/agent/tools/process_tool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from uipath.eval.mocks import mockable
1010
from uipath.platform.common import InvokeProcess
1111

12+
from .structured_tool_with_output_type import StructuredToolWithOutputType
1213
from .utils import sanitize_tool_name
1314

1415

@@ -37,11 +38,12 @@ async def process_tool_fn(**kwargs: Any):
3738
)
3839
)
3940

40-
tool = StructuredTool(
41+
tool = StructuredToolWithOutputType(
4142
name=tool_name,
4243
description=resource.description,
4344
args_schema=input_model,
4445
coroutine=process_tool_fn,
46+
output_type=output_model,
4547
)
4648

4749
return tool
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import Any
2+
3+
from langchain_core.tools import StructuredTool
4+
from pydantic import Field
5+
from typing_extensions import override
6+
7+
8+
class StructuredToolWithOutputType(StructuredTool):
9+
output_type: Any = Field(Any, description="Output type.")
10+
11+
@override
12+
@property
13+
def OutputType(self) -> type[Any]:
14+
return self.output_type

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)