함수 호출 — 도구 정의로 에이전트 만들기
함수 호출 — 도구 정의로 에이전트 만들기
모델에 **함수 호출(function calling)**을 붙이면, 모델이 정해진 도구를 호출하고 그 결과를 반영해 답합니다. 실세계 데이터가 필요한 작업을 에이전트로 만들 때 핵심이에요.
토큰: 팁/도구 추가하기
Mistral SDK에서 tools 파라미터로 도구 목록을 넘겨요. 각 도구는 이름과 JSON Schema 기반 파라미터로 정의합니다.
from mistralai import Mistral
client = Mistral(api_key="<YOUR_API_KEY>")
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "특정 도시의 현재 날씨를 가져온다",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "도시 이름"}
},
"required": ["city"],
},
},
}
]
response = client.chat.complete(
model="mistral-small-latest",
messages=[{"role": "user", "content": "서울 날씨 알려줘"}],
tools=tools,
)
도구 실행 루프
모델이 get_weather를 호출하겠다고 하면, 앱 쪽에서 그 함수를 실제로 실행하고 결과를 tool 역할 메시지로 돌려줘야 해요. 이렇게 모델 호출 → 도구 실행 → 다시 모델에 전달을 반복하면 최종 답을 만들 수 있습니다.
더 알아보기
https://docs.mistral.ai/guides/basics/function_calling/— 함수 호출 가이드https://docs.mistral.ai/guides/rag/— 문서 검색 기반 RAG 설정