canonicalize • AI Agent SDK

canonicalize: Map a raw, potentially-volatile platform id to a stable canonical id.

canonicalize

Method

</div>

This is a method of the BasePlatformAdapter class in the base module.

Map a raw, potentially-volatile platform id to a stable canonical id.

Consulted on the session-key path before link/pairing resolution so an alias/format change for the same human (e.g. WhatsApp’s JID→LID migration, a number↔UUID alias flip) collapses to one stable session key — preserving transcript, memory and in-flight run-state — instead of silently forking the conversation.

This is the :class:~praisonaiagents.gateway.protocols. IdentityCanonicalizerProtocol method, so a `BasePlatformAdapter` conforms structurally and can be handed anywhere that protocol is accepted.

Default is the identity function, so adapters that do not override this are fully backward-compatible (the raw id keys the session exactly as before). Implementations MUST be deterministic and total: return the raw id unchanged when no canonical form is known, never raise.

Signature

python
def canonicalize(platform: str, raw_user_id: str) -> str

Parameters

ParamField str

No description available.

ParamField str

No description available.

Returns

ResponseField str

The result of the operation.

Source

View on GitHub

praisonaiagents/bots/base.py at line 682