Lesson 2

Function Calling

Giving LLMs abilities

🔧Function Calling: How AI Uses Tools

🤖 By itself, AI can only generate text. But if you give it descriptions of tools (functions), it can decide when to call them and with what parameters.

Available tools (click any):
👆

Select a tool above to see an example

Key Insight

Function Calling is like giving AI a phone number for a service. AI doesn't do the work itself, it "calls" the right function and uses its response. This lets you connect AI to databases, APIs, file systems — anything!

📝How to write Function Calling prompts
System Prompt Example:
You are an assistant with access to tools.
When the user asks for something that requires a tool:
1. Identify which tool is needed
2. Call it with correct parameters
3. Use the result to answer

Available tools are provided in the tools parameter.

This prompt explains to the model that it has access to tools and how to use them.

Tool Definition Example (JSON Schema):
{
  "name": "get_weather",
  "description": "Get current weather in a city",
  "parameters": {
    "type": "object",
    "properties": {
      "city": {
        "type": "string",
        "description": "City name"
      },
      "units": {
        "type": "string",
        "enum": ["celsius", "fahrenheit"]
      }
    },
    "required": ["city"]
  }
}

JSON Schema describes the function parameters: which fields are required, what data types are accepted.

Prompt Writing Tips:
  • Use clear descriptions: AI needs to understand when to use each tool
  • Specify required parameters via "required" in JSON Schema
  • Add example values in description for better understanding
  • Test your prompts: verify that AI correctly selects and calls functions