Beginner LevelAI, LLMs, Embeddings & MCP
How does LLM Tool Calling (Function Calling) allow models to execute external API code?
❓ Interview Prompt: Explain function declarations, structured JSON tool calls, application execution loops, and returning tool outputs.
Tool Calling (Function Calling) enables an LLM to interact with external APIs, databases, and local system code.
Execution Loop Steps:
1
Tool Definition: Application passes JSON Schema declarations of available functions to the LLM.
2
Model Decision: If the query requires an external tool, the model returns a structured tool call request (JSON) instead of plain text.
3
App Execution: Application executes the actual local function or API call.
4
Result Feedback: Application sends function execution results back to the LLM as a
tool role message to generate the final response.Code Implementation Example
typescript
// Function declaration passed to LLM
const getWeatherTool = {
name: 'get_current_weather',
description: 'Get real-time temperature for a city',
parameters: {
type: 'object',
properties: {
location: { type: 'string', description: 'City name e.g. Tokyo' }
},
required: ['location']
}
};
// Application handles tool call request from model
if (response.toolCalls) {
const call = response.toolCalls[0];
if (call.name === 'get_current_weather') {
const data = await fetchWeather(call.args.location);
// Return data back to LLM...
}
}💡Declaring tools and handling function execution requests from an LLM.
🎯 Interview Key Takeaway
Tool calling allows LLMs to return structured JSON specifying function names and arguments for application code execution.
#Function Calling#Tools#JSON Schema#Beginner
Back to all AI, LLMs, Embeddings & MCP Questions→