Function call 의 arguments 는 streaming 에서 JSON fragment 로 와. 개별 fragment 는 valid JSON 아냐 — {"loc, ation":", Seoul"} 같이 split. Concat 후 한 번에 json.loads.
왜 fragment 야?
모델이 token 단위로 생성하니까 arguments JSON 도 token 단위로 chunked. 매 token 이 한 chunk. 중간 fragment 에 json.loads 박는 건 guaranteed crash.
Accumulator 패턴
tool_call_id 별로 arguments_str 들고 있고, 매 fragment 를 append, stream 이 tool-call complete 신호 (또는 stream 끝) 일 때만 parse. SDK 가 이걸 abstract 하지만 raw httpx 에선 직접 작성.
여러 tool call 동시
한 turn 에 여러 tool call 이 가능 — tool_calls[i].function.arguments 의 i 가 인덱스. 각 인덱스별 accumulator 따로 — 섞지 마.