Serialization converts in-memory objects into representations that services can transport or storage systems can persist; deserialization reverses that boundary. In service-oriented systems, SDK clients hide these conversions so a remote call can resemble an ordinary Python function. gRPC serializes Protocol Buffer requests into binary data, sends them across the network, and reconstructs responses as Python objects. section 4.5 section 2.4.2
A production serialization path commonly follows three transformations:
- Convert application-native values into a declared transport model, such as dictionaries into Protocol Buffer messages. section 3.9.2
- Serialize the transport model, send it through the network, then deserialize the response at the client boundary. section 4.5
- Use JSON when values have flexible shapes, such as strings, numbers, lists, or nested dictionaries, while exposing native Python values to callers. section 4.6.4
- Serialize checkpoint and job results before persistence so crashed workflows can reload state and completed jobs can expose stored results. section 9.2.2
Flexible memory values
A memory entry such as [{"name": "lisinopril", "dosage": "10mg"}] is JSON-encoded before a gRPC request, stored as a string, and decoded back into a native list when retrieved. The service boundary stays simple while the application retains flexible data types. section 4.6.4
Listing 3.18 ModelClient chat method implementation
def chat(
self,
model: str,
messages: List[Dict[str, Any]],
temperature: float = 0.7,
max_tokens: Optional[int] = None,
tools: Optional[List[Dict[str, Any]]] = None,
response_format: Optional[str] = None,
system_prompt_name: Optional[str] = None,
fallback_config: Optional[FallbackConfig] = None,
) -> ChatResponse:
pb_messages = [self._dict_to_proto_msg(m) for m in messages] #A
config = models_pb2.ChatConfig(temperature=temperature) #A
if max_tokens: #A
config.max_tokens = max_tokens #A
request = models_pb2.ChatRequest( #A
model=model, #A
messages=pb_messages, #A
config=config, #A
) #A
if system_prompt_name: #A
request.system_prompt_name = system_prompt_name #A
response = self._stub.Chat( #B
request, metadata=self._metadata) #B
return self._proto_to_chat_response(response) #CTrace a client method that converts dictionaries into Protocol Buffer messages, builds a typed request, invokes gRPC, and returns a Python response. section 3.9.2


























