promptdojo_

Reading the response — content blocks, stop_reason, usage — step 9 of 9

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Final drill. Build a session-level aggregator across multiple responses. Write summarize_session(responses) that:

  • For each response in the list, calls parse_response(r) (provided).
  • Aggregates across all responses:
    • total_text: all text fields joined with " | " (skip empty texts).
    • tool_call_count: total number of tool_use blocks across all responses.
    • total_tokens: sum of tokens across all responses.
    • final_stop: the stop_reason of the LAST response.
  • Returns the aggregate dict.

Two sessions run. Expected output:

agent session: text='Searching... | Found Tokyo ramen guide.' tools=1 tokens=180 final=end_turn
truncated session: text='Starting...' tools=0 tokens=1024 final=max_tokens

full-screen editor opens — close anytime to keep reading.