2929)
3030from uipath .runtime .schema import UiPathRuntimeSchema
3131
32- from uipath_langchain .chat .hitl import REQUIRE_CONVERSATIONAL_CONFIRMATION
3332from uipath_langchain .runtime .errors import LangGraphErrorCode , LangGraphRuntimeError
3433from uipath_langchain .runtime .messages import UiPathChatMessagesMapper
3534from uipath_langchain .runtime .schema import get_entrypoints_schema , get_graph_schema
@@ -51,6 +50,7 @@ def __init__(
5150 entrypoint : str | None = None ,
5251 callbacks : list [BaseCallbackHandler ] | None = None ,
5352 storage : UiPathRuntimeStorageProtocol | None = None ,
53+ tool_confirmation_schemas : dict [str , Any ] | None = None ,
5454 ):
5555 """
5656 Initialize the runtime.
@@ -59,15 +59,14 @@ def __init__(
5959 graph: The CompiledStateGraph to execute
6060 runtime_id: Unique identifier for this runtime instance
6161 entrypoint: Optional entrypoint name (for schema generation)
62+ tool_confirmation_schemas: Map of tool name to JSON schema for tool confirmation
6263 """
6364 self .graph : CompiledStateGraph [Any , Any , Any , Any ] = graph
6465 self .runtime_id : str = runtime_id or "default"
6566 self .entrypoint : str | None = entrypoint
6667 self .callbacks : list [BaseCallbackHandler ] = callbacks or []
6768 self .chat = UiPathChatMessagesMapper (self .runtime_id , storage )
68- confirmation_names , confirmation_schemas = self ._get_tool_confirmation_info ()
69- self .chat .tool_names_requiring_confirmation = confirmation_names
70- self .chat .tool_confirmation_schemas = confirmation_schemas
69+ self .chat .tool_confirmation_schemas = tool_confirmation_schemas or {}
7170 self ._middleware_node_names : set [str ] = self ._detect_middleware_nodes ()
7271
7372 async def execute (
@@ -490,40 +489,6 @@ def _detect_middleware_nodes(self) -> set[str]:
490489
491490 return middleware_nodes
492491
493- def _get_tool_confirmation_info (self ) -> tuple [set [str ], dict [str , Any ]]:
494- """Single pass over graph nodes to collect confirmation tool names and schemas."""
495- names : set [str ] = set ()
496- schemas : dict [str , Any ] = {}
497-
498- def _record (tool : Any , fallback_name : str ) -> None :
499- metadata = getattr (tool , "metadata" , None ) or {}
500- if not metadata .get (REQUIRE_CONVERSATIONAL_CONFIRMATION ):
501- return
502- tool_name = getattr (tool , "name" , fallback_name )
503- names .add (tool_name )
504- tool_call_schema = getattr (tool , "tool_call_schema" , None )
505- if tool_call_schema is not None :
506- schemas [tool_name ] = tool_call_schema .model_json_schema ()
507- else :
508- schemas [tool_name ] = {}
509-
510- for node_name , node_spec in self .graph .nodes .items ():
511- bound = getattr (node_spec , "bound" , None )
512- if bound is None :
513- continue
514- # Low-code: single-tool UiPathToolNode
515- tool = getattr (bound , "tool" , None )
516- if tool is not None :
517- _record (tool , node_name )
518- continue
519- # Coded: multi-tool ToolNode (create_agent)
520- tools_by_name = getattr (bound , "tools_by_name" , None )
521- if isinstance (tools_by_name , dict ):
522- for fallback_name , tool in tools_by_name .items ():
523- _record (tool , fallback_name )
524-
525- return names , schemas
526-
527492 def _is_middleware_node (self , node_name : str ) -> bool :
528493 """Check if a node name represents a middleware node."""
529494 return node_name in self ._middleware_node_names
0 commit comments