Skip to content

OrchestrationContext.call_entity does not provide any way to specify type for expected output #90

Closed

Description

The call_entity method currently returns Task[Unknown] that can break type-safety. Ideally, the call_entity method should provide a way to specify the type of the expected output (similar to how call_activity does (using TOutput) -

@abstractmethod
    def call_activity(self, activity: Union[Activity[TInput, TOutput], str], *,
                      input: Optional[TInput] = None,
                      retry_policy: Optional[RetryPolicy] = None,
                      tags: Optional[dict[str, str]] = None) -> Task[TOutput]:
        """Schedule an activity for execution.

        Parameters
        ----------
        activity: Union[Activity[TInput, TOutput], str]
            A reference to the activity function to call.
        input: Optional[TInput]
            The JSON-serializable input (or None) to pass to the activity.
        retry_policy: Optional[RetryPolicy]
            The retry policy to use for this activity call.
        tags: Optional[dict[str, str]]
            Optional tags to associate with the activity invocation.

        Returns
        -------
        Task
            A Durable Task that completes when the called activity function completes or fails.
        """
        pass

    @abstractmethod
    def call_entity(self, entity: EntityInstanceId,
                    operation: str,
                    input: Optional[TInput] = None) -> Task:
        """Schedule entity function for execution.

        Parameters
        ----------
        entity: EntityInstanceId
            The ID of the entity instance to call.
        operation: str
            The name of the operation to invoke on the entity.
        input: Optional[TInput]
            The optional JSON-serializable input to pass to the entity function.

        Returns
        -------
        Task
            A Durable Task that completes when the called entity function completes or fails.
        """
        pass

Error -

Image

Activity

  1. andystaples commented on Jan 12, 2026

    @andystaples
    Contributor

    The reason that knowing the output type is difficult is that it is determined based on the entity name from the entity ID, and the operation. For class-based entities, users are free to define operations as separate methods on the entity with different input and output types - we would need a way to dynamically retrieve the type-hinting for class methods which as far as I can tell, is not possible in time for static type checking.

    For now, I'll type-hint the Task as Task[Any] so the compiler stops complaining, but it'll be up to the user to check and cast back to the actual return type as needed.

  2. andystaples commented on Jan 12, 2026

    @andystaples
    Contributor

    Note: Here's a draft PR for slightly better behavior than what we have today (details in description) but there are several issues we will need to work out before deciding whether to merge. #103

  3. andystaples commented on Jul 16, 2026

    @andystaples
    Contributor

    Released in v1.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions