인터리브드 씽킹
인터리브드 씽킹 (Interleaved Thinking)
도구 호출(tool calling)을 하는 모델은, 도구 결과를 받은 뒤에도 "그럼 이제 뭘 할까?" 하고 판단을 내릴 수 있어야 해요. 인터리브드 씽킹(Interleaved Thinking) 은 모델이 도구 호출 사이에 추론(reasoning) 단계를 끼워 넣을 수 있게 해주는 기능이에요. 도구 결과를 받은 뒤 더 정교한 의사 결정을 내릴 수 있게 돕죠.
소개 (Introduction)
인터리브드 씽킹을 켜면 모델이 여러 번의 도구 호출을 그 사이의 추론 단계와 함께 연결(chain) 할 수 있어요. 중간 결과를 바탕으로 더 세밀한(nuanced) 판단을 내릴 수 있게 됩니다.
⚠️ 중요: 인터리브드 씽킹은 토큰 사용량과 응답 지연 시간을 늘립니다. 이 기능을 활성화할 때는 예산과 성능 요구사항을 신중히 고려해야 해요.
인터리브드 씽킹은 어떻게 동작하나요? (How Interleaved Thinking Works)
인터리브드 씽킹을 사용하면 모델은 다음을 할 수 있어요.
- 도구 선택 과정에 대한 투명한 추론(transparent reasoning) 제공
- 중간 결과를 바탕으로 더 세밀한 판단 수행
- 여러 도구 호출을 그 사이의 추론 단계와 함께 연결
- 다음 행동을 결정하기 전에 도구 호출의 결과에 대해 추론
지원되는 모델 (Supported Models)
vLLM은 현재 다음 인터리브드 씽킹 모델을 지원해요.
| 모델 시리즈 | Reasoning Parser 이름 |
|---|---|
| moonshotai/Kimi-K2-Thinking | kimi_k2 |
| MiniMaxAI/MiniMax-M2 | minimax_m2 |
사용 예시 (Example Usage)
도구 호출과 함께 인터리브드 씽킹을 사용하려면, 이 기능을 지원하는 모델을 지정하고 채팅 완료 요청에서 도구 호출을 활성화하면 됩니다. 다음이 그 예시예요.
"""
vllm serve MiniMaxAI/MiniMax-M2 \
--tensor-parallel-size 4 \
--tool-call-parser minimax_m2 \
--reasoning-parser minimax_m2 \
--enable-auto-tool-choice
"""
import json
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
def get_current_weather(location: str, unit: "str"):
"""Get the current weather in a given location"""
if unit == "celsius":
return f"The current temperature in {location} is 22°C."
else:
return f"The current temperature in {location} is 72°F."
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g., 'San Francisco, CA'",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location", "unit"],
},
},
}
]
messages = [{"role": "user", "content": "What's the weather in Fahrenheit like in San Francisco?"}]
response = client.chat.completions.create(
model=client.models.list().data[0].id,
messages=messages,
tools=tools,
tool_choice="auto",
)
tool_call = response.choices[0].message.tool_calls[0].function
messages.append(
{
"role": "assistant",
"tool_calls": response.choices[0].message.tool_calls,
"reasoning": response.choices[0].message.reasoning, # append reasoning
}
)
서버를 실행할 때 --tool-call-parser minimax_m2, --reasoning-parser minimax_m2, --enable-auto-tool-choice를 지정하는 것을 볼 수 있어요. 이렇게 하면 각 도구 호출 사이에 reasoning이 자연스럽게 끼워져, 모델이 도구 결과를 보고 다음 판단을 내리게 됩니다. 응답 메시지의 reasoning 필드에 그 추론 내용이 담겨요.