Tool calling explained: function calling, internals, MCP, RAG, LangChain, Ollama, Llama

Tool calling vs function calling, how it works inside models, vs MCP and RAG, LangChain, Ollama models, Llama 3.1, benchmarks and a JavaScript loop.

Walking a room through the products he has shipped
Walking a room through the products he has shipped

Key takeaways

  • Tool calling and function calling mean the same thing: models request actions your code runs.
  • Models emit structured calls from schemas in context, and your application executes them.
  • MCP standardises how tools are served, while tool calling is the model mechanism underneath.
  • Ollama supports tools for models tagged with tools, including Llama 3.1, Qwen3 and gpt-oss.
  • BFCL and tau-bench measure tool calling, but your own evaluation set matters most.

Tool calling lets a language model request actions, such as searching, querying a database or calling an API, by returning structured arguments that your code executes. It is the foundation of agents. I build AI systems with retrieval, validation and fallbacks, such as RAG.NextUpgrad and DocuLens AI, so this page covers tool versus function calling, how it works inside models, MCP and RAG comparisons, LangChain, Ollama, Llama 3.1, benchmarks and a minimal JavaScript loop.

Is tool calling the same as function calling?

Yes, essentially. Function calling was OpenAI's original name for letting models return structured requests to call developer-defined functions. Tool calling or tool use is the broader term now used by most providers, including Anthropic.

Also asked as: is tool calling and function calling the same

Tools can include your own functions plus built-in capabilities offered by providers, such as web search, code execution or computer use, which run on the provider's side. In both cases, the model does not execute anything itself; it outputs a tool name and arguments, and an application runs the tool and returns the result. Documentation and frameworks use the terms interchangeably, so treat them as synonyms. Learning one provider's format makes others easy to pick up.

How does tool calling work under the hood?

The API inserts your tool definitions, names, descriptions and JSON schemas, into the model's context using special formatting. Models are trained to emit a structured tool call when useful, which the API parses and returns to your application.

Your code executes the tool, sends the result back as a tool result message, and the model continues, either calling more tools or answering. Some providers use constrained decoding to guarantee arguments match the schema. Parallel tool calls let models request several tools in one turn. Training on many examples of tool use teaches models when to call tools and how to fill parameters. Tool descriptions act as prompts, so clear names, purposes and parameter explanations directly improve reliability.

What is the difference between tool calling and MCP?

Tool calling is the model's ability to request a tool with structured arguments. MCP, the Model Context Protocol, is a standard way for applications to discover and run tools hosted on servers, which are then presented to the model through tool calling.

Without MCP, developers define each tool in their application code. With MCP, a server exposes tools, resources and prompts that any compatible client, such as Claude Desktop or coding agents, can connect to and use. The client converts MCP tools into tool definitions for the model, executes calls through the server, and returns results. MCP standardises integration; tool calling remains the underlying model mechanism. Secure MCP servers with authentication and least-privilege access.

What is the difference between tool calling and RAG?

RAG retrieves relevant information before generation and adds it to the prompt, following fixed steps. Tool calling lets the model decide during generation to request actions, including retrieval, calculations or external API calls.

Classic RAG always retrieves, whether needed or not, and suits question answering over documents, as in RAG.NextUpgrad with hybrid retrieval and citations. Tool calling enables dynamic behaviour: the model might search only when needed, refine queries, or call other tools, such as a calendar or database. Agentic RAG combines them by exposing retrieval as a tool. Fixed RAG is more predictable; tool-driven retrieval is more flexible but harder to evaluate.

How does LangChain tool calling work?

In LangChain, you define tools as Python functions with the tool decorator or Pydantic schemas, attach them to a chat model with bind_tools, and the model returns messages containing tool_calls with names and arguments.

You then execute the calls, either manually or with prebuilt components such as ToolNode in LangGraph or LangChain's agent helpers, and pass results back as tool messages. LangChain standardises tool calling across providers, so the same tools work with Claude, OpenAI, Gemini and Ollama models. Write clear docstrings, since they become tool descriptions. For production, add validation, error handling and limits on how many tool calls an agent may make.

How do you enable tool calling in Ollama?

Use a model that supports tools, then pass a tools array with JSON schemas in requests to Ollama's chat API or its OpenAI-compatible endpoint. The model returns tool calls, which your code executes before sending results back.

Also asked as: how to enable tool calling in ollama

Ollama's Python and JavaScript libraries accept Python functions or schemas as tools and return structured tool calls. Streaming responses can include tool calls in recent versions. Reliability depends on the model, its size and the chat template; small models may skip tools or produce invalid arguments. Increase context length for agent workflows, validate arguments, and test with realistic prompts. Frameworks such as LangChain and LlamaIndex wrap Ollama tool calling for agents.

Which Ollama models support tool calling?

Ollama marks tool-capable models with a tools tag in its library. Common choices include Llama 3.1, 3.2 and 3.3, Qwen2.5 and Qwen3, Mistral and Mistral Nemo, gpt-oss, Devstral, Granite and Command R models.

Filter the Ollama library by the tools category to see the current list, since new models are added frequently. Larger models handle multi-step tool use more reliably, while small ones suit single, well-defined tools. Models trained specifically for agents, such as Qwen3 and gpt-oss, tend to follow tool formats more consistently. Test your exact tools and prompts, because performance varies widely between tasks even among models that support tools.

Does Llama 3.1 support tool calling?

Yes. Llama 3.1 was trained for tool use, supporting custom tools defined with JSON schemas and built-in tool formats for search, a code interpreter and Wolfram Alpha. It works through Ollama, vLLM, Groq and other providers.

The 70B and 405B models handle tools more reliably than the 8B model, which works for simple single calls but can struggle with complex sequences. Use the correct chat template, which serving engines usually apply automatically. Newer models, such as Llama 3.3, Qwen3 and gpt-oss, often perform better on tool benchmarks, so compare options. Validate arguments and handle cases where the model answers directly instead of calling a needed tool.

Which LLM benchmark measures tool calling?

The Berkeley Function Calling Leaderboard is the best-known benchmark for tool calling, testing simple, multiple, parallel and multi-turn calls. Tau-bench measures agents completing realistic customer service tasks with tools and policies.

Also asked as: which llm benchmark mesures tool calling

Other benchmarks include ToolBench, API-Bank and newer evaluations focused on MCP servers and agentic workflows. Benchmarks measure different skills: correct arguments, choosing between tools, knowing when not to call any, and completing multi-step tasks reliably over repeated attempts. Repeated runs reveal reliability, which single scores hide. Leaderboard ranks may not match your tools, so build a small evaluation set from your real use cases, measuring success rate, argument accuracy and how often the model needs retries.

How does AI tool calling work in plain JavaScript?

In about forty lines: define a tools array with names, descriptions and JSON schemas; call a model API with fetch; if the response contains a tool call, run the matching JavaScript function; append the result; and call the API again until the model answers.

Also asked as: how ai tool calling works (40 lines of vanilla javascript

Keep a map from tool names to functions, parse arguments with JSON.parse inside a try block, and return errors to the model as tool results so it can recover. Add a maximum loop count to prevent endless cycles. Never expose API keys in browser code; run this loop on a server, such as Node.js, or behind your own API. Log every call and result to debug unexpected behaviour. Writing it by hand clarifies what agent frameworks automate.

Sources

  1. Anthropic, Tool use overviewdocs.anthropic.com
  2. OpenAI, Function callingplatform.openai.com
  3. Ollama, Tool supportollama.com
  4. Berkeley Function Calling Leaderboardgorilla.cs.berkeley.edu
  5. Yao et al., tau-bencharxiv.org
  6. LangChain, Tool calling conceptspython.langchain.com
Pranjul Rathour
Pranjul Rathour
GenAI Engineer · India

GenAI engineer and AI product builder with 2+ years shipping production-grade AI systems: RAG pipelines, fine-tuned LLMs, hybrid retrieval and multi-modal apps across vision, speech and OCR, architected end to end from ingestion to deployment. Leads engineering for SCULT INDIA's 14-member team, founded the 500+ member TechVerse Enclave community and has mentored 200+ students. Three hackathon first prizes: Changethon 2025 (IIT Roorkee), Product Genesis at Vividhotsava 2025 (CSJMU) and BYTEBATTLE (MeetKats).

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way. Email pranjulrathour41@gmail.com.

Keep reading

More on Shipping AI apps

All Shipping AI apps guides →
Campus talks · hackathon judging · mentoring

Want this as a live session at your college?

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way.

Pranjul Rathour, GenAI engineer in India