Skip to content

Replace private encode/decode imports with pickle serialization#28

Merged
pamelafox merged 1 commit intoAzure-Samples:mainfrom
pamelafox:encodefix
Mar 4, 2026
Merged

Replace private encode/decode imports with pickle serialization#28
pamelafox merged 1 commit intoAzure-Samples:mainfrom
pamelafox:encodefix

Conversation

@pamelafox
Copy link
Contributor

Summary

Remove usage of private agent_framework._workflows._checkpoint_encoding functions (encode_checkpoint_value, decode_checkpoint_value) in the PostgreSQL checkpoint storage examples, per microsoft/agent-framework#4428. These are internal APIs not meant for public use.

Changes

Both examples/workflow_hitl_checkpoint_pg.py and examples/spanish/workflow_hitl_checkpoint_pg.py:

  • Removed from agent_framework._workflows._checkpoint_encoding import decode_checkpoint_value, encode_checkpoint_value
  • Removed from psycopg.types.json import Jsonb
  • Added import pickle for direct serialization
  • Changed DB column from JSONB to BYTEA since we're storing binary pickle data
  • Simplified save: pickle.dumps(checkpoint) instead of encode_checkpoint_value(checkpoint.to_dict()) + Jsonb()
  • Simplified load/list/get_latest: pickle.loads(row["data"]) instead of WorkflowCheckpoint.from_dict(decode_checkpoint_value(...))
  • Updated docstrings to reflect pickle-based storage and include security warnings

Rationale

Per the MAF maintainer's response, encode_checkpoint_value/decode_checkpoint_value are intentional internals — custom checkpoint storage backends should implement their own serialization.

WorkflowCheckpoint contains live framework objects (WorkflowMessage, WorkflowEvent, etc.) that aren't directly JSON-serializable, so straight JSON isn't an option without reimplementing the same pickle+base64 hybrid the private API uses internally. Direct pickleBYTEA is the simplest correct approach and mirrors what MAF's built-in FileCheckpointStorage does under the hood.

Remove usage of private agent_framework._workflows._checkpoint_encoding
functions (encode_checkpoint_value, decode_checkpoint_value) in the
PostgreSQL checkpoint storage examples, as these are internal APIs not
meant for public use (see microsoft/agent-framework#4428).

Instead, serialize WorkflowCheckpoint objects directly with pickle and
store as BYTEA in PostgreSQL. This is simpler than reimplementing the
pickle+base64 hybrid that the private API uses, and avoids depending on
internals that may break across releases.
@madebygps
Copy link
Contributor

lgtm!

@pamelafox pamelafox merged commit 3b348ae into Azure-Samples:main Mar 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants