Extract connection setup/message building, tool-call round processing,
and the multi-round loop into three private helpers:
- _build_initial_messages() — static, constructs prompt message list
- _process_round_tool_calls() — executes one round of tool calls
- _run_tool_loop() — drives the multi-round loop, returns result tuple
run() is now ~35 lines of logic (down from 129), with error recovery
consolidated in a single return at the end.
Fixes#1135
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>