PromptisePromptise
PlatformSoonEnterprise
DocsGitHub
Talk to usGet started
Promptise - AI Framework LogoPromptise

The full-stack framework for agentic systems. Build with the framework. Run it on the platform. Launch it with our engineers.

pip install promptise

[01] Product

  • Framework
  • Platform (coming soon)
  • Enterprise
  • How it works
  • Contact

[02] Framework

  • The Agent
  • The Interface
  • The Harness

[03] Resources

  • Documentation
  • GitHub
  • Why Promptise
  • Use cases
  • Roadmap
  • Guides
  • Learning Paths
  • Questions

[04] Company

  • About
  • Terms of Service
  • Privacy Policy
  • Cookie Policy
  • Subprocessors

© 2026 Promptise by Manser Ventures. All rights reserved.

hello@promptise.com
← Learning paths> Agentic Engineering with Promptise Foundry
Lesson 17 / 100
17%

What Is Tool Calling? LLM Function Calling Explained

What tool calling (function calling) is: how an LLM asks your code to run a function, the JSON schema it sees, parallel calls, and how it differs from MCP.

Beginner7 minTool CallingModel Context Protocol (MCP)
All 100 lessons↓
  1. ✓What Is an AI Agent? Definition, How It Works, Examples
  2. ✓How to Build an AI Agent in Python (2026 Guide)
  3. ✓Build a Personal AI Agent: Memory, Reminders, Chat
  4. ✓What Is an Agent Harness? Parts and How to Build One
  5. ✓System Prompt Best Practices for AI Agents in Python
  6. ✓Best LLM for AI Agents (2026): Picks, Prices, How to Test
  7. ✓AI Agent YAML: Define and Run an Agent From a Config File
  8. ✓Streaming LLM Responses with FastAPI: Tokens and Tool Calls
  9. ✓Best Local LLM for AI Agents: Ollama Models by GPU (2026)
  10. ✓Claude AI Agent with MCP: Use Anthropic Models in Promptise
  11. ✓Gemini AI Agent with MCP: Use Google Models in Promptise
  12. ✓Azure OpenAI Agent with MCP: Use Deployments in Promptise
  13. ✓OpenRouter AI Agent with MCP: Many Models in Promptise
  14. ✓Ollama AI Agent with MCP: Run Local Models in Promptise
  15. ✓LLM Semantic Cache and Model Fallback in Python
  16. ✓What Is MCP (Model Context Protocol)? A Developer's Guide
  17. 17What Is Tool Calling? LLM Function Calling Explained
  18. 18MCP Tools vs Resources vs Prompts (With Python Examples)
  19. 19How to Connect MCP Servers to Your AI Agent in Python
  20. 20Build a Production MCP Server in Python (Step by Step)
  21. 21MCP Transports: stdio vs Streamable HTTP vs SSE (Python)
  22. 22MCP 2026-07-28 Migration: Make Your MCP Server Stateless
  23. 23OpenAPI to MCP: Turn Any REST API into an MCP Server
  24. 24MCP Authentication in Python: API Keys, JWT and OAuth
  25. 25Build an Authenticated MCP Server for Your AI Agent (Python)
  26. 26MCP Security Best Practices: A Checklist for MCP Servers
  27. 27Testing MCP Servers in Python: pytest Without a Live Server
  28. 28Too Many MCP Tools? How to Fix LLM Tool Selection in Python
  29. 29Idempotent Tool Calls: Make AI Agent Retries Safe
  30. 30AI Agent Tool Failures: Stop Unsafe Workarounds
  31. 31MCP Server Caching, Timeouts and Circuit Breakers in Python
  32. 32MCP Middleware for Servers: Auth, Logging, Rate Limits
  33. 33MCP vs CLI for AI Agents: Tokens, Security, When to Use Each
  34. 34LangChain vs MCP: Differences and How They Work Together
  35. 35FastMCP Alternatives for Production MCP Servers (2026)
  36. 36AI Agent Audit Logging: Tamper-Evident Logs in Python
  37. 37AI Agent Human in the Loop: Approve Tool Calls in Python
  38. 38AI Agent Prompt Injection: How to Defend Against It
  39. 39Hidden Text Prompt Injection: Sanitize Pages for AI Agents
  40. 40Build a Multi-Agent System in Python (and When Not To)
  41. 41Context Engineering for AI Agents: Context Window Management
  42. 42Context Compaction for AI Agents: Trim vs Summarize
  43. 43How to Deploy an AI Agent with Docker (2026 Guide)
  44. 44LLM Tool Rate Limiting: Per-Client Limits for MCP Servers
  45. 45MCP Long-Running Tasks: Background Jobs in Python
  46. 46MCP Server Monitoring: Prometheus, OpenTelemetry and Logs
  47. 47Best AI Agent Frameworks (2026): Python Options Compared
  48. 48Self-Improving AI Agent: Learn From Tool Failures in Python
  49. 49AI Agent Identity: Authenticate Agents to MCP Servers
  50. 50Code-Action Agents in Python: One Program vs 37 Tool Calls
  51. 51Multi-Tenant AI Agents: Keep Each Customer's Data Apart
  52. 52What Is Agentic RAG? How It Differs from Classic RAG
  53. 53AI Agent Memory in Python: Short-Term and Long-Term
  54. 54Per-User Agent Memory Isolation: Stop Leaks Between Users
  55. 55Agentic RAG in Python: Give Your AI Agent a Search Tool
  56. 56AI Agent Reasoning Patterns in Python: From ReAct to Debate
  57. 57Plan-and-Execute Agents in Python: Beyond the ReAct Loop
  58. 58Self-Modifying AI Agent in Python: Open Mode & Limits
  59. 59CrewAI Alternatives: 7 Options and How to Migrate (2026)
  60. 60Migrate from AutoGen: Agent Framework, AG2 and More
  61. 61What Is an LLM Guardrail? Types, Examples and Limits
  62. 62Best LLM Guardrails Tools (2026): 9 Platforms Compared
  63. 63AI Agent Guardrails in Python: Block Injection, Redact PII
  64. 64NeMo Guardrails vs Guardrails AI: Which to Choose (2026)
  65. 65AI-Based PII Detection and Redaction Tools for LLM Apps
  66. 66Stop Secrets Leaking Into LLM Logs and Traces
  67. 67AI Agent Code Execution Sandbox: Run LLM Code Safely
  68. 68AI Agent Network Egress: Limit Where Agents Can Connect
  69. 69AutoGen Docker Task Isolation: Secure the Code Executor
  70. 70SPIFFE for AI Agents: Workload Identity Without API Keys
  71. 71On-Behalf-Of Auth for AI Agents: Act as Each User
  72. 72AI Agent Production Checklist: What to Check Before Launch
  73. 73Approval Fatigue: Auto-Approve Safe AI Agent Actions
  74. 74What Is Human in the Loop AI? Approvals for AI Agents
  75. 75AI Agent Notifications: Webhook and Slack Alerts in Python
  76. 76AI Agent Observability: Trace Tool Calls, Tokens and Cost
  77. 77Best AI Agent Observability Tools (2026), Compared
  78. 78AI Agent Stuck in a Loop? How to Detect and Stop It
  79. 79How to Run, Debug and Deploy an AI Agent in Python
  80. 80AI Agent Cost Tracking: Tokens and Cost per Run and User
  81. 81How to Evaluate AI Agents: Evals, LLM Judges and pass^k
  82. 82AI Agent Cost Control: Budgets That Stop Runaway Spend
  83. 83How to Test LLM Prompts and AI Agents in Python
  84. 84AI Agent Evals in CI: Run Them on Every Pull Request
  85. 85What Is an Agentic Runtime? AI Agent Runtimes Explained
  86. 86Autonomous AI Agent Runtime: Budgets, Crash Recovery, API
  87. 87Event-Driven AI Agents: Webhook, Cron and File Triggers
  88. 88AI Agent Cron Jobs: Run an Agent on a Schedule
  89. 89AI Agent Webhook Trigger: Run an Agent on HTTP Events
  90. 90AI Agent File Watcher: Process New Files Automatically
  91. 91Custom AI Agent Triggers: Wake an Agent From Any Source
  92. 92AI Agent Event Filters: Skip Runs Before the LLM
  93. 93AI Agent Retries and a Dead Letter Queue for Failed Runs
  94. 94Run Multiple AI Agents: One Runtime, Many Processes
  95. 95AI Agent Manifest: Declare a Long-Running Agent in YAML
  96. 96AI Agent CLI: Start, Stop and Inspect Running Agents
  97. 97AI Agent Monitoring Dashboard in the Terminal
  98. 98Multi-Agent Event Bus: Chain Agents With Events
  99. 99Distributed AI Agents: Run Agents Across Many Machines
  100. 100Pause and Resume an AI Agent: Lifecycle States Explained

Lessons in this path

  1. ✓What Is an AI Agent? Definition, How It Works, Examples
  2. ✓How to Build an AI Agent in Python (2026 Guide)
  3. ✓Build a Personal AI Agent: Memory, Reminders, Chat
  4. ✓What Is an Agent Harness? Parts and How to Build One
  5. ✓System Prompt Best Practices for AI Agents in Python
  6. ✓Best LLM for AI Agents (2026): Picks, Prices, How to Test
  7. ✓AI Agent YAML: Define and Run an Agent From a Config File
  8. ✓Streaming LLM Responses with FastAPI: Tokens and Tool Calls
  9. ✓Best Local LLM for AI Agents: Ollama Models by GPU (2026)
  10. ✓Claude AI Agent with MCP: Use Anthropic Models in Promptise
  11. ✓Gemini AI Agent with MCP: Use Google Models in Promptise
  12. ✓Azure OpenAI Agent with MCP: Use Deployments in Promptise
  13. ✓OpenRouter AI Agent with MCP: Many Models in Promptise
  14. ✓Ollama AI Agent with MCP: Run Local Models in Promptise
  15. ✓LLM Semantic Cache and Model Fallback in Python
  16. ✓What Is MCP (Model Context Protocol)? A Developer's Guide
  17. 17What Is Tool Calling? LLM Function Calling Explained
  18. 18MCP Tools vs Resources vs Prompts (With Python Examples)
  19. 19How to Connect MCP Servers to Your AI Agent in Python
  20. 20Build a Production MCP Server in Python (Step by Step)
  21. 21MCP Transports: stdio vs Streamable HTTP vs SSE (Python)
  22. 22MCP 2026-07-28 Migration: Make Your MCP Server Stateless
  23. 23OpenAPI to MCP: Turn Any REST API into an MCP Server
  24. 24MCP Authentication in Python: API Keys, JWT and OAuth
  25. 25Build an Authenticated MCP Server for Your AI Agent (Python)
  26. 26MCP Security Best Practices: A Checklist for MCP Servers
  27. 27Testing MCP Servers in Python: pytest Without a Live Server
  28. 28Too Many MCP Tools? How to Fix LLM Tool Selection in Python
  29. 29Idempotent Tool Calls: Make AI Agent Retries Safe
  30. 30AI Agent Tool Failures: Stop Unsafe Workarounds
  31. 31MCP Server Caching, Timeouts and Circuit Breakers in Python
  32. 32MCP Middleware for Servers: Auth, Logging, Rate Limits
  33. 33MCP vs CLI for AI Agents: Tokens, Security, When to Use Each
  34. 34LangChain vs MCP: Differences and How They Work Together
  35. 35FastMCP Alternatives for Production MCP Servers (2026)
  36. 36AI Agent Audit Logging: Tamper-Evident Logs in Python
  37. 37AI Agent Human in the Loop: Approve Tool Calls in Python
  38. 38AI Agent Prompt Injection: How to Defend Against It
  39. 39Hidden Text Prompt Injection: Sanitize Pages for AI Agents
  40. 40Build a Multi-Agent System in Python (and When Not To)
  41. 41Context Engineering for AI Agents: Context Window Management
  42. 42Context Compaction for AI Agents: Trim vs Summarize
  43. 43How to Deploy an AI Agent with Docker (2026 Guide)
  44. 44LLM Tool Rate Limiting: Per-Client Limits for MCP Servers
  45. 45MCP Long-Running Tasks: Background Jobs in Python
  46. 46MCP Server Monitoring: Prometheus, OpenTelemetry and Logs
  47. 47Best AI Agent Frameworks (2026): Python Options Compared
  48. 48Self-Improving AI Agent: Learn From Tool Failures in Python
  49. 49AI Agent Identity: Authenticate Agents to MCP Servers
  50. 50Code-Action Agents in Python: One Program vs 37 Tool Calls
  51. 51Multi-Tenant AI Agents: Keep Each Customer's Data Apart
  52. 52What Is Agentic RAG? How It Differs from Classic RAG
  53. 53AI Agent Memory in Python: Short-Term and Long-Term
  54. 54Per-User Agent Memory Isolation: Stop Leaks Between Users
  55. 55Agentic RAG in Python: Give Your AI Agent a Search Tool
  56. 56AI Agent Reasoning Patterns in Python: From ReAct to Debate
  57. 57Plan-and-Execute Agents in Python: Beyond the ReAct Loop
  58. 58Self-Modifying AI Agent in Python: Open Mode & Limits
  59. 59CrewAI Alternatives: 7 Options and How to Migrate (2026)
  60. 60Migrate from AutoGen: Agent Framework, AG2 and More
  61. 61What Is an LLM Guardrail? Types, Examples and Limits
  62. 62Best LLM Guardrails Tools (2026): 9 Platforms Compared
  63. 63AI Agent Guardrails in Python: Block Injection, Redact PII
  64. 64NeMo Guardrails vs Guardrails AI: Which to Choose (2026)
  65. 65AI-Based PII Detection and Redaction Tools for LLM Apps
  66. 66Stop Secrets Leaking Into LLM Logs and Traces
  67. 67AI Agent Code Execution Sandbox: Run LLM Code Safely
  68. 68AI Agent Network Egress: Limit Where Agents Can Connect
  69. 69AutoGen Docker Task Isolation: Secure the Code Executor
  70. 70SPIFFE for AI Agents: Workload Identity Without API Keys
  71. 71On-Behalf-Of Auth for AI Agents: Act as Each User
  72. 72AI Agent Production Checklist: What to Check Before Launch
  73. 73Approval Fatigue: Auto-Approve Safe AI Agent Actions
  74. 74What Is Human in the Loop AI? Approvals for AI Agents
  75. 75AI Agent Notifications: Webhook and Slack Alerts in Python
  76. 76AI Agent Observability: Trace Tool Calls, Tokens and Cost
  77. 77Best AI Agent Observability Tools (2026), Compared
  78. 78AI Agent Stuck in a Loop? How to Detect and Stop It
  79. 79How to Run, Debug and Deploy an AI Agent in Python
  80. 80AI Agent Cost Tracking: Tokens and Cost per Run and User
  81. 81How to Evaluate AI Agents: Evals, LLM Judges and pass^k
  82. 82AI Agent Cost Control: Budgets That Stop Runaway Spend
  83. 83How to Test LLM Prompts and AI Agents in Python
  84. 84AI Agent Evals in CI: Run Them on Every Pull Request
  85. 85What Is an Agentic Runtime? AI Agent Runtimes Explained
  86. 86Autonomous AI Agent Runtime: Budgets, Crash Recovery, API
  87. 87Event-Driven AI Agents: Webhook, Cron and File Triggers
  88. 88AI Agent Cron Jobs: Run an Agent on a Schedule
  89. 89AI Agent Webhook Trigger: Run an Agent on HTTP Events
  90. 90AI Agent File Watcher: Process New Files Automatically
  91. 91Custom AI Agent Triggers: Wake an Agent From Any Source
  92. 92AI Agent Event Filters: Skip Runs Before the LLM
  93. 93AI Agent Retries and a Dead Letter Queue for Failed Runs
  94. 94Run Multiple AI Agents: One Runtime, Many Processes
  95. 95AI Agent Manifest: Declare a Long-Running Agent in YAML
  96. 96AI Agent CLI: Start, Stop and Inspect Running Agents
  97. 97AI Agent Monitoring Dashboard in the Terminal
  98. 98Multi-Agent Event Bus: Chain Agents With Events
  99. 99Distributed AI Agents: Run Agents Across Many Machines
  100. 100Pause and Resume an AI Agent: Lifecycle States Explained
← Path overview

Tool calling is how a language model asks your code to run a function, such as looking up an order or querying a database, and then uses the result in its answer. OpenAI calls it function calling, Anthropic calls it tool use, and most frameworks say tool calling. This page shows the request and response cycle with a real run, explains parallel calls, and separates tool calling from MCP, structured outputs and agents.

[01]

What is tool calling?

Tool calling (also called function calling) is an LLM API feature that lets a model ask your application to run a function. You send tools as names, descriptions and JSON schemas. When a tool would help, the model replies with a structured call instead of text. Your code runs it and returns the result.

Key takeaways:

  • The model never executes anything. It returns a tool name and JSON arguments. OpenAI's function calling guide puts it plainly: when the model calls a function, you must execute it and return the result.

  • The schema is the interface. The model only knows what the name, description and parameter schema tell it. Vague descriptions cause wrong calls.

  • One turn can contain several calls. Models can request parallel tool calls when the calls don't depend on each other.

  • Tool calling is the building block of agents. An agent is tool calling in a loop.


[02]

How does tool calling work?

Every provider follows the same cycle. OpenAI's guide lists five steps: send a request with the tools the model may call, receive a tool call, run your code with the call's arguments, send a second request with the tool output, and receive a final answer or more tool calls.

A sequence between your app and the model API: the app sends messages and tool schemas, the model returns a get_weather tool call, your code runs it, the app sends the tool result with the same call ID, and the model replies with a final answer or more tool calls.
FigureThe five steps of a tool call between your app and the model API

The details differ by provider. In the OpenAI API the reply carries tool_calls, and you return each result as a tool message with the matching call ID. In the Anthropic API the reply has stop_reason: "tool_use" and one or more tool_use blocks, and you answer with tool_result blocks, as its tool use docs describe. Anthropic also runs some server tools, such as web search, on its own infrastructure; for your own tools, your code still does the work.

Two options matter in practice. Parallel tool calls let the model ask for several calls in one turn; OpenAI's parallel_tool_calls: false limits it to zero or one. Strict mode (strict: true) makes the arguments match your schema exactly, which OpenAI recommends enabling. OpenAI introduced function calling in June 2023, and every major model API now supports some version of it.


[03]

A tool calling example

The script prints the schema the model receives for a small Python function, then asks a question that needs two lookups. Promptise Foundry's @tool decorator generates the schema from the function's signature and docstring, and the agent runs the call cycle for you.

Pythontool_calling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import asyncio
import json

from langchain_core.utils.function_calling import convert_to_openai_tool
from promptise import build_agent, tool

FORECASTS = {"Paris": "14°C, light rain", "Tokyo": "22°C, clear"}


@tool
def get_weather(city: str) -> str:
    """Current weather for a city."""
    return FORECASTS.get(city, "No data")


async def main():
    # 1. What the model receives: a name, a description and a JSON schema.
    print(json.dumps(convert_to_openai_tool(get_weather), indent=2))

    # 2. What the model sends back, and what the agent does with it.
    agent = await build_agent(
        model="openai:gpt-5-mini",
        instructions="Answer briefly.",
        extra_tools=[get_weather],
    )
    try:
        result = await agent.ainvoke(
            {"messages": [{"role": "user", "content": "Is it warmer in Paris or Tokyo?"}]}
        )
        for msg in result["messages"][1:]:
            for call in getattr(msg, "tool_calls", None) or []:
                print(f"tool call  id={call['id'][:12]}...  {call['name']} {call['args']}")
            if msg.type == "tool":
                print(f"result     id={msg.tool_call_id[:12]}...  {msg.content}")
            elif msg.content:
                print(f"answer     {msg.content}")
    finally:
        await agent.shutdown()


asyncio.run(main())

Real output from one run with gpt-5-mini:

Output
{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "Current weather for a city.",
    "parameters": {
      "properties": {
        "city": {
          "type": "string"
        }
      },
      "required": [
        "city"
      ],
      "type": "object"
    }
  }
}
tool call  id=call_6BqLkdr...  get_weather {'city': 'Paris'}
tool call  id=call_z6aZl8L...  get_weather {'city': 'Tokyo'}
result     id=call_6BqLkdr...  14°C, light rain
result     id=call_z6aZl8L...  22°C, clear
answer     Tokyo is warmer — 22°C (clear) vs Paris 14°C (light rain).

The first block is everything the model knows about the tool: its name, one sentence of description and a schema with one required string. The model then asked for both cities in a single turn, two parallel calls with different IDs. Each result goes back with the ID of the call it answers, which is how the model matches results to requests. The answer comes from the tool results, not from the model's training data.

Note what is missing from the schema: the city parameter has no description. For a tool this simple that's fine. For tools with dates, IDs or units, describe each parameter, or the model will guess the format. How LLM tool calling works has more design rules for tools and results.


[04]

Tool calling vs function calling, MCP and structured outputs

Term

What it is

Who runs the code

Use it for

Tool calling

Model API feature: the model returns a structured call to one of your tools

Your application

Letting a model use APIs, databases and code

Function calling

OpenAI's name for the same feature

Your application

Same as tool calling

MCP (Model Context Protocol)

A protocol for discovering and calling tools that live in a separate server

The MCP server, called by your app's MCP client

Reusing tools across agents and apps

Structured outputs

The model's final answer is forced to match a JSON schema

Nobody: it is just output

Extracting data in a fixed shape

AI agent

A loop that repeats tool calling until a goal is met

Your application, or a framework

Multi-step tasks

MCP and tool calling work together rather than compete. An agent connects to an MCP server, lists its tools, and passes their schemas to the model through the model's tool calling API. When the model asks for a tool, the agent forwards the call to the server. What is MCP explains the protocol, and MCP tools vs resources vs prompts covers what else a server can offer.


[05]

Common misconceptions about tool calling

"The model runs my function." It doesn't, and that is the most useful fact about tool calling. Because your code runs every call, you can validate the arguments, check permissions, ask a human, or refuse. Human approval for tool calls builds on exactly this.

"Tool call arguments can be trusted." The model fills in arguments from the conversation, which may include text from a user, a web page or another tool. Treat arguments as untrusted input: validate types and ranges, and never pass them straight to a shell or SQL query. Prompt injection defense for AI agents explains why.

"The model picks the right tool every time." It picks based on names and descriptions. Overlapping tools, vague descriptions and long tool lists all cause wrong choices. Too many MCP tools shows what happens past a few dozen tools.

"Tool schemas are free." Every schema is sent as input tokens on every model call. Large tool lists add cost to each round of an agent.


[06]

Frequently asked questions

Is tool calling the same as function calling?

Yes. Function calling is OpenAI's name for the feature, and its docs say it is also known as tool calling. Anthropic calls it tool use. They all describe the same idea: the model returns a structured request to call a function you defined, and your application runs it.

Does the LLM execute the function?

No. The model only produces a tool name and arguments as JSON. Your application, or the framework you use, runs the function and sends the result back to the model in the next request. Some providers also host built-in server tools such as web search, which run on the provider's side.

What is parallel tool calling?

Parallel tool calling means the model asks for several tool calls in one reply, for example the weather in two cities. Your code can run them at the same time and return each result with its call ID. Disable it when calls must happen in order or when you want to approve them one at a time.

What is the difference between tool calling and MCP?

Tool calling is how a model asks for a tool. MCP is how an application finds tools and calls them in a separate server. An agent uses both: MCP to list and run the tools, tool calling to let the model choose them. You can use tool calling without MCP by passing plain functions.

Which models support tool calling?

All major model APIs support it, including OpenAI, Anthropic, Google and Mistral, and many open-weight models served through tools like Ollama or vLLM. Quality varies: smaller models are more likely to pick the wrong tool or produce invalid arguments, so test with the model you plan to use.


[07]

Next steps

  • See tool calling inside an agent loop: How to build an AI agent in Python.

  • Design tools the model uses well: How LLM tool calling works.

  • Put tools in a server: What is MCP?

  • All guides on the topic: the tools and MCP hub.

  • Reference: Building agents in the Promptise docs.

← PreviousWhat Is MCP (Model Context Protocol)? A Developer's GuideNext lesson →MCP Tools vs Resources vs Prompts (With Python Examples)