Part 18 / Topic 3 of 6
Parallel tool calls
One model turn can request several tools at once. The rule: return all the tool_result blocks in one user message, each tied to its id — and errors go back as data, not as crashes:
# examples/02_a_tool_dispatcher_that_reports_errors.py (real run)
# {'type': 'tool_result', 'tool_use_id': 'toolu_1', 'content': '{"order_id": "A1001", "status": "shipped"}'}
# {'type': 'tool_result', 'tool_use_id': 'toolu_2', 'content': 'No order with id Z9999', 'is_error': True}
# {'type': 'tool_result', 'tool_use_id': 'toolu_3', 'content': "Unknown tool 'cancel_order'", 'is_error': True}
The dispatcher pattern: try the call; on failure return is_error: True with a message the model can read and recover from — given "No order with id Z9999", the model asks the user to check the id. A crashing tool kills the conversation; an error-reporting tool keeps the agent useful. Splitting results across messages discourages the model from parallel calls — keep them together.
🧪 Quick quiz
- The model calls three tools in one turn. How do you return the results?
Show the answer
All tool_result blocks in one user message, each with its matching tool_use_id — including the failures as is_error results (verified in the dispatcher example).
Done here? The practice set for Part 18 — 4 exercises with solutions — is on the part page.