Skip to main content

Python SDK for Perceptic Workflow definitions - cross-language Temporal workflow types

Project description

Perceptic Workflow SDK

Python SDK for Perceptic Workflow definitions. This package provides cross-language Temporal workflow types that are compatible with the Java workflow definitions in perceptic-core-client.

Installation

uv add perceptic-workflow-sdk

Usage

Runtime Input Contract

Workflows started through Perceptic Core receive a typed envelope:

  • AgentInput[T] where:
    • workflow_rid identifies the run
    • user_id identifies the authenticated caller
    • payload contains your workflow-specific input model T

On the wire, Perceptic Core sends camelCase (workflowRid, userId, payload). In Python, use snake_case (workflow_rid, user_id, payload) per PEP 8. The SDK handles alias mapping automatically.

Workflow Events

from perceptic_workflow import (
    WorkflowEvent,
    InfoEvent,
    CheckpointEvent,
    UserInputEvent,
    UserInputRequestEvent,
    WorkflowCheckpointStatus,
)

# Create events
info_event = InfoEvent(
    event_id=1,
    type="progress",
    payload={"step": "processing"},
    timestamp=datetime.now()
)

Implementing Workflows

The SDK provides a mixin class for implementing Perceptic-compatible workflows:

from pydantic import BaseModel
from temporalio import workflow
from perceptic_workflow import AgentInput, PercepticWorkflow, WorkflowEvent


class ResearchInput(BaseModel):
    query: str
    context: str

@workflow.defn
class MyWorkflow(PercepticWorkflow):
    def __init__(self):
        self._events: list[WorkflowEvent] = []
        self._paused = False

    @workflow.run
    async def run(self, input: AgentInput[ResearchInput]) -> dict:
        # Envelope fields use snake_case in Python.
        workflow_rid = input.workflow_rid
        user_id = input.user_id
        request = input.payload

        if request is None:
            raise ValueError("payload is required")

        return {
            "workflowRid": workflow_rid,
            "userId": user_id,
            "query": request.query,
            "context": request.context,
        }

    @workflow.update(name=PercepticWorkflow.UPDATE_SUBMIT_USER_INPUT)
    async def submit_user_input(self, inputs: dict) -> None:
        self._paused = False
        # Handle user input

    @workflow.update(name=PercepticWorkflow.UPDATE_INTERRUPT)
    async def interrupt(self, reason: str) -> None:
        # Handle interruption
        pass

    @workflow.query(name=PercepticWorkflow.QUERY_IS_PAUSED)
    def is_paused(self) -> bool:
        return self._paused

    @workflow.query(name=PercepticWorkflow.QUERY_GET_EVENTS)
    def get_events(self, after_event_id: int | None = None) -> list[WorkflowEvent]:
        if after_event_id is None:
            return self._events
        return [e for e in self._events if e.event_id > after_event_id]

Decorator Validation

PercepticWorkflow no longer performs runtime validation of Temporal handler decorators during class creation. This avoids import-time failures for abstract workflow bases and mixin-based inheritance patterns.

Handler contract enforcement is expected to happen through linting and type-check tooling in your development pipeline:

uv run ty check
uv run workflow-typecheck

Troubleshooting

  • ValidationError: Field required ... workflow_rid/user_id during workflow activation usually means your @workflow.run signature expects the wrong shape.
  • Use AgentInput[YourPayloadModel] for the first workflow argument, not a flattened domain model.
  • For run-start requests, send workflowRid and inputs; userId is derived from auth context by Perceptic Core.

Compatibility

This package is designed to be compatible with:

  • perceptic-core-client (Java)
  • perceptic-core-workflow-runtime (Java)

The workflow definitions and event types are generated from the same JSON Schema sources to ensure cross-language compatibility.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perceptic_workflow_sdk-0.50.99.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perceptic_workflow_sdk-0.50.99-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file perceptic_workflow_sdk-0.50.99.tar.gz.

File metadata

  • Download URL: perceptic_workflow_sdk-0.50.99.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for perceptic_workflow_sdk-0.50.99.tar.gz
Algorithm Hash digest
SHA256 2747f89cd4466af50a3309d0cdfbc9b13c81b7ceca34a3d93324ad57eb51b90b
MD5 d4efc0c8bac5af6385985e8bed7321db
BLAKE2b-256 7a54c2a79f22be94c8de7f1cdd040762b7212f096d6506df66f2b102ee20c613

See more details on using hashes here.

Provenance

The following attestation bundles were made for perceptic_workflow_sdk-0.50.99.tar.gz:

Publisher: publish-python.yml on perceptic/perceptic-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file perceptic_workflow_sdk-0.50.99-py3-none-any.whl.

File metadata

File hashes

Hashes for perceptic_workflow_sdk-0.50.99-py3-none-any.whl
Algorithm Hash digest
SHA256 cc056ff7731bd8bc9d6eb2efc79bff9ec4e3a91389ce23e275d41373f865695c
MD5 b244a929bd96cd56b8f3d35a07db64cc
BLAKE2b-256 a0085cff2346827c9c46152caf7c04937a4aebb92c479cf974d8d773a92a5132

See more details on using hashes here.

Provenance

The following attestation bundles were made for perceptic_workflow_sdk-0.50.99-py3-none-any.whl:

Publisher: publish-python.yml on perceptic/perceptic-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page