Thinking 모드

Thinking 모드

DeepSeek 모델은 최종 답변을 내놓기 전에 먼저 사고(chain-of-thought) 추론을 거치는 thinking 모드를 지원해요. 이 과정을 거치면 최종 응답의 정확도가 올라가요. 기본적으로 켜져 있고, 끄거나 추론 강도를 조절할 수도 있어요.

출처: https://api-docs.deepseek.com/guides/thinking_mode

켜기/끄기와 추론 강도

제어 파라미터는 사용하는 API 포맷에 따라 조금씩 달라요.

제어 항목 OpenAI 포맷 Anthropic 포맷 Responses API 포맷
Thinking 모드 켜기/끄기 {"thinking": {"type": "enabled/disabled"}} {"reasoning": {"effort": "none/low/high/max"}} (none은 모드 끔)
추론 강도 {"reasoning_effort": "low/high/max"} {"output_config": {"effort": "low/high/max"}}

Thinking 모드는 기본적으로 켜져 있고 기본 추론 강도는 high예요. 사용자가 설정한 강도가 실제 추론 강도로 매핑되는 관계는 deepseek-v4-flashdeepseek-v4-pro가 동일해요.

요청한 강도 실제 매핑된 강도
low low
medium high
high high
xhigh high
max max

Chat Completion에서 OpenAI SDK로 thinking 파라미터를 쓰려면 extra_body 안에 넣어야 해요.

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    # ...
    reasoning_effort="high",
    extra_body={"thinking": {"type": "enabled"}}
)

입력·출력 파라미터

Thinking 모드에서는 temperature, top_p, presence_penalty, frequency_penalty 파라미터를 지원하지 않아요. 기존 소프트웨어와의 호환성을 위해 이 값들을 설정해도 오류가 나진 않지만 효과도 없어요.

thinking 모드에서 사고 내용은 content와 같은 레벨의 reasoning_content 파라미터로 돌아와요. 이후 턴의 문맥을 이어붙일 때 reasoning_content를 API에 다시 넘길지는 상황에 따라 달라져요.

  • user 메시지 사이에 모델이 도구 호출을 하지 않았다면, 중간 assistantreasoning_content는 문맥 이어붙이기에 참여하지 않아도 돼요. 이후 턴에서 API에 넘겨도 무시돼요.
  • user 메시지 사이에 모델이 도구 호출을 했다면, 중간 assistantreasoning_content는 문맥 이어붙이기에 반드시 참여해야 하고, 이후 모든 턴에서 API에 다시 넘겨야 해요.

다중 턴 대화

각 턴에서 모델은 사고(reasoning_content)와 최종 답변(content)을 함께 내놓아요. 도구 호출이 없으면 이전 턴의 사고 내용은 다음 턴 문맥에 이어붙지 않아요. 아래 코드처럼 두 번째 턴에서 첫 번째 턴의 reasoning_content를 다시 넘겨도 API가 무시해요.

from openai import OpenAI
client = OpenAI(api_key="<DeepSeek API Key>", base_url="https://api.deepseek.com")

# Turn 1
messages = [{"role": "user", "content": "9.11 and 9.8, which is greater?"}]
response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=messages,
    reasoning_effort="high",
    extra_body={"thinking": {"type": "enabled"}},
)

reasoning_content = response.choices[0].message.reasoning_content
content = response.choices[0].message.content

# Turn 2
# reasoning_content는 API가 무시해요
messages.append(response.choices[0].message)
messages.append({'role': 'user', 'content': "How many Rs are there in the word 'strawberry'?"})
response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=messages,
    reasoning_effort="high",
    extra_body={"thinking": {"type": "enabled"}},
)

도구 호출

DeepSeek 모델의 thinking 모드는 도구 호출도 지원해요. 최종 답변을 내기 전에 여러 번의 추론과 도구 호출을 반복해 응답 품질을 높일 수 있어요.

주의할 점이 있어요. tools 파라미터를 담은 요청에서는 reasoning_content를 이후 모든 요청에 완전히 다시 넘겨야 해요. 제대로 넘기지 않으면 API가 400 오류를 돌려줘요. 턴 안에서 생긴 reasoning_content는 계속 API에 보내져서 모델이 이전 추론을 이어갈 수 있게 하고, response.choices[0].message에는 content, reasoning_content, tool_callsassistant 메시지에 필요한 모든 필드가 들어가 있어요.

더 알아보기

  • 도구 호출을 이어서 배우려면 «도구 호출 (Tool Calls)» 문서를 봐요.
  • 다중 턴 대화 기본은 «다중 턴 대화» 문서를 봐요.
  • 채팅 완성 API의 전체 파라미터는 «채팅 완성 API» 문서를 봐요.