promptdojo_

Wire the real model — swap fake_llm for the Anthropic SDK shape — step 8 of 9

Write extract_text_and_tools(response) that takes a response object (real anthropic.types.Message OR a MockMessage with matching attribute access) and returns a tuple (text_parts, tool_calls):

  • text_parts is a list of strings, one per text block in response.content, in order.
  • tool_calls is a list of dicts, one per tool_use block, each shaped {"id": ..., "name": ..., "input": ...}.

Iterate response.content, branch on block.type, build both lists. Skip blocks whose type is neither "text" nor "tool_use" (forward-compat for thinking blocks — they exist but you don't need them here).

The script will run two cases. Expected output:

text=['Let me look that up.'] tools=[{'id': 'toolu_01', 'name': 'search', 'input': {'q': 'ramen'}}]
text=['Found a 2026 guide.', 'Hope this helps!'] tools=[]

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