C.W.K.
Stream
Lesson 01 of 04 · published

Local Tool Calling 101

~18 min · tools, function-calling

Level 0Downloader
0 XP0/41 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Tool calling이 뭐야

Tool calling (function calling)은 모델이 직접 답하는 대신 외부 함수 실행을 요청하게 해. 모델이 구조화된 request 반환 — 함수 이름 + 인자. 아빠 코드가 함수 실행해서 결과 다시 보내면 모델이 거기서 이어서 가. 이게 LLM이 만 안 하고 행동하게 만드는 거야.

OpenAI 스타일 JSON Schema로 정의

Ollama는 호환성 위해 OpenAI tool 형식 사용:

  • 각 tool은 type: "function"이랑 function 객체 가짐.
  • functionname, description, parameters (JSON Schema) 가짐.
  • description은 모델이 이 tool 호출할지 결정할 때 읽는 거 — 신중한 1줄 docstring처럼 써.

모든 모델이 tool 지원하는 거 아님

Tool calling은 모델이 그렇게 학습됐어야 해. 안정적인 family: Qwen 2.5+ / 3 / 3.5, Llama 3.1+, Mistral / Mixtral, Command R, GPT-OSS, Qwen3-Coder. ollama show MODEL로 capability 확인 — capabilities 줄에서 tools 찾아.

Code

Tool 정의하고 모델 반환값 보기·python
import httpx, json

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city. Returns temperature and condition.",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "City name, e.g. 'Tokyo'"},
                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
            },
            "required": ["city"],
        },
    },
}]

resp = httpx.post(
    "http://localhost:11434/api/chat",
    json={
        "model": "qwen2.5:7b",
        "messages": [{"role": "user", "content": "What's the weather in Tokyo right now?"}],
        "tools": tools,
        "stream": False,
    },
    timeout=120.0,
)

msg = resp.json()["message"]
print(json.dumps(msg, indent=2))
# 기대: 빈 content, tool_calls가 get_weather(city="Tokyo")로 채워짐
보내기 전에 tool capability 확인·bash
# Tool 지원 안 하는 모델에 토큰 낭비 X
ollama show qwen2.5:7b | grep -i capabilities
# 봐야 할 것: list 안에 'tools'

# 'tools' 안 보이면 모델 업그레이드하거나 tools-capable variant 사용

External links

Exercise

search_files(pattern, directory) tool 정의해. '이번 주 수정된 모든 Python 파일 찾기' request 보내. 응답의 raw tool_calls 출력. 아직 실행하지 마 — 모델이 반환한 구조화된 request 관찰만.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.