Function Calling / Tool Use: LLM 도구 사용
function-calling, function-calling-tool-use, function calling, tool use, tool calling
정의
Function Calling (또는 Tool Use) 은 LLM 이 정의된 함수/도구를 호출 인자를 생성 하는 기능. JSON schema 로 함수 시그니처를 알려주면, LLM 이 사용자 질의에 맞는 함수와 인자를 JSON 으로 반환.
OpenAI (2023), Anthropic Claude, Google Gemini, 오픈소스 (Llama 3.1+) 모두 지원.
예시
함수 스펙 정의
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" },
"unit": { "enum": ["C", "F"], "default": "C" }
},
"required": ["city"]
}
}
}
대화
사용자: “서울 날씨 알려줘”
LLM 응답:
{
"tool_calls": [{
"function": "get_weather",
"arguments": { "city": "Seoul", "unit": "C" }
}]
}
실행 후 결과 재주입
tool result: {"temp": 22, "condition": "sunny"}
LLM 이 최종 답변 생성: “서울은 현재 22°C 로 맑습니다.”
Agent 프레임워크
Function calling 을 반복적으로 활용:
- ReAct: Reasoning + Acting 사이클
- LangChain, LlamaIndex: 도구 오케스트레이션
- MCP (Model Context Protocol): Anthropic 의 표준 (2024)
함정
- 오호출: LLM 이 없는 함수를 호출하려 함. 스키마 검증 필수.
- 인자 hallucination: 필수 필드 누락, enum 아닌 값 반환
- 무한 루프: 도구 결과가 계속 다음 도구 호출 트리거
- 토큰 낭비: 도구 스펙 자체가 큰 컨텍스트 소비
💬 댓글