Tool loop 의 한 cycle 은 3 phase — (1) context 전송, 모델이 tool_calls 또는 텍스트 반환. (2) 텍스트면 종료. tool_calls 면 각 tool 실행 + 결과 capture. (3) 결과 다시 보냄, 모델이 텍스트 또는 또 다른 tool_call. tool_call 없을 때까지 loop.
Phase per phase
- Phase 1:
responses.create(input, tools=[...]). Output 이 tool_call 인지 텍스트인지 inspect. - Phase 2: 매 tool_call 의 name + arguments 로 handler 호출. 결과 capture.
- Phase 3: 결과를
function_call_output(Responses) 또는 tool-role 메시지 (Chat Completions) 로 다음 호출에 input. 텍스트 받을 때까지 반복.
Loop depth 항상 cap
max_tool_iterations=10. 모델이 ping-pong 무한 가능 (bad prompt 에서). Cap 없으면 multi-day rate-limit 사고가 multi-day spend 사고로 변환. Circuit breaker 명시적 abort 와 clear error.
Production 에선 hook 이 필수
매 iteration 의 tool, arguments, 결과를 JSONL 에 log. Replay-based 테스팅 (Production 트랙) 의 base — captured loop 를 CI 에서 replay 가능하게.