Skip to content

Policy Types

AbstractPolicy

Bases: Generic[E, N, P], ABC

A policy maps a tree with a given signature (contravariant parameter N) and inner policy type (covariant parameter P) to a search stream.

Note

We use an abstract class instead of a protocol to allow isinstance checks when loading policies dynamically.

Source code in src/delphyne/core/policies.py
18
19
20
21
22
23
24
25
26
27
28
29
30
class AbstractPolicy(Generic[E, N, P], ABC):
    """
    A policy maps a tree with a given signature (contravariant parameter
    N) and inner policy type (covariant parameter P) to a search stream.

    !!! note
        We use an abstract class instead of a protocol to allow
        `isinstance` checks when loading policies dynamically.
    """

    @abstractmethod
    def __call__[T](self, tree: "Tree[N, P, T]", env: E) -> AbstractStream[T]:
        pass

AbstractSearchPolicy

Bases: Generic[E, N], ABC

A search policy takes as arguments a tree with a given signature (covariant type parameter N), a global policy environment, and an inner policy with appropriate type, and returns a search stream.

Source code in src/delphyne/core/policies.py
33
34
35
36
37
38
39
40
41
42
43
44
class AbstractSearchPolicy(Generic[E, N], ABC):
    """
    A search policy takes as arguments a tree with a given signature
    (covariant type parameter `N`), a global policy environment, and an
    inner policy with appropriate type, and returns a search stream.
    """

    @abstractmethod
    def __call__[P, T](
        self, tree: "Tree[N, P, T]", env: E, policy: P
    ) -> AbstractStream[T]:
        pass

AbstractPromptingPolicy

Bases: Generic[E], ABC

A prompting policy takes as arguments a query (attached to a specific node) and a global policy environment, and returns a search stream.

Source code in src/delphyne/core/policies.py
47
48
49
50
51
52
53
54
55
56
57
58
class AbstractPromptingPolicy(Generic[E], ABC):
    """
    A prompting policy takes as arguments a query (attached to a
    specific node) and a global policy environment, and returns a search
    stream.
    """

    @abstractmethod
    def __call__[T](
        self, query: AttachedQuery[T], env: E
    ) -> AbstractStream[T]:
        pass