UiPath Runtime Python SDK

0.10.0 · active · verified Tue Apr 14

uipath-runtime provides foundational interfaces and base contracts for building agent runtimes in the UiPath ecosystem. It defines the protocols that all runtime implementations must follow, offering utilities for execution context, event streaming, tracing, structured error handling, durable execution, and human-in-the-loop interactions. This package, currently at version 0.10.0, is under rapid development, with minor version changes indicating potential breaking changes to public interfaces.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic custom runtime by implementing the `UiPathRuntimeProtocol`. This protocol defines essential methods like `get_schema`, `execute`, `stream`, and `dispose` that all custom UiPath runtimes should follow.

from typing import Any, AsyncGenerator, Optional
from uipath.runtime import (
    UiPathRuntimeResult,
    UiPathRuntimeStatus,
    UiPathRuntimeSchema,
    UiPathRuntimeEvent,
    UiPathExecuteOptions,
    UiPathStreamOptions,
    UiPathRuntimeProtocol
)

class MyRuntime(UiPathRuntimeProtocol):
    """Example runtime implementing the UiPath runtime protocols."""

    async def get_schema(self) -> UiPathRuntimeSchema:
        return UiPathRuntimeSchema(
            name="MyRuntime",
            description="A sample UiPath runtime",
            input_schema={'type': 'object', 'properties': {'name': {'type': 'string'}}},
            output_schema={'type': 'object', 'properties': {'message': {'type': 'string'}}},
        )

    async def execute(
        self, input: Any, options: Optional[UiPathExecuteOptions] = None
    ) -> UiPathRuntimeResult:
        name = input.get('name', 'World')
        message = f"Hello, {name}!"
        return UiPathRuntimeResult(status=UiPathRuntimeStatus.SUCCESS, output={'message': message})

    async def stream(
        self, input: Any, options: Optional[UiPathStreamOptions] = None
    ) -> AsyncGenerator[UiPathRuntimeEvent, None]:
        yield UiPathRuntimeEvent(name='start', payload={'input': input})
        await self.execute(input, options) # Simulate execution
        yield UiPathRuntimeEvent(name='end', payload={'result': 'success'})

    async def dispose(self) -> None:
        # Clean up resources if any
        pass

# To use this runtime (e.g., in a higher-level SDK or framework):
# runtime_instance = MyRuntime()
# schema = await runtime_instance.get_schema()
# print(schema.model_dump_json(indent=2))
# result = await runtime_instance.execute({'name': 'Alice'})
# print(result.model_dump_json(indent=2))

view raw JSON →