Serialization

Overview

Many components in Gen AI Builder can be serialized and deserialized using the to_dict and from_dict methods. There are also to_json and from_json as a convenience.

Here is how we can serialize an Agent and then deserialize it back:

Serialization Overrides

All classes that implement the SerializableMixin can be serialized using the above methods. However, only fields marked with metadata={"serializable": True} will be included in the serialization process. If you need to add or remove fields in the serialization process, you can pass serialization_overrides to any of the serialization methods.

Types Overrides

Due to some unfortunate internals of the Gen AI Builder's serialization process, you may occasionally run into a NameError when serializing. It will look something like this:

NameError: name 'BaseWebSearchDriver' is not defined

This is something we're actively working on fixing, but in the meantime, you can use the types_overrides parameter to pass in a dictionary of types that need to be overridden during serialization.

Here is an example of how you can use types_overrides:


Could this page be better? Report a problem or suggest an addition!