Function Calling and Tool Usage
Learning Objectives
By the end of this session, you will be able to:
Understand what Function Calling is
Learn why AI models need external tools
Understand how Tool Calling works
Explore real-world examples of AI tool usage
Learn how AI applications interact with APIs
Understand the relationship between Function Calling and AI Agents
Build a foundation for advanced agentic systems
Introduction
So far in this series, we have learned that Large Language Models (LLMs) are excellent at generating text.
They can:
Answer questions
Generate code
Summarize documents
Explain concepts
However, there is an important limitation.
LLMs can only generate responses based on:
Training data
Context provided in prompts
Retrieved information
They cannot directly:
Check the weather
Read a database
Send an email
Create a calendar event
Query a CRM system
Call a REST API
To perform these actions, AI systems need access to external tools.
This is where Function Calling and Tool Usage become important.
These capabilities transform AI systems from simple chatbots into intelligent assistants capable of interacting with real-world systems.
Why This Topic Matters
Imagine asking an AI assistant:
What is the current weather in Delhi?
A traditional LLM may not know the latest weather conditions.
A tool-enabled AI system can:
User Question
?
Weather API
?
Current Weather
?
AI Response
The AI retrieves live information and provides an accurate answer.
Similarly, businesses use tool-enabled AI systems to:
Query databases
Create support tickets
Send notifications
Generate reports
Manage workflows
Function Calling is one of the most important technologies behind modern AI assistants and AI agents.
The Limitation of Pure LLMs
Consider the question:
How many customers registered today?
A standard LLM cannot answer because:
It has no access to your database
It does not know today's data
It cannot query external systems
Without tools:
User
?
LLM
?
No Real-Time Information
With tools:
User
?
LLM
?
Database Query
?
Result
?
Response
This dramatically expands the capabilities of AI systems.
What Is Function Calling?
Function Calling allows an AI model to request the execution of predefined functions.
The model does not execute code itself.
Instead, it identifies:
Which function should be called
What parameters should be provided
The application executes the function and returns the results.
Example
User:
Book a meeting tomorrow at 10 AM.
AI determines:
{
"function": "create_calendar_event",
"date": "tomorrow",
"time": "10:00 AM"
}
The application executes the function.
The result is returned to the model.
The model then responds:
Your meeting has been scheduled.
Understanding Tool Calling
Function Calling is often considered a specific type of Tool Calling.
A tool can be:
API
Database query
Calculator
Search engine
File system
Email service
Calendar service
Simplified Workflow
User Request
?
LLM
?
Tool Selection
?
Tool Execution
?
Result
?
LLM Response
This pattern is used by many modern AI systems.
Real-World Example: Weather Assistant
User asks:
What is the weather in Mumbai today?
Step 1
The model recognizes:
Current weather information required
Step 2
The model selects:
Weather Tool
Step 3
Application calls:
Weather API
Step 4
Result returned:
31°C, Sunny
Step 5
Final response:
The current temperature in Mumbai is 31°C with sunny conditions.
The model becomes far more useful because it can access live information.
Why Function Calling Is Revolutionary
Before Function Calling:
AI = Text Generator
After Function Calling:
AI = Intelligent Assistant
The AI can now interact with:
Enterprise systems
Business applications
Cloud services
Databases
External APIs
This capability laid the foundation for modern AI Agents.
Function Calling Architecture
A simplified architecture:
+------------+
| User |
+------------+
|
v
+------------+
| LLM |
+------------+
|
v
+------------+
| Function |
| Selection |
+------------+
|
v
+------------+
| Tool/API |
+------------+
|
v
+------------+
| Result |
+------------+
|
v
+------------+
| Response |
+------------+
This pattern appears in nearly every enterprise AI solution.
Common Types of Tools
Database Tools
Used to:
Retrieve records
Search data
Generate reports
Example:
Get customer details.
Search Tools
Used to:
Search websites
Retrieve documentation
Find information
Example:
Find company leave policy.
File System Tools
Used to:
Read files
Create files
Analyze documents
Example:
Summarize this PDF.
Email Tools
Used to:
Draft emails
Send emails
Read messages
Example:
Send a meeting reminder.
Calendar Tools
Used to:
Create events
Check schedules
Manage appointments
Example:
Schedule a meeting.
Example: Database Tool
User asks:
Show my recent orders.
The AI generates:
{
"tool": "get_orders",
"customerId": 12345
}
The application queries:
Orders Database
Result:
Order 1001
Order 1002
Order 1003
The AI formats the information into a user-friendly response.
Example: Calculator Tool
User asks:
What is 457 × 932?
Instead of reasoning manually, the model may call:
{
"tool": "calculator",
"expression": "457*932"
}
Result:
425924
The final answer becomes more reliable.
Structured Outputs and Function Calling
In the previous session, we learned about structured outputs.
Function Calling relies heavily on structured responses.
Example:
{
"function": "search_products",
"category": "laptops",
"budget": 50000
}
The application can easily process this information.
This is why structured outputs and Function Calling are closely related.
Function Calling vs Traditional APIs
Traditional Software:
User
?
Frontend
?
Backend
?
API
AI-Powered Software:
User
?
LLM
?
Function Selection
?
API
?
Result
?
LLM
The AI becomes an intelligent layer between users and business systems.
Real-World Enterprise Use Cases
Customer Support
Tools:
CRM
Ticketing system
Knowledge base
Example:
Create a support ticket.
Banking
Tools:
Account lookup
Transaction history
Loan services
Example:
Show my account balance.
Human Resources
Tools:
Employee database
Leave management
Payroll systems
Example:
How many leave days do I have?
E-Commerce
Tools:
Product catalog
Inventory systems
Order management
Example:
Track my order.
Function Calling and AI Agents
Function Calling is a fundamental building block of AI Agents.
Without tools:
Agent
?
Conversation Only
With tools:
Agent
?
Reasoning
?
Tool Usage
?
Action
This enables agents to:
Perform tasks
Execute workflows
Automate processes
Later in this series, we will explore AI Agents in detail.
Example Agent Workflow
User:
Book a flight and add it to my calendar.
Agent:
1. Search flights
2. Select flight
3. Book flight
4. Create calendar event
5. Confirm completion
Each step may involve multiple tool calls.
This demonstrates how powerful tool-enabled AI systems can become.
Common Challenges
Incorrect Tool Selection
The model may choose the wrong tool.
Missing Parameters
Required information may be unavailable.
API Failures
External services can fail.
Security Concerns
Not every tool should be accessible.
Permission Management
Users should only access authorized resources.
These challenges become increasingly important in production environments.
Security Considerations
Organizations must carefully control:
Tool access
API permissions
Data exposure
User authorization
Example:
An AI assistant should not be able to:
Delete customer records
unless appropriate permissions exist.
Security is a critical part of AI system design.
Best Practices
Define Clear Tool Descriptions
Help the model understand when to use each tool.
Validate Inputs
Never trust generated parameters blindly.
Handle Errors Gracefully
Provide meaningful fallback responses.
Restrict Sensitive Operations
Use proper authorization controls.
Log Tool Usage
Track actions for auditing and debugging.
Architecture Diagram: Enterprise AI Assistant
User
?
AI Assistant
?
Tool Router
?
+---------------+
? ? ?
CRM Database Email
? ? ?
Results Returned
?
AI Response
This architecture is increasingly common in enterprise environments.
.NET Perspective
In .NET applications, Function Calling is commonly implemented using:
Semantic Kernel
Azure OpenAI
OpenAI SDK
ASP.NET Core APIs
Typical use cases:
Internal copilots
HR assistants
Customer support automation
Enterprise workflow systems
Function Calling integrates naturally with existing .NET business applications.
Python Perspective
Python provides strong support through:
OpenAI SDK
LangChain
CrewAI
LangGraph
LlamaIndex
Example:
def get_weather(city):
return "31°C Sunny"
# Tool available to AI model
The model decides when the function should be invoked.
The application executes it and returns the result.
Assignment
Design Activity
Create an AI assistant for a university.
Identify at least five tools it should use.
Examples:
Student records
Course catalog
Attendance system
Library database
Exam schedules
Architecture Exercise
Design a Function Calling workflow for:
AI Customer Support Assistant
Include:
User request
Tool selection
API call
Final response
Key Takeaways
Function Calling allows AI systems to interact with external tools.
Tool Calling extends AI beyond simple text generation.
AI models identify which tool should be used and what parameters are needed.
Function Calling enables access to databases, APIs, files, and business systems.
Structured outputs play a critical role in Tool Calling workflows.
Function Calling is a foundational technology behind AI Agents.
Most enterprise AI applications rely heavily on tool integrations.
What's Next?
In Session 12, we will explore:
Building Your First AI Application
You will learn how to combine prompts, model selection, structured outputs, and Function Calling to build a complete AI-powered application using modern development tools and frameworks.