AI Agents by HandAll problemsAbout

All problems › Python drill · medium · ~6 min

d06 · Save and load history

json SDK blocks conversation state persistence

Solve it in your browser →

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.

Starter code and hidden tests open in the editor. Nothing to install.