Missing Tool Results 오류

Missing Tool Results 오류

툴 호출 결과가 없는 상태로 모델에 새 메시지를 보낼 때 발생하는 AI_MissingToolResultsError 오류를 해결하는 문서예요.

출처: 문서

본문

문제

다음과 같은 메시지와 함께 AI_MissingToolResultsError 오류가 발생해요:

Tool results are missing for tool calls: ...

원인

이 오류는 이전 턴에서 아직 해결되지 않은 툴 호출(pending tool calls)이 있는데 새 메시지를 LLM(대규모 언어 모델)로 보내려 할 때 발생해요.

AI SDK 코어 로직은 진행하기 전에 대화 기록의 모든 tool-call 파트가 해결되었는지 검증해요. "해결됨(resolved)"은 보통 다음을 의미해요:

  1. 툴이 실행되어 tool-result가 기록에 추가되었어요.
  2. 또는, 툴 호출이 tool-approval-response를 촉발했어요(툴 승인을 사용하는 경우).

결과나 승인 응답이 없는 툴 호출이 발견되면, 모델에 유효하지 않은 대화 기록을 보내지 않도록 이 오류가 던져져요.

해결 방법

대화 기록의 모든 툴 호출이 제대로 처리되도록 하세요.

1. 툴 결과 제공하기

일반적인 툴 호출이라면 툴 실행 출력을 제공해야 해요.

const messages = [
  { role: 'user', content: 'What is the weather in NY?' },
  {
    role: 'assistant',
    content: [
      {
        type: 'tool-call',
        toolCallId: 'call_123',
        toolName: 'getWeather',
        args: { location: 'New York' },
      },
    ],
  },
  // You MUST include this tool message with the result:
  {
    role: 'tool',
    content: [
      {
        type: 'tool-result',
        toolCallId: 'call_123',
        toolName: 'getWeather',
        result: 'Sunny, 25°C',
      },
    ],
  },
  // Now you can add a new user message
  { role: 'user', content: 'And in London?' },
];

2. 툴 승인 처리하기

툴 승인 워크플로우를 사용한다면 tool-approval-response를 포함해야 해요.

const messages = [
  // ... assistant requests tool execution (needs approval)
  {
    role: 'tool',
    content: [
      {
        type: 'tool-approval-response',
        approvalId: 'approval_123',
        approved: true, // or false
      },
    ],
  },
];

더 알아보기 (Learn more)

전체 사이트맵