d06 · Save and load history (~6 min)
Serialization. Edit drills.py. Standard library only; no model calls, no API key.
def dump_history(messages):
Return the conversation as JSON text.
Assistant content may hold SDK block objects (anthropic.types.TextBlock, ToolUseBlock), exactly as appended from response.content, mixed with plain dicts and string content.
def load_history(text):
Inverse of dump_history: return the history as plain dicts and lists, with each block's type/text or type/id/name/input intact, ready to send as messages=.
Failure messages are enough to go on, so leave the tests unread until you submit.