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: alltextfields joined with" | "(skip empty texts).tool_call_count: total number of tool_use blocks across all responses.total_tokens: sum oftokensacross all responses.final_stop: thestop_reasonof 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