# canonical_hooks_bytes

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/hooks/loading/canonical_hooks_bytes)

Serialize configuration into a stable byte representation.

## Signature

```python
canonical_hooks_bytes(
    config: HooksConfig,
    *,
    groups: Mapping[HookEvent, Sequence[SourcedGroup]] | None = None,
) -> bytes
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `config` | `HooksConfig` | Yes | Validated Hooks v2 configuration. |
| `groups` | `Mapping[HookEvent, Sequence[SourcedGroup]] \| None` | No | Matching sourced groups. When supplied, each group additionally records its non-file origin and environment overlay, so enabling a plugin that contributes hooks changes the snapshot id. Groups from the project and user files serialize identically either way. (default: `None`) |

## Returns

`bytes`

UTF-8 JSON with sorted keys, event order fixed to `HookEvent`, and

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/e4c1ffe9ee63d7854147de490ca27495ef157a7b/libs/code/deepagents_code/hooks/loading.py#L289)