๐Ÿค– AI/ML

Tool Use

Tool Use / Function Calling

The ability of AI to use external tools such as calculators and search. A core foundational technology of agent systems.

๐Ÿ“– Detailed Explanation

Tool Use refers to the ability of an LLM to go beyond text generation and perform real tasks by calling external tools or APIs. Also called Function Calling, it enables AI to utilize a variety of tools, such as calculators, web search, database queries, and file system access.

Tool Use took off in 2023 when OpenAI introduced the Function Calling feature in GPT-4. Since then, major LLMs such as Anthropic Claude and Google Gemini have all supported this feature, and it has become a core component of AI Agent systems.

Technically, Tool Use works as follows: the model expresses its intent to call a tool in a specific format (usually JSON), the system parses it to execute the actual function, and the result is passed back to the model. The model understands a tool's schema (name, description, parameters) and selects the right tool at the appropriate time.

In practice, Tool Use is at the core of a wide range of AI applications, including RAG systems, automated workflows, data analysis, and customer service bots. It is an essential technology for evolving from a simple chatbot into an AI Agent that performs real work.

๐Ÿ’ป Code Example

An example of Tool Use (Function Calling) with the OpenAI API.

from openai import OpenAI
import json

client = OpenAI()

# ๋„๊ตฌ ์ •์˜ (๋‚ ์”จ API ์˜ˆ์‹œ)
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "ํŠน์ • ์œ„์น˜์˜ ํ˜„์žฌ ๋‚ ์”จ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "๋„์‹œ๋ช… (์˜ˆ: ์„œ์šธ, ๋ถ€์‚ฐ)"
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": "์˜จ๋„ ๋‹จ์œ„"
                    }
                },
                "required": ["location"]
            }
        }
    }
]

# ์‹ค์ œ ๋„๊ตฌ ํ•จ์ˆ˜ ๊ตฌํ˜„
def get_weather(location: str, unit: str = "celsius") -> dict:
    """๋‚ ์”จ API ํ˜ธ์ถœ ์‹œ๋ฎฌ๋ ˆ์ด์…˜"""
    weather_data = {
        "์„œ์šธ": {"temp": 22, "condition": "๋ง‘์Œ"},
        "๋ถ€์‚ฐ": {"temp": 25, "condition": "ํ๋ฆผ"}
    }
    return weather_data.get(location, {"temp": 20, "condition": "์•Œ ์ˆ˜ ์—†์Œ"})

# LLM๊ณผ ๋Œ€ํ™”
messages = [{"role": "user", "content": "์„œ์šธ ๋‚ ์”จ ์–ด๋•Œ?"}]

response = client.chat.completions.create(
    model="gpt-4-turbo",
    messages=messages,
    tools=tools,
    tool_choice="auto"
)

# Tool Call ์ฒ˜๋ฆฌ
if response.choices[0].message.tool_calls:
    tool_call = response.choices[0].message.tool_calls[0]
    func_name = tool_call.function.name
    func_args = json.loads(tool_call.function.arguments)

    # ๋„๊ตฌ ์‹คํ–‰
    result = get_weather(**func_args)

    # ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ LLM์— ์ „๋‹ฌ
    messages.append(response.choices[0].message)
    messages.append({
        "role": "tool",
        "tool_call_id": tool_call.id,
        "content": json.dumps(result, ensure_ascii=False)
    })

    final_response = client.chat.completions.create(
        model="gpt-4-turbo",
        messages=messages
    )
    print(final_response.choices[0].message.content)
    # ์ถœ๋ ฅ: "์„œ์šธ์˜ ํ˜„์žฌ ๋‚ ์”จ๋Š” ๋ง‘๊ณ , ๊ธฐ์˜จ์€ 22๋„์ž…๋‹ˆ๋‹ค."

๐Ÿ—ฃ๏ธ Say It Like This in Practice

๐Ÿ’ฌ In a Meeting
"If we add Tool Use to this chatbot and integrate it with the actual reservation system, users will be able to look up and change reservations through conversation alone."
๐Ÿ’ฌ In an Interview
"I have experience developing AI Agents using Tool Use. I defined more than 10 tools and automated complex multi-step tasks with the ReAct pattern."
๐Ÿ’ฌ In a Technical Discussion
"Claude's Tool Use is more stable than GPT's in parallel function calling. If you need complex tool combinations, I recommend Claude 3.5 Sonnet."

Take a mock interview on this topic โ†’ WIA SOOM AI Interview ยท Start for free

โš ๏ธ Common Mistakes & Cautions

โŒ

Unclear tool descriptions

If a tool's description is ambiguous, the LLM will select the wrong tool. Describe clearly when and why it is used.

โŒ

Missing error handling

If there is no handling for tool execution failures, the entire workflow will stop. Be sure to implement try-catch and retry logic.

โœ…

The right way

Write a detailed description for each tool, validate parameter types, implement graceful degradation on failure, and log tool calls.

๐Ÿ”— Related Terms

๐Ÿ“š Learn More