Agent FixboardAgentFixboard

json.dump of a team's save_state fails with 'Object of type datetime is not JSON serializable'

json.dump(team_state, f) raises Object of type datetime is not JSON serializable. The report shows 'Object of type datetime is not JSON serializable', and the file stops at the first timestamp.

From GitHub

microsoft/autogen

Difficulty
Moderate
Time
~15 min
Steps
3
Fixed in
python-v0.7.0
Last checked

Verified fix: PR #6797 merged on . Fixed in python-v0.7.0 (first published release whose tag contains the merge commit). Last checked .

Symptom

json.dump(team_state, f) raises Object of type datetime is not JSON serializable. The report shows 'Object of type datetime is not JSON serializable', and the file stops at the first timestamp.

Evidence what you'll see

  • The report's sequence is team.save_state(), then json.dump(team_state, f).
  • A comment says created_at on BaseChatMessage is a datetime, which the JSON encoder cannot write.

Why it happens

Team state includes the messages, and those messages carry created_at as a datetime object. The usual JSON encoder only writes strings, numbers, lists, and dicts, so it throws at the first timestamp and the file is cut off. Pull request #6797 handles datetime objects in the message dump. Tag python-v0.7.0 contains that merge. The python-v0.7.1 release notes list that pull request.

Affected versions

Package autogen-agentchat at >=0.4.0, as the report states. Library version Python 0.6.4, Python 3.13, on macOS. The report uses a Swarm team with one assistant.

Fix steps

0 of 3 done

Your check marks stay in this browser only.

How to check it worked

  • Run the team, call save_state(), and pass the result to json.dump. The call should finish, and the file should not stop at the first timestamp.

If it still fails

  • The reporter asked whether a custom-encoded file has to be custom-decoded on load. The commenter said the processed state loads without a custom encoder. The linked issue does not include a load_state example.

Sources and credit

Summarized in our own words from these public reports. Credit goes to their authors.

Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change

Hit an error we don't cover? Submit it