Home
Back to Overview

Function Calling & Tool Use

Transform LLMs from text generators into agents that can act

This is where text generation becomes agency - the foundation of all modern agent systems

What Makes an Agent?

Text Generator

🧠
LLM Only
Generates text responses
Capabilities:
  • ✓ Answer questions
  • ✓ Generate text
  • ✓ Explain concepts
Limitations:
  • ✗ No real-time data
  • ✗ No actions
  • ✗ Text only

Agent

🤖
LLM + Tools
Can think AND act
Capabilities:
  • ✓ Everything LLM can do
  • ✓ Access real-time data
  • ✓ Perform actions
  • ✓ Interact with systems
Power:
Can DO, not just SAY

The Key Difference

Function calling lets the LLM invoke predefined functions to access data or perform actions it cannot do alone. This transforms a text generator into an autonomous agent capable of interacting with the real world.

The Core Idea

🧠

Text Generator

Can only SAY

User: "What time is it?"
LLM: "I don't have access to real-time data..."
❌ Limited to training data
🤖

Agent

Can DO and SAY

User: "What time is it?"
Agent: *calls getCurrentTime()* → "It's 13:46"
✅ Can access real-world data

This is Agency

The ability to DO, not just SAY.

An agent transforms a language model from a passive text generator into an active system that can reason about actions, execute tools, and interact with the real world. This fundamental shift enables autonomous behavior and real-world problem-solving.

How It Works

1. Function Definition

getCurrentTime = {
description: "Get the current time",
handler: () => new Date().toLocaleTimeString()
}

2. LLM Sees Available Tools

Available functions:
  • • getCurrentTime: "Get the current time"
  • • getWeather: "Get weather for a city"
  • • calculate: "Perform math"

3. LLM Decides When to Use

"What time?" → getCurrentTime() ✓
"What's 5+5?" → calculate() ✓
"Tell a joke" → No tool needed

Real-World Applications

📅 Personal Assistant

Calendar, email, reminders

🔍 Research Agent

Web search, document reading

💻 Coding Assistant

File operations, code execution

📊 Data Analyst

Database queries, calculations

Agent Architecture

1

User Input

"What time is it?"
↓
2

LLM with Function Definitions

LLM analyzes the request and sees available tools. It decides which function to call.

Available Tools:
• getCurrentTime() - Get current time
• getWeather() - Get weather data
• calculate() - Perform calculations
Decision: Use getCurrentTime()
↓
3

Tool Executor

Executes the selected function and returns the result.

Function Call:
getCurrentTime()
Returns:
"1:46:36 PM"
↓
4

LLM Processes Result

LLM receives the tool result and formats it into a natural language response.

Input:
Tool result: "1:46:36 PM"
Output:
"It's 13:46"
↓
5

Final Response

"It's 13:46"

Architecture Flow

Components:
  • • LLM (Decision Maker)
  • • Function Registry
  • • Tool Executor
  • • Response Formatter
Key Features:
  • • Autonomous decision making
  • • Tool selection logic
  • • Result processing
  • • Natural language output

🛠️ Designing Good Tools

Tool Design Principles

  • ✓ Single Purpose: Each tool does one thing well
  • ✓ Clear Descriptions: LLM needs to understand when to use it
  • ✓ Explicit Parameters: Use JSON Schema for validation
  • ✓ Error Handling: Return clear error messages
  • ✓ Idempotent: Safe to call multiple times

Security Considerations

  • ⚠️ Validate Inputs: Never trust LLM parameters directly
  • ⚠️ Sanitize Outputs: Clean data before returning
  • ⚠️ Rate Limiting: Prevent abuse of expensive operations
  • ⚠️ Access Control: Check permissions before executing
  • ⚠️ Timeouts: Prevent hanging operations

Example Tools

Time Tools

  • • getCurrentTime()
  • • getDate()
  • • timezoneConvert()

Math Tools

  • • calculate()
  • • convertUnits()
  • • solveEquation()

Data Tools

  • • searchWeb()
  • • readFile()
  • • queryDatabase()

Key Takeaway

Function calling is THE feature that enables AI agents.
❌

Without it, LLMs can only talk

✅

With it, they can act

This is the foundation of all modern agent systems.

Next: Persistent Memory