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.
Tool Use / Function Calling
The ability of AI to use external tools such as calculators and search. A core foundational technology of agent systems.
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.
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๋์
๋๋ค."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
If a tool's description is ambiguous, the LLM will select the wrong tool. Describe clearly when and why it is used.
If there is no handling for tool execution failures, the entire workflow will stop. Be sure to implement try-catch and retry logic.
Write a detailed description for each tool, validate parameter types, implement graceful degradation on failure, and log tool calls.