> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# canonicalize • AI Agent SDK

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

# canonicalize

<div className="flex items-center gap-2">
  <Badge color="purple">Method</Badge>
</div>

> This is a method of the [**BasePlatformAdapter**](../classes/BasePlatformAdapter) class in the [**base**](../modules/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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def canonicalize(platform: str, raw_user_id: str) -> str
```

## Parameters

<ParamField query="platform" type="str" required={true}>
  No description available.
</ParamField>

<ParamField query="raw_user_id" type="str" required={true}>
  No description available.
</ParamField>

### Returns

<ResponseField name="Returns" type="str">
  The result of the operation.
</ResponseField>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/bots/base.py#L461">
  `praisonaiagents/bots/base.py` at line 461
</Card>
