AI·에이전트

Anthropic function calling 30분 셋업

· · 추천 0 · 댓글 0 · 조회 60
const tools = [{
  name: 'get_weather',
  description: '날씨 가져오기',
  input_schema: {
    type: 'object',
    properties: { city: { type: 'string' } },
    required: ['city']
  }
}]

const res = await client.messages.create({
  model: 'claude-sonnet-4-7',
  tools,
  messages: [{ role: 'user', content: '서울 날씨' }]
})

if (res.stop_reason === 'tool_use') {
  const tool = res.content.find(c => c.type === 'tool_use')
  // execute tool, send result back
}

공식 docs 따라가면 30분. 첫 함수 호출 성공하면 다음은 쉬움