-
Notifications
You must be signed in to change notification settings - Fork 32
feat: confirmToolCall support — startToolCall with requireConfirmation + ToolRunnableCallable [JAR-9208] #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
| from langchain_core.callbacks import BaseCallbackHandler | ||
| from langchain_core.runnables.config import RunnableConfig | ||
| from langchain_core.tools import BaseTool | ||
| from langgraph.errors import EmptyInputError, GraphRecursionError, InvalidUpdateError | ||
| from langgraph.graph.state import CompiledStateGraph | ||
| from langgraph.types import Command, Interrupt, StateSnapshot | ||
|
|
@@ -29,7 +30,8 @@ | |
| ) | ||
| from uipath.runtime.schema import UiPathRuntimeSchema | ||
|
|
||
| from uipath_langchain.chat.hitl import REQUIRE_CONVERSATIONAL_CONFIRMATION | ||
| from uipath_langchain.agent.tools.tool_node import RunnableCallableWithTool | ||
| from uipath_langchain.chat.hitl import get_confirmation_schema | ||
| from uipath_langchain.runtime.errors import LangGraphErrorCode, LangGraphRuntimeError | ||
| from uipath_langchain.runtime.messages import UiPathChatMessagesMapper | ||
| from uipath_langchain.runtime.schema import get_entrypoints_schema, get_graph_schema | ||
|
|
@@ -65,9 +67,7 @@ def __init__( | |
| self.entrypoint: str | None = entrypoint | ||
| self.callbacks: list[BaseCallbackHandler] = callbacks or [] | ||
| self.chat = UiPathChatMessagesMapper(self.runtime_id, storage) | ||
| self.chat.tool_names_requiring_confirmation = ( | ||
| self._get_tool_names_requiring_confirmation() | ||
| ) | ||
| self.chat.tools_requiring_confirmation = self._get_tool_confirmation_info() | ||
| self._middleware_node_names: set[str] = self._detect_middleware_nodes() | ||
|
|
||
| async def execute( | ||
|
|
@@ -490,17 +490,37 @@ def _detect_middleware_nodes(self) -> set[str]: | |
|
|
||
| return middleware_nodes | ||
|
|
||
| def _get_tool_names_requiring_confirmation(self) -> set[str]: | ||
| names: set[str] = set() | ||
| for node_name, node_spec in self.graph.nodes.items(): | ||
| # langgraph's processing node.bound -> runnable.tool -> baseTool (if tool node) | ||
| tool = getattr(getattr(node_spec, "bound", None), "tool", None) | ||
| if tool is None: | ||
| def _get_tool_confirmation_info(self) -> dict[str, Any]: | ||
| """Build {tool_name: input_schema} for tools requiring confirmation. | ||
|
|
||
| Walks compiled graph nodes once at runtime init. This is needed because coded agents | ||
| (create_agent) export a compiled graph as the only artifact — there's no side channel | ||
| to pass confirmation metadata from the build step to the runtime. | ||
| """ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a problem for low code agents, but might as well unify how we get tools requiring confirmation |
||
| schemas: dict[str, Any] = {} | ||
| for node_spec in self.graph.nodes.values(): | ||
| bound = getattr(node_spec, "bound", None) | ||
| if bound is None: | ||
| continue | ||
|
|
||
| # Coded agents: one tool per node | ||
| if isinstance(bound, RunnableCallableWithTool): | ||
| schema = get_confirmation_schema(bound.tool) | ||
| if schema is not None: | ||
| schemas[bound.tool.name] = schema | ||
| continue | ||
| metadata = getattr(tool, "metadata", None) or {} | ||
| if metadata.get(REQUIRE_CONVERSATIONAL_CONFIRMATION): | ||
| names.add(getattr(tool, "name", node_name)) | ||
| return names | ||
|
|
||
| # Low-code agents: multiple tools in one node | ||
| tools_by_name = getattr(bound, "tools_by_name", None) | ||
| if isinstance(tools_by_name, dict): | ||
| for tool in tools_by_name.values(): | ||
| if not isinstance(tool, BaseTool): | ||
| continue | ||
| schema = get_confirmation_schema(tool) | ||
| if schema is not None: | ||
| schemas[tool.name] = schema | ||
|
|
||
| return schemas | ||
|
|
||
| def _is_middleware_node(self, node_name: str) -> bool: | ||
| """Check if a node name represents a middleware node.""" | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.