본문 바로가기
C.W.K.
Stream
Lesson 01 of 07 · published

Tool Definition Schema — JSON Schema 위 contract

~22 min · tools, schema, function-calling

Level 0Tokenizer
0 XP0/54 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

tool parameters 는 JSON Schema 의 일부인 type, properties, required, enum, description 으로 정의해. strict mode 에서는 모델의 호출이 schema 에 정확히 맞아야 하므로 schema 가 arguments 구조의 기준이 돼.

API 마다 wrapper 가 달라

Responses 는 tool 객체의 최상위에 nameparameters 를 두고, Chat Completions 는 중첩된 function 객체 안에 둬. schema 본문은 같지만 wrapper 를 섞으면 호출이 깨질 수 있어.

모델은 handler 구현을 보지 못해

모델이 보는 건 name, description, 각 property 설명과 enum 을 포함한 parameters schema 야. 실제 handler 코드는 볼 수 없으므로 schema 로 표현하지 못한 사용 조건은 description 에 분명히 적어.

property 설명에는 값의 뜻을 적어

parameters.properties.units.description: 'temperature unit, celsius or fahrenheit' 처럼 값의 의미와 허용 범위를 알려줘. 'required'처럼 schema 자체가 이미 표현하는 정보만 되풀이하면 routing 에 도움이 되지 않아.

Code

Tool 정의 (Responses shape)·python
tools = [{
    "type": "function",
    "name": "get_weather",             # top-level name
    "description": "Get current weather for a location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City and country, e.g. 'London, UK'"
            },
            "units": {
                "type": ["string", "null"],
                "enum": ["celsius", "fahrenheit"],
                "description": "Temperature unit"
            }
        },
        "required": ["location", "units"],
        "additionalProperties": False
    },
    "strict": True,
}]
Tool 정의 (Chat Completions shape)·python
tools = [{
    "type": "function",
    "function": {                      # nested under "function"
        "name": "get_weather",
        "description": "Get current weather for a location.",
        "parameters": { ... },
        "strict": True,
    }
}]

External links

Exercise

send_email(to, subject, body, cc[]?, bcc[]?) tool 을 Responses 와 Chat Completions 형식으로 각각 정의해. 두 정의가 같은 handler 를 호출하는지 확인해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.