Typed registry로서의 tools
TypeScript에선 tool registry를 strict 타입으로 인코드 가능 — 각 tool의 input 모양이 Zod 스키마나 TypeScript interface가 되고, 핸들러 시그니처가 거기서 흘러나옴. Python이 런타임에 찾는 tool-loop 버그 절반을 컴파일 타임 체크가 잡아.
같은 두-라운드 모양
프로토콜은 Python과 동일. Assistant content 리스트엔 tool_use 블록 포함; 후속 user 턴은 tool_use_id마다 tool_result 운반. 다른 점 단 하나 — TypeScript가 malformed 메시지 빌드를 허용 안 해, 타입이 막아.
Input validation엔 Zod
Tools가 input_schema(JSON Schema) 가져옴. Handler 호출 전에 모델의 tool input을 Zod로 validate — 모델이 가끔 args에 창의적이고, Zod parse 단계가 'maybe-string maybe-number'를 런타임 계약으로.
원칙: Input validation 없는 tool 루프는 모델 의도 추측. Validate, 아니면 버그 수용.