AgentFixboard

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

Saving a team's state to a JSON file raises a TypeError, and the file is cut off at the first timestamp.

From GitHub

microsoft/autogen

Difficulty
Easy
Time
~5 min
Steps
1
Fixed in
python-v0.7.1
Last checked

Verified fix: PR #6797 merged on . Fixed in python-v0.7.1 (first stable release containing the merge commit). Last checked .

Symptom

Saving a team's state to a JSON file raises a TypeError, and the file is cut off at the first timestamp.

Evidence what you'll see

  • TypeError: Object of type datetime is not JSON serializable
  • The error is raised by json.dump(team_state, f) after team.save_state()
  • Seen with a Swarm team, but any team with messages in its state is affected

Cause

Messages and events carry a created_at datetime field, and the message dump kept it as a datetime object instead of a JSON-safe value.

Fix steps

0 of 1 done

Your check marks stay in this browser only.

Verify the fix worked

  • Run a team, call save_state(), and confirm json.dump writes the whole state without errors.

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