PromptisePromptise
Docs
GitHub
Promptise - AI Framework LogoPromptise

The foundation layer for agentic intelligence. Build, secure and operate autonomous AI systems with Promptise Foundry.

pip install promptise

[01] Foundry

  • MCPcast
  • The Promptise Agent
  • Reasoning Engine
  • MCP
  • Agent Runtime
  • Prompt Engineering
  • Execution Engine
  • Agent Identity

[02] Resources

  • Documentation
  • GitHub
  • Guides
  • Learning Paths
  • Questions

[03] Company

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

© 2026 Promptise by Manser Ventures. All rights reserved.

Open source · Python

← Learning paths> Agentic Engineering with Promptise Foundry
Lesson 15 / 71
21%

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 71 lessons↓
  1. ✓What Is an AI Agent? Definition, How It Works, Examples
  2. ✓How to Build an AI Agent in Python (2026 Guide)
  3. ✓What Is an Agent Harness? Parts and How to Build One
  4. ✓System Prompt Best Practices for AI Agents in Python
  5. ✓Best LLM for AI Agents: Test and Switch Models in Python
  6. ✓AI Agent YAML: Define and Run an Agent From a Config File
  7. ✓Streaming LLM Responses with FastAPI: Tokens and Tool Calls
  8. ✓Claude AI Agent with MCP: Use Anthropic Models in Promptise
  9. ✓Gemini AI Agent with MCP: Use Google Models in Promptise
  10. ✓Azure OpenAI Agent with MCP: Use Deployments in Promptise
  11. ✓OpenRouter AI Agent with MCP: Many Models in Promptise
  12. ✓Ollama AI Agent with MCP: Run Local Models in Promptise
  13. ✓LLM Semantic Cache and Model Fallback in Python
  14. ✓What Is MCP (Model Context Protocol)? A Developer's Guide
  15. 15What Is Tool Calling? LLM Function Calling Explained
  16. 16MCP Tools vs Resources vs Prompts (With Python Examples)
  17. 17How to Connect MCP Servers to Your AI Agent in Python
  18. 18Build a Production MCP Server in Python (Step by Step)
  19. 19MCP Transports: stdio vs Streamable HTTP vs SSE (Python)
  20. 20FastAPI MCP Server: Turn Your FastAPI App into MCP Tools
  21. 21OpenAPI to MCP: Turn Any REST API into an MCP Server
  22. 22MCP Authentication in Python: API Keys, JWT and OAuth
  23. 23Build an Authenticated MCP Server for Your AI Agent (Python)
  24. 24MCP Security Best Practices: A Checklist for MCP Servers
  25. 25Testing MCP Servers in Python: pytest Without a Live Server
  26. 26Too Many MCP Tools? LLM Tool Selection, Measured
  27. 27MCP Server Caching, Timeouts and Circuit Breakers in Python
  28. 28MCP vs CLI for AI Agents: Tokens, Security, When to Use Each
  29. 29AI Agent Audit Logging: Tamper-Evident Logs in Python
  30. 30AI Agent Human in the Loop: Approve Tool Calls in Python
  31. 31AI Agent Prompt Injection: How to Defend Against It
  32. 32Build a Multi-Agent System in Python (and When Not To)
  33. 33Context Engineering for AI Agents: Context Window Management
  34. 34How to Deploy an AI Agent with Docker (2026 Guide)
  35. 35LLM Tool Rate Limiting: Per-Client Limits for MCP Servers
  36. 36MCP Long-Running Tasks: Background Jobs in Python
  37. 37MCP Server Monitoring: Prometheus, OpenTelemetry and Logs
  38. 38Python AI Agent Frameworks Compared: Which to Choose (2026)
  39. 39Self-Improving AI Agent: Learn From Tool Failures in Python
  40. 40AI Agent Identity: Authenticate Agents to MCP Servers
  41. 41Code-Action Agents in Python: One Program vs 37 Tool Calls
  42. 42Multi-Tenant AI Agents: Keep Each Customer's Data Apart
  43. 43What Is Agentic RAG? How It Differs from Classic RAG
  44. 44AI Agent Memory in Python: Short-Term and Long-Term
  45. 45Agentic RAG in Python: Give Your AI Agent a Search Tool
  46. 46AI Agent Reasoning Patterns in Python: 9 Patterns Tested
  47. 47Plan-and-Execute Agents in Python: Beyond the ReAct Loop
  48. 48Self-Modifying AI Agent in Python: Open Mode & Limits
  49. 49CrewAI Alternatives: 7 Options and How to Migrate (2026)
  50. 50Migrate from AutoGen: Agent Framework, Promptise and More
  51. 51What Is an LLM Guardrail? Types, Examples and Limits
  52. 52AI Agent Guardrails in Python: Block Injection, Redact PII
  53. 53AI Agent Code Execution Sandbox: Run LLM Code Safely
  54. 54AI Agent Production Checklist: What to Check Before Launch
  55. 55Approval Fatigue: Auto-Approve Safe AI Agent Actions
  56. 56What Is Human in the Loop AI? Approvals for AI Agents
  57. 57AI Agent Notifications: Webhook and Slack Alerts in Python
  58. 58AI Agent Observability: Trace Tool Calls, Tokens and Cost
  59. 59AI Agent Stuck in a Loop? How to Detect and Stop It
  60. 60How to Run, Debug and Deploy an AI Agent in Python
  61. 61AI Agent Cost Tracking: Tokens and Cost per Run and User
  62. 62How to Evaluate AI Agents: Evals, LLM Judges and pass^k
  63. 63AI Agent Cost Control: Budgets That Stop Runaway Spend
  64. 64How to Test LLM Prompts and AI Agents in Python
  65. 65AI Agent Evals in CI: Run Them on Every Pull Request
  66. 66Autonomous AI Agent Runtime: Budgets, Crash Recovery, API
  67. 67Event-Driven AI Agents: Webhook, Cron and File Triggers
  68. 68Durable AI Agents: Crash Recovery and Safe Resume
  69. 69Deploy AI Agents in Production: Long-Running Python Agents
  70. 70What Is an AI Agent Framework? When You Need One
  71. 71LangGraph Alternatives: 7 Options and How to Migrate (2026)

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. ✓What Is an Agent Harness? Parts and How to Build One
  4. ✓System Prompt Best Practices for AI Agents in Python
  5. ✓Best LLM for AI Agents: Test and Switch Models in Python
  6. ✓AI Agent YAML: Define and Run an Agent From a Config File
  7. ✓Streaming LLM Responses with FastAPI: Tokens and Tool Calls
  8. ✓Claude AI Agent with MCP: Use Anthropic Models in Promptise
  9. ✓Gemini AI Agent with MCP: Use Google Models in Promptise
  10. ✓Azure OpenAI Agent with MCP: Use Deployments in Promptise
  11. ✓OpenRouter AI Agent with MCP: Many Models in Promptise
  12. ✓Ollama AI Agent with MCP: Run Local Models in Promptise
  13. ✓LLM Semantic Cache and Model Fallback in Python
  14. ✓What Is MCP (Model Context Protocol)? A Developer's Guide
  15. 15What Is Tool Calling? LLM Function Calling Explained
  16. 16MCP Tools vs Resources vs Prompts (With Python Examples)
  17. 17How to Connect MCP Servers to Your AI Agent in Python
  18. 18Build a Production MCP Server in Python (Step by Step)
  19. 19MCP Transports: stdio vs Streamable HTTP vs SSE (Python)
  20. 20FastAPI MCP Server: Turn Your FastAPI App into MCP Tools
  21. 21OpenAPI to MCP: Turn Any REST API into an MCP Server
  22. 22MCP Authentication in Python: API Keys, JWT and OAuth
  23. 23Build an Authenticated MCP Server for Your AI Agent (Python)
  24. 24MCP Security Best Practices: A Checklist for MCP Servers
  25. 25Testing MCP Servers in Python: pytest Without a Live Server
  26. 26Too Many MCP Tools? LLM Tool Selection, Measured
  27. 27MCP Server Caching, Timeouts and Circuit Breakers in Python
  28. 28MCP vs CLI for AI Agents: Tokens, Security, When to Use Each
  29. 29AI Agent Audit Logging: Tamper-Evident Logs in Python
  30. 30AI Agent Human in the Loop: Approve Tool Calls in Python
  31. 31AI Agent Prompt Injection: How to Defend Against It
  32. 32Build a Multi-Agent System in Python (and When Not To)
  33. 33Context Engineering for AI Agents: Context Window Management
  34. 34How to Deploy an AI Agent with Docker (2026 Guide)
  35. 35LLM Tool Rate Limiting: Per-Client Limits for MCP Servers
  36. 36MCP Long-Running Tasks: Background Jobs in Python
  37. 37MCP Server Monitoring: Prometheus, OpenTelemetry and Logs
  38. 38Python AI Agent Frameworks Compared: Which to Choose (2026)
  39. 39Self-Improving AI Agent: Learn From Tool Failures in Python
  40. 40AI Agent Identity: Authenticate Agents to MCP Servers
  41. 41Code-Action Agents in Python: One Program vs 37 Tool Calls
  42. 42Multi-Tenant AI Agents: Keep Each Customer's Data Apart
  43. 43What Is Agentic RAG? How It Differs from Classic RAG
  44. 44AI Agent Memory in Python: Short-Term and Long-Term
  45. 45Agentic RAG in Python: Give Your AI Agent a Search Tool
  46. 46AI Agent Reasoning Patterns in Python: 9 Patterns Tested
  47. 47Plan-and-Execute Agents in Python: Beyond the ReAct Loop
  48. 48Self-Modifying AI Agent in Python: Open Mode & Limits
  49. 49CrewAI Alternatives: 7 Options and How to Migrate (2026)
  50. 50Migrate from AutoGen: Agent Framework, Promptise and More
  51. 51What Is an LLM Guardrail? Types, Examples and Limits
  52. 52AI Agent Guardrails in Python: Block Injection, Redact PII
  53. 53AI Agent Code Execution Sandbox: Run LLM Code Safely
  54. 54AI Agent Production Checklist: What to Check Before Launch
  55. 55Approval Fatigue: Auto-Approve Safe AI Agent Actions
  56. 56What Is Human in the Loop AI? Approvals for AI Agents
  57. 57AI Agent Notifications: Webhook and Slack Alerts in Python
  58. 58AI Agent Observability: Trace Tool Calls, Tokens and Cost
  59. 59AI Agent Stuck in a Loop? How to Detect and Stop It
  60. 60How to Run, Debug and Deploy an AI Agent in Python
  61. 61AI Agent Cost Tracking: Tokens and Cost per Run and User
  62. 62How to Evaluate AI Agents: Evals, LLM Judges and pass^k
  63. 63AI Agent Cost Control: Budgets That Stop Runaway Spend
  64. 64How to Test LLM Prompts and AI Agents in Python
  65. 65AI Agent Evals in CI: Run Them on Every Pull Request
  66. 66Autonomous AI Agent Runtime: Budgets, Crash Recovery, API
  67. 67Event-Driven AI Agents: Webhook, Cron and File Triggers
  68. 68Durable AI Agents: Crash Recovery and Safe Resume
  69. 69Deploy AI Agents in Production: Long-Running Python Agents
  70. 70What Is an AI Agent Framework? When You Need One
  71. 71LangGraph Alternatives: 7 Options and How to Migrate (2026)
← Path overview

Tool calling is the feature that turns a language model from a text generator into something that can look up an order, query a database or send an email. OpenAI calls it function calling, Anthropic calls it tool use, and most frameworks say tool calling. This glossary page defines tool calling, 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.

Text
1
2
3
4
5
6
7
8
9
10
11
12
 your app                                   model API
    │  1. messages + tool schemas               │
    │ ────────────────────────────────────────▶ │
    │  2. tool call: get_weather {"city":"Paris"}│
    │ ◀──────────────────────────────────────── │
    │                                           │
    │  3. your code runs get_weather("Paris")   │
    │                                           │
    │  4. messages + tool result (same call id) │
    │ ────────────────────────────────────────▶ │
    │  5. final answer, or more tool calls      │
    │ ◀──────────────────────────────────────── │

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 generates the schema from the function's signature and docstring and 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
42
import asyncio
import json

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

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_5jlX5k4...  get_weather {'city': 'Paris'}
tool call  id=call_dOEVOYD...  get_weather {'city': 'Tokyo'}
result     id=call_5jlX5k4...  14°C, light rain
result     id=call_dOEVOYD...  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)