33from typing import Optional
44
55from dotenv import load_dotenv
6- from uipath ._cli ._debug ._bridge import ConsoleDebugBridge , get_debug_bridge
7- from uipath ._cli ._utils ._debug import setup_debugging
6+ from uipath ._cli ._debug ._bridge import get_debug_bridge
87from uipath ._cli ._utils ._studio_project import StudioClient
98from uipath ._cli .middlewares import MiddlewareResult
109from uipath ._config import UiPathConfig
1817 UiPathRuntimeFactoryProtocol ,
1918 UiPathRuntimeFactoryRegistry ,
2019 UiPathRuntimeProtocol ,
21- UiPathRuntimeResult ,
22- UiPathStreamOptions ,
2320)
24- from uipath .runtime .events import UiPathRuntimeStateEvent
2521from uipath .tracing import LlmOpsHttpExporter
2622from uipath_langchain ._cli ._runtime ._exception import LangGraphRuntimeError
2723
3329logger = logging .getLogger (__name__ )
3430
3531
36- async def execute_runtime (ctx : UiPathRuntimeContext ) -> UiPathRuntimeResult :
37- with ctx :
38- runtime : UiPathRuntimeProtocol | None = None
39- factory : UiPathRuntimeFactoryProtocol | None = None
40- try :
41- factory = UiPathRuntimeFactoryRegistry .get (context = ctx )
42- runtime = await factory .new_runtime (ctx .entrypoint , ctx .job_id or "default" )
43- options = UiPathExecuteOptions (resume = ctx .resume )
44- ctx .result = await runtime .execute (input = ctx .get_input (), options = options )
45- return ctx .result
46- finally :
47- if runtime :
48- await runtime .dispose ()
49- if factory :
50- await factory .dispose ()
51-
52-
53- async def debug_runtime (
54- ctx : UiPathRuntimeContext ,
55- ) -> UiPathRuntimeResult | None :
56- with ctx :
57- runtime : UiPathRuntimeProtocol | None = None
58- factory : UiPathRuntimeFactoryProtocol | None = None
59- try :
60- factory = UiPathRuntimeFactoryRegistry .get (context = ctx )
61- runtime = await factory .new_runtime (ctx .entrypoint , "default" )
62- debug_bridge : UiPathDebugBridgeProtocol = ConsoleDebugBridge ()
63- await debug_bridge .emit_execution_started ()
64- options = UiPathStreamOptions (resume = ctx .resume )
65- async for event in runtime .stream (ctx .get_input (), options = options ):
66- if isinstance (event , UiPathRuntimeResult ):
67- await debug_bridge .emit_execution_completed (event )
68- ctx .result = event
69- elif isinstance (event , UiPathRuntimeStateEvent ):
70- await debug_bridge .emit_state_update (event )
71- return ctx .result
72- finally :
73- if runtime :
74- await runtime .dispose ()
75- if factory :
76- await factory .dispose ()
77-
78-
7932def agents_debug_middleware (
8033 entrypoint : Optional [str ],
8134 input : Optional [str ],
8235 resume : bool ,
8336 input_file : Optional [str ],
8437 output_file : Optional [str ],
85- debug : bool ,
86- debug_port : int ,
8738 ** kwargs ,
8839) -> MiddlewareResult :
89- """Middleware to handle LangGraph execution"""
90-
91- if not setup_debugging (debug , debug_port ):
92- logger .error (f"Failed to start debug server on port { debug_port } " )
93-
40+ """Middleware to handle Agents LangGraph execution"""
9441 _prepare_agent_run_files ()
9542
9643 try :
@@ -99,6 +46,7 @@ async def execute_debug_runtime():
9946 trace_manager = UiPathTraceManager ()
10047
10148 with UiPathRuntimeContext .with_defaults (
49+ entrypoint = entrypoint ,
10250 input = input ,
10351 input_file = input_file ,
10452 output_file = output_file ,
@@ -117,7 +65,7 @@ async def execute_debug_runtime():
11765 factory = UiPathRuntimeFactoryRegistry .get (context = ctx )
11866
11967 runtime = await factory .new_runtime (
120- entrypoint , ctx .job_id or "default "
68+ ctx . entrypoint , ctx .job_id or "agents "
12169 )
12270
12371 debug_bridge : UiPathDebugBridgeProtocol = get_debug_bridge (ctx )
0 commit comments