Skip to content

featherweight.identity

identity

The identity of a run: who it is for, as a typed value the application defines.

An identity is a Pydantic model (class Teacher(BaseModel): user_id: str ...). The application declares the type once, where the framework has to check it and to rebuild it (AgentRunner(db, identity_type=Teacher)), and passes a value with identity=. Tools read it as runtime.context.identity. featherweight carries it: it does not authenticate anyone, decide what they may do, get a credential for them or keep them. See docs/specs/identity.md.

IdentitySpec

IdentitySpec(identity_type: Any = None)

What a runner (a worker, a client) declared as identity_type, and the checks that come with it.

None declares nothing: runs have no identity, and passing one is an error. A Pydantic model class makes an identity required. A union of one or more model classes and None (Teacher | None) allows a run without one. A union of several models (Teacher | Student) is for an agent or a job that serves different kinds of people: the kind of an identity, the name of its class, says which one it is.

describe

describe() -> str

The declaration as words, for an error message.

check

check(identity: Any) -> None

Raise TypeError for a programming error: an identity when no type is declared, none when one is required, or one that is not an instance of the declared type.

accepts

accepts(other: IdentitySpec) -> bool

Whether a run on this declaration can take every identity that other can produce: each of its models is one of ours (or a subclass of one), and if it allows no identity, so do we. A worker's type is other, and its runner's is self.

dump

dump(
    identity: Any,
) -> tuple[dict[str, Any] | None, str | None]

The identity as what travels in a queue message: its fields as JSON-ready data, without the ones marked exclude=True, and its kind (the name of its class). (None, None) for none.

load

load(data: Any, kind: str | None = None) -> Any

Rebuild an identity from dump's output: the model of the declared type that kind names, validated against data (ValidationError if it does not fit; ValueError if the kind is missing or is not one of the declared models). None is None when the type allows it.