도구 호출
사용자 코드에서 실행하는 함수를 모델이 호출하도록 합니다.
tools에 함수를 정의합니다. 모델이 함수 호출이 필요하다고 판단하면 텍스트 대신 도구 호출을 반환합니다. 사용자 코드에서 함수를 실행한 후, 그 결과를 다음 요청에 포함해 보냅니다. Raon은 도구 정의를 그대로 모델에 전달하며, 웹 검색을 제외한 도구는 직접 실행하지 않습니다.
import json
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather in Seoul?"}]
completion = client.chat.completions.create(model="raon-1-mini-preview", messages=messages, tools=tools)
message = completion.choices[0].message
if message.tool_calls:
messages.append(message)
for call in message.tool_calls:
args = json.loads(call.function.arguments)
result = {"city": args["city"], "temperature_c": 18} # your function here
messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})
completion = client.chat.completions.create(model="raon-1-mini-preview", messages=messages, tools=tools)
print(completion.choices[0].message.content)Responses(function_call, function_call_output 항목)와 Messages(tool_use, tool_result 블록)도 각 API 형식에 맞춰 같은 방식으로 사용합니다.
권장 사항
- 함수와 파라미터 설명은 명확하게 작성하세요. 모델은 이 설명을 바탕으로 사용할 도구를 선택합니다.
- 일부 에이전트는 매 턴 도구 호출을 기대합니다. 에이전트가 항상 도구를 사용해야 한다면 시스템 프롬프트에 명시하세요.
- Messages의
tool_choice는auto,any,none을 지원합니다. 특정 도구를 지정하면 400 오류가 반환됩니다.

