promptdojo_

Write parse_response(response) that takes a response dict (from Anthropic's messages.create) and returns a structured dict:

  • text — string, joined text from all text-type blocks (joined with one space; empty string if none).
  • tool_uses — list of {"id": ..., "name": ..., "input": ...} dicts, one per tool_use-type block.
  • stop_reason — copy response["stop_reason"] through.
  • tokens — int, sum of usage.input_tokens + usage.output_tokens.

Skip any block whose type is neither text nor tool_use (e.g., thinking blocks).

Three responses run for you. Expected output:

text='Paris.' tool_uses=[] stop=end_turn tokens=37
text='Let me search.' tool_uses=[{'id': 't1', 'name': 'search', 'input': {'q': 'ramen'}}] stop=tool_use tokens=58
text='' tool_uses=[] stop=max_tokens tokens=1024

this step needs the editor

on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.

open this same url on a laptop to keep going today.