Large language models (LLMs) have surged in popularity, with the tool-calling feature dramatically expanding their capabilities beyond simple text generation. Now, LLMs can handle complex automation tasks such as dynamic UI creation and autonomous actions. Trained on massive datasets, these models excel at understanding and producing structured data, making them ideal for precise tool-calling applications. This has fueled their widespread adoption in AI-driven software development, where tool-calling – from basic functions to sophisticated agents – is now central. This article explores the fundamentals of LLM tool calling and demonstrates how to implement it using open-source tools to build powerful agents.
Key Learning Objectives
- Grasp the concept of LLM tools.
- Understand the fundamentals of tool calling and its applications.
- Explore tool-calling implementations in OpenAI (ChatCompletions API, Assistants API, parallel tool calling, and structured output), Anthropic models, and LangChain.
- Learn to construct effective AI agents using open-source resources.
*This article is part of the***Data Science Blogathon.
Table of Contents
- What are Tools?
- What is Tool Calling?
- How Does Tool Calling Work?
- Example Use Cases
- Tool Calling with OpenAI Models
- Utilizing the Assistant API
- Parallel Function Calling
- Structured Output
- Tool Calling with Anthropic Claude
- Tool Calling with LangChain
- Schema Definition with Pydantic
- Building Agents with Tool Calling
- Introducing Composio
- Building a GitHub Agent
- Frequently Asked Questions
What are Tools?
Tools are mechanisms allowing LLMs to interact with external systems. These tools are functions accessible to the LLM, executed independently when the LLM deems their use necessary. A typical tool definition includes:
- Name: A descriptive function/tool name.
- Description: A detailed tool explanation.
- Parameters: A JSON schema defining the function/tool parameters.
What is Tool Calling?
Tool calling enables the model to generate responses matching a user-defined function schema. When the LLM decides a tool is needed, it produces a structured output conforming to the tool's argument schema. For example, given a get_weather
function schema, a query about a city's weather would return a formatted schema of function arguments, enabling execution to retrieve the weather data. Importantly, the LLM doesn't execute the tool; it generates the structured input for external execution.
How Does Tool Calling Work?
Companies like OpenAI and Anthropic have trained models to select appropriate tools based on context. Each provider handles tool invocation and responses differently. Generally:
- Define Tools and Provide a Prompt: Define tools with names, descriptions, and structured schemas, along with the user's prompt (e.g., "What's the weather in London?").
- LLM Tool Selection: The LLM assesses tool necessity. If so, it halts text generation and generates a JSON-formatted response with tool parameter values.
- Extract, Execute, and Return: Extract parameters, run the function, and return outputs to the LLM.
- Answer Generation: The LLM uses tool outputs to formulate the final answer.
Example Use Cases
- Action Enablement: Connect LLMs to applications (Gmail, GitHub, Discord) to automate actions (sending emails, creating pull requests, sending messages).
- Data Provision: Fetch data from knowledge bases (web, Wikipedia, APIs) to provide specific information to LLMs.
- Dynamic UIs: Update application UIs based on user input.
The following sections detail tool-calling approaches in OpenAI, Anthropic, and LangChain. Open-source models (like Llama 3) and inference providers (like Groq) also support tool calling.
(The remainder of the article would continue with detailed explanations of tool calling in OpenAI, Anthropic, LangChain, building agents, Composio, and a GitHub agent example, mirroring the structure and content of the original input but with rephrased sentences and vocabulary.)
The above is the detailed content of Tool Calling in LLMs. For more information, please follow other related articles on the PHP Chinese website!

The legal tech revolution is gaining momentum, pushing legal professionals to actively embrace AI solutions. Passive resistance is no longer a viable option for those aiming to stay competitive. Why is Technology Adoption Crucial? Legal professional

Many assume interactions with AI are anonymous, a stark contrast to human communication. However, AI actively profiles users during every chat. Every prompt, every word, is analyzed and categorized. Let's explore this critical aspect of the AI revo

A successful artificial intelligence strategy cannot be separated from strong corporate culture support. As Peter Drucker said, business operations depend on people, and so does the success of artificial intelligence. For organizations that actively embrace artificial intelligence, building a corporate culture that adapts to AI is crucial, and it even determines the success or failure of AI strategies. West Monroe recently released a practical guide to building a thriving AI-friendly corporate culture, and here are some key points: 1. Clarify the success model of AI: First of all, we must have a clear vision of how AI can empower business. An ideal AI operation culture can achieve a natural integration of work processes between humans and AI systems. AI is good at certain tasks, while humans are good at creativity and judgment

Meta upgrades AI assistant application, and the era of wearable AI is coming! The app, designed to compete with ChatGPT, offers standard AI features such as text, voice interaction, image generation and web search, but has now added geolocation capabilities for the first time. This means that Meta AI knows where you are and what you are viewing when answering your question. It uses your interests, location, profile and activity information to provide the latest situational information that was not possible before. The app also supports real-time translation, which completely changed the AI experience on Ray-Ban glasses and greatly improved its usefulness. The imposition of tariffs on foreign films is a naked exercise of power over the media and culture. If implemented, this will accelerate toward AI and virtual production

Artificial intelligence is revolutionizing the field of cybercrime, which forces us to learn new defensive skills. Cyber criminals are increasingly using powerful artificial intelligence technologies such as deep forgery and intelligent cyberattacks to fraud and destruction at an unprecedented scale. It is reported that 87% of global businesses have been targeted for AI cybercrime over the past year. So, how can we avoid becoming victims of this wave of smart crimes? Let’s explore how to identify risks and take protective measures at the individual and organizational level. How cybercriminals use artificial intelligence As technology advances, criminals are constantly looking for new ways to attack individuals, businesses and governments. The widespread use of artificial intelligence may be the latest aspect, but its potential harm is unprecedented. In particular, artificial intelligence

The intricate relationship between artificial intelligence (AI) and human intelligence (NI) is best understood as a feedback loop. Humans create AI, training it on data generated by human activity to enhance or replicate human capabilities. This AI

Anthropic's recent statement, highlighting the lack of understanding surrounding cutting-edge AI models, has sparked a heated debate among experts. Is this opacity a genuine technological crisis, or simply a temporary hurdle on the path to more soph

India is a diverse country with a rich tapestry of languages, making seamless communication across regions a persistent challenge. However, Sarvam’s Bulbul-V2 is helping to bridge this gap with its advanced text-to-speech (TTS) t


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version
