Skip to content

Types

conatus._types

Types used throughout the library.

TypeOfType module-attribute

TypeOfType = (
    object
    | GenericAlias
    | TypeAliasType
    | UnionType
    | TypeVar
    | str
    | type
)

The type of a type hint.

Unfortunately, we have to include object here, since some of the type hints we deal with (e.g. Annotated) are a typing special form, meaning that their type cannot be expressed in a Python file, at least as of Python 3.13.

ParamType module-attribute

ParamType = object | None

The type of a parameter.

This is essentially a more rigorous version of Any.

FunctionType module-attribute

FunctionType = (
    FunctionType | MethodType | Callable[..., ParamType]
)

The type of a function.

Can be either a Python function or a method.

OptionalArg module-attribute

OptionalArg: TypeAlias = V | NotGiven

Optional argument type.

This is a type that can be either a value or the NotGiven sentinel object.

CTUS_NOT_GIVEN module-attribute

CTUS_NOT_GIVEN = NotGiven()

Not given sentinel object, specific to our project.

PrimitiveType module-attribute

PrimitiveType = str | int | float | bool | None

Primitive type.

SimpleDict module-attribute

SimpleDict = Mapping[
    str, PrimitiveType | Mapping[str, PrimitiveType] | None
]

Simple dictionary type with max depth of 2.

ExpectedTaskInputType module-attribute

ExpectedTaskInputType: TypeAlias = Literal[
    "none", "singleton", "list", "dict"
]

The type of the expected task input.

Possible values are:

  • "none": The task has no input.
  • "singleton": The task has a single input.
  • "list": The task has a list of inputs.
  • "dict": The task has a dictionary of inputs.

ExpectedTaskOutputType module-attribute

ExpectedTaskOutputType: TypeAlias = ExpectedTaskInputType

The type of the expected task output.

Existing module-attribute

Existing = Annotated[T, ExistingVariable]

An annotated type to indicate that a variable already exists.

In practice, Existing is a marker class that is used for an Action or ActionBlueprint to indicate that only existing variables should be used. This means, in practice, that an AI will not be able to pass a value for the variable, even if the type is JSON-compatible.

RawAction module-attribute

RawAction: TypeAlias = (
    "Action | ActionBlueprint | ActionStarterPack | FunctionType"
)

A raw action that can be converted to an action.

Can be either:

IteratorAsyncFn module-attribute

IteratorAsyncFn = Callable[
    ..., Coroutine[ParamType, ParamType, AsyncIterator[T]]
]

A async function that yields an async iterator.

AsyncFn module-attribute

AsyncFn = Callable[..., Coroutine[ParamType, ParamType, T]]

A async function that returns a value.

NotGiven

A sentinel object to represent a missing argument.

__bool__

__bool__() -> Literal[False]

Return False.

Source code in conatus/_types.py
def __bool__(self) -> Literal[False]:
    """Return False."""
    return False

__repr__

__repr__() -> str

Return the string representation of the sentinel object.

Source code in conatus/_types.py
@override
def __repr__(self) -> str:
    """Return the string representation of the sentinel object."""
    return "NOT_GIVEN"

FunctionDefinition

Bases: TypedDict

A function definition mirroring OpenAI's FunctionDefinition.

name instance-attribute

name: Required[str]

The name of the function.

description instance-attribute

description: Required[str]

The description of the function.

parameters instance-attribute

parameters: Required[dict[str, ParamType]]

The parameters of the function.

strict instance-attribute

strict: Required[bool]

Whether the function is strict.

StructuredOutputDefinition

Bases: TypedDict

A structured output definition.

name instance-attribute

name: Required[str]

The name of the structured output.

description instance-attribute

description: Required[str]

The description of the structured output.

schema instance-attribute

schema: Required[dict[str, ParamType]]

The schema of the structured output.

strict instance-attribute

strict: Required[bool]

Whether the structured output is strict.

ExistingVariable

An annotation marker to indicate that a variable already exists.