You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+80-55Lines changed: 80 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ Runtime abstractions and contracts for the UiPath Python SDK.
7
7
8
8
## Overview
9
9
10
-
`uipath-runtime` provides the foundational interfaces and base classes for building agent runtimes in the UiPath ecosystem.
11
-
It defines the contracts that all runtime implementations must follow and provides utilities for execution context, event streaming, tracing, and structured error handling.
10
+
`uipath-runtime` provides the foundational interfaces and base contracts for building agent runtimes in the UiPath ecosystem.
11
+
It defines the protocols that all runtime implementations must follow and provides utilities for execution context, event streaming, tracing, and structured error handling.
12
12
13
13
This package is typically used as a dependency by higher-level SDKs such as:
@@ -24,20 +24,21 @@ You would use this directly only if you're building custom runtime implementatio
24
24
uv add uipath-runtime
25
25
```
26
26
27
-
## Runtime Base Class
27
+
## Runtime Protocols
28
28
29
-
All runtimes inherit from `UiPathBaseRuntime` and implement these core methods:
29
+
All runtimes implement the `UiPathRuntimeProtocol` (or one of its sub-protocols):
30
30
31
31
-`get_schema()` — defines input and output JSON schemas.
32
32
-`execute(input, options)` — executes the runtime logic and returns a `UiPathRuntimeResult`.
33
33
-`stream(input, options)` — optionally streams runtime events for real-time monitoring.
34
-
-`cleanup()` — releases resources.
34
+
-`dispose()` — releases resources when the runtime is no longer needed.
35
+
36
+
Any class that structurally implements these methods satisfies the protocol.
35
37
36
38
```python
37
39
from typing import Any, AsyncGenerator, Optional
40
+
38
41
from uipath.runtime import (
39
-
UiPathBaseRuntime,
40
-
UiPathRuntimeContext,
41
42
UiPathRuntimeResult,
42
43
UiPathRuntimeStatus,
43
44
UiPathRuntimeSchema,
@@ -46,11 +47,10 @@ from uipath.runtime import (
46
47
UiPathStreamOptions,
47
48
)
48
49
from uipath.runtime.events import UiPathRuntimeStateEvent
49
-
from uipath.runtime.errors import UiPathRuntimeError, UiPathErrorCode, UiPathErrorCategory
50
50
51
51
52
-
classMyCustomRuntime(UiPathBaseRuntime):
53
-
"""Example runtime demonstrating the base runtime interface."""
52
+
classMyRuntime:
53
+
"""Example runtime implementing the UiPath runtime protocols."""
54
54
55
55
asyncdefget_schema(self) -> UiPathRuntimeSchema:
56
56
return UiPathRuntimeSchema(
@@ -73,7 +73,7 @@ class MyCustomRuntime(UiPathBaseRuntime):
73
73
) -> UiPathRuntimeResult:
74
74
message = (inputor {}).get("message", "")
75
75
return UiPathRuntimeResult(
76
-
output={"result": f"Echo: {message}"},
76
+
output={'message': 'Hello from MyRuntime'},
77
77
status=UiPathRuntimeStatus.SUCCESSFUL,
78
78
)
79
79
@@ -88,7 +88,7 @@ class MyCustomRuntime(UiPathBaseRuntime):
88
88
status=UiPathRuntimeStatus.SUCCESSFUL,
89
89
)
90
90
91
-
asyncdefcleanup(self) -> None:
91
+
asyncdefdispose(self) -> None:
92
92
pass
93
93
```
94
94
@@ -98,6 +98,12 @@ class MyCustomRuntime(UiPathBaseRuntime):
98
98
Runtimes can optionally emit real-time events during execution:
99
99
100
100
```python
101
+
from uipath.runtime.events import (
102
+
UiPathRuntimeStateEvent,
103
+
UiPathRuntimeMessageEvent,
104
+
)
105
+
from uipath.runtime.result import UiPathRuntimeResult
106
+
101
107
asyncfor event in runtime.stream({"query": "hello"}):
102
108
ifisinstance(event, UiPathRuntimeStateEvent):
103
109
print(f"State update: {event.payload}")
@@ -138,32 +144,41 @@ Resulting JSON contract:
138
144
139
145
## Runtime Factory
140
146
141
-
`UiPathRuntimeFactory` provides a consistent way to create and manage runtime instances.
147
+
`UiPathRuntimeFactoryProtocol` provides a consistent contract for discovering and creating runtime instances.
142
148
143
149
Factories decouple runtime construction (configuration, dependencies) from runtime execution, allowing orchestration, discovery, reuse, and tracing across multiple types of runtimes.
print(result.output) # {'message': 'Hello from MyRuntime'}
235
250
```
236
251
237
252
## Example: Runtime Orchestration
238
253
239
-
This example demonstrates an **orchestrator runtime** that receives a `UiPathRuntimeFactory`, creates child runtimes through it, and executes each one via `UiPathExecutionRuntime`, all within a single shared `UiPathTraceManager` and `UiPathRuntimeContext`.
254
+
This example demonstrates an **orchestrator runtime** that receives a `UiPathRuntimeFactoryProtocol`, creates child runtimes through it, and executes each one via `UiPathExecutionRuntime`, all within a single shared `UiPathTraceManager`.
240
255
241
256
<details>
242
257
<summary>Orchestrator Runtime</summary>
243
258
244
259
```python
245
-
from typing import Any, Optional, TypeVar, Generic
260
+
from typing import Any, Optional, AsyncGenerator
246
261
247
262
from uipath.core import UiPathTraceManager
248
263
from uipath.runtime import (
249
-
UiPathRuntimeContext,
250
-
UiPathBaseRuntime,
251
264
UiPathExecutionRuntime,
252
265
UiPathRuntimeResult,
253
266
UiPathRuntimeStatus,
254
267
UiPathExecuteOptions,
255
-
UiPathRuntimeFactory,
268
+
UiPathStreamOptions,
269
+
UiPathRuntimeProtocol,
270
+
UiPathRuntimeFactoryProtocol
256
271
)
257
272
258
273
259
-
classChildRuntime(UiPathBaseRuntime):
274
+
classChildRuntime:
260
275
"""A simple child runtime that echoes its name and input."""
261
276
262
-
def__init__(
263
-
self,
264
-
name: str,
265
-
):
266
-
super().__init__()
277
+
def__init__(self, name: str):
267
278
self.name = name
268
279
269
280
asyncdefget_schema(self):
@@ -283,29 +294,38 @@ class ChildRuntime(UiPathBaseRuntime):
0 commit comments