11# UiPath Runtime
22
3+ [ ![ PyPI downloads] ( https://img.shields.io/pypi/dm/uipath-runtime.svg )] ( https://pypi.org/project/uipath-runtime/ )
4+ [ ![ Python versions] ( https://img.shields.io/pypi/pyversions/uipath-runtime.svg )] ( https://pypi.org/project/uipath-runtime/ )
5+
36Core runtime abstractions and contracts for the UiPath Python SDK.
47
58## Overview
@@ -27,6 +30,33 @@ class MyCustomRuntime(UiPathBaseRuntime):
2730 def __init__ (self , context : UiPathRuntimeContext):
2831 super ().__init__ (context)
2932
33+ async def get_schema (self ) -> UiPathRuntimeSchema:
34+ # Returns the runtime's schema including entrypoint type and input/output JSON schemas.
35+ return UiPathRuntimeSchema(
36+ file_path = self .context.entrypoint,
37+ type = " agent" ,
38+ input = {
39+ " type" : " object" ,
40+ " properties" : {
41+ " message" : {
42+ " type" : " string" ,
43+ " description" : " Input message"
44+ }
45+ },
46+ " required" : [" message" ]
47+ },
48+ output = {
49+ " type" : " object" ,
50+ " properties" : {
51+ " result" : {
52+ " type" : " string" ,
53+ " description" : " Execution result"
54+ }
55+ },
56+ " required" : [" result" ]
57+ }
58+ )
59+
3060 async def execute (self ) -> UiPathRuntimeResult:
3161 # Execute your agent logic
3262 return UiPathRuntimeResult(
@@ -36,7 +66,7 @@ class MyCustomRuntime(UiPathBaseRuntime):
3666
3767 async def stream (
3868 self ,
39- ) -> AsyncGenerator[Union[ UiPathRuntimeEvent, UiPathRuntimeResult] , None ]:
69+ ) -> AsyncGenerator[UiPathRuntimeEvent, None ]:
4070 # Stream events during execution for real-time monitoring
4171 yield UiPathRuntimeStateEvent(
4272 payload = {" status" : " starting" },
@@ -69,30 +99,30 @@ class MyCustomRuntime(UiPathBaseRuntime):
6999The factory pattern handles runtime instantiation, instrumentation, and tracing:
70100
71101``` python
72- from uipath.runtime import UiPathRuntimeFactory, UiPathRuntimeContext
102+ from uipath.runtime import UiPathRuntimeFactory, UiPathRuntimeContext, UiPathRuntimeExecutor
73103
74- factory = UiPathRuntimeFactory(
75- MyCustomRuntime,
76- UiPathRuntimeContext,
77- )
104+ factory = UiPathRuntimeFactory(MyCustomRuntime)
105+
106+ executor = UiPathRuntimeExecutor()
78107
79108# Add OpenTelemetry instrumentation
80- factory .add_instrumentor(MyInstrumentor, get_current_span)
109+ executor .add_instrumentor(MyInstrumentor, get_current_span)
81110
82111# Add span exporters for tracing
83- factory .add_span_exporter(JsonLinesFileExporter(" trace.jsonl" ))
112+ executor .add_span_exporter(JsonLinesFileExporter(" trace.jsonl" ))
84113
85114# Execute
86115context = UiPathRuntimeContext(entrypoint = " main.py" , input = ' {"query": "hello"}' )
87- result = await factory.execute(context)
116+ async with factory.from_context(context):
117+ result = await executor.execute(runtime)
88118```
89119
90120### Event Streaming
91121
92122Runtimes can stream events during execution for real-time monitoring:
93123
94124``` python
95- async for event in factory .stream(context ):
125+ async for event in executor .stream(runtime ):
96126 if isinstance (event, UiPathRuntimeStateEvent):
97127 print (f " State update: { event.payload} " )
98128 elif isinstance (event, UiPathRuntimeMessageEvent):
0 commit comments