penzai.data_effects.local_state.freeze_local_states(handled: WithFunctionalLocalState, states: dict[str, Any]) Any[source]#

Embeds the given states into a handled model, and removes the handler.

This function converts a functionalized stateful model into a single effectful one, making it easier to inspect, patch, or serialize. It is roughly the inverse of handle_local_states, and handle_local_states can be used to re-install the handler.

  • handled – A WithFunctionalLocalState wrapping a model, as constructed using handle_local_states.

  • states – A state dictionary, either from handle_local_states or from calling the handled model to get updated states.


A copy of the original model, without the WithFunctionalLocalState wrapper, and with each of the states embedded as a FrozenLocalStateRequest inside the tree.