|
1 | 1 | # UiPath Runtime |
2 | 2 |
|
| 3 | +[](https://pypi.org/project/uipath-runtime/) |
| 4 | +[](https://pypi.org/project/uipath-runtime/) |
| 5 | + |
3 | 6 | Core runtime abstractions and contracts for the UiPath Python SDK. |
4 | 7 |
|
5 | 8 | ## Overview |
@@ -27,16 +30,41 @@ class MyCustomRuntime(UiPathBaseRuntime): |
27 | 30 | def __init__(self, context: UiPathRuntimeContext): |
28 | 31 | super().__init__(context) |
29 | 32 |
|
| 33 | + async def get_schema(self) -> UiPathRuntimeSchema: |
| 34 | + # Returns the runtime's JSON schemas |
| 35 | + return UiPathRuntimeSchema( |
| 36 | + input={ |
| 37 | + "type": "object", |
| 38 | + "properties": { |
| 39 | + "message": { |
| 40 | + "type": "string", |
| 41 | + "description": "Input message" |
| 42 | + } |
| 43 | + }, |
| 44 | + "required": ["message"] |
| 45 | + }, |
| 46 | + output={ |
| 47 | + "type": "object", |
| 48 | + "properties": { |
| 49 | + "result": { |
| 50 | + "type": "string", |
| 51 | + "description": "Execution result" |
| 52 | + } |
| 53 | + }, |
| 54 | + "required": ["result"] |
| 55 | + } |
| 56 | + ) |
| 57 | + |
30 | 58 | async def execute(self) -> UiPathRuntimeResult: |
31 | | - # Execute your agent logic |
| 59 | + # Execute framework-specific agent invoke logic |
32 | 60 | return UiPathRuntimeResult( |
33 | 61 | output={"result": "success"}, |
34 | 62 | status=UiPathRuntimeStatus.SUCCESSFUL |
35 | 63 | ) |
36 | 64 |
|
37 | 65 | async def stream( |
38 | 66 | self, |
39 | | - ) -> AsyncGenerator[Union[UiPathRuntimeEvent, UiPathRuntimeResult], None]: |
| 67 | + ) -> AsyncGenerator[UiPathRuntimeEvent, None]: |
40 | 68 | # Stream events during execution for real-time monitoring |
41 | 69 | yield UiPathRuntimeStateEvent( |
42 | 70 | payload={"status": "starting"}, |
@@ -69,30 +97,30 @@ class MyCustomRuntime(UiPathBaseRuntime): |
69 | 97 | The factory pattern handles runtime instantiation, instrumentation, and tracing: |
70 | 98 |
|
71 | 99 | ```python |
72 | | -from uipath.runtime import UiPathRuntimeFactory, UiPathRuntimeContext |
| 100 | +from uipath.runtime import UiPathRuntimeFactory, UiPathRuntimeContext, UiPathRuntimeExecutor |
73 | 101 |
|
74 | | -factory = UiPathRuntimeFactory( |
75 | | - MyCustomRuntime, |
76 | | - UiPathRuntimeContext, |
77 | | -) |
| 102 | +factory = UiPathRuntimeFactory(MyCustomRuntime) |
| 103 | + |
| 104 | +executor = UiPathRuntimeExecutor() |
78 | 105 |
|
79 | 106 | # Add OpenTelemetry instrumentation |
80 | | -factory.add_instrumentor(MyInstrumentor, get_current_span) |
| 107 | +executor.add_instrumentor(MyInstrumentor, get_current_span) |
81 | 108 |
|
82 | 109 | # Add span exporters for tracing |
83 | | -factory.add_span_exporter(JsonLinesFileExporter("trace.jsonl")) |
| 110 | +executor.add_span_exporter(JsonLinesFileExporter("trace.jsonl")) |
84 | 111 |
|
85 | 112 | # Execute |
86 | 113 | context = UiPathRuntimeContext(entrypoint="main.py", input='{"query": "hello"}') |
87 | | -result = await factory.execute(context) |
| 114 | +async with factory.from_context(context): |
| 115 | + result = await executor.execute(runtime) |
88 | 116 | ``` |
89 | 117 |
|
90 | 118 | ### Event Streaming |
91 | 119 |
|
92 | 120 | Runtimes can stream events during execution for real-time monitoring: |
93 | 121 |
|
94 | 122 | ```python |
95 | | -async for event in factory.stream(context): |
| 123 | +async for event in executor.stream(runtime): |
96 | 124 | if isinstance(event, UiPathRuntimeStateEvent): |
97 | 125 | print(f"State update: {event.payload}") |
98 | 126 | elif isinstance(event, UiPathRuntimeMessageEvent): |
|
0 commit comments