Learning Library

← Back to Library

Tool Calling: Traditional vs Embedded Approaches

Key Points

  • Tool calling lets an LLM access real‑time data (e.g., APIs, databases) by having the client send messages plus tool definitions, after which the model suggests which tool to invoke.
  • A tool definition includes the tool’s name, description, and required input parameters, and can represent anything from external APIs to code executed by a code interpreter.
  • In a typical flow, the LLM recommends a tool call, the client executes the call (e.g., fetching Miami’s temperature), returns the result to the LLM, and the model produces a final answer.
  • Traditional tool calling can suffer from hallucinations or incorrect tool calls because the LLM directly dictates which tool to use.
  • Embedded tool calling mitigates those issues by inserting a library/framework between the application and the LLM to manage tool definitions and execution, offering tighter control and fewer errors.

Full Transcript

# Tool Calling: Traditional vs Embedded Approaches **Source:** [https://www.youtube.com/watch?v=h8gMhXYAv1k](https://www.youtube.com/watch?v=h8gMhXYAv1k) **Duration:** 00:04:44 ## Summary - Tool calling lets an LLM access real‑time data (e.g., APIs, databases) by having the client send messages plus tool definitions, after which the model suggests which tool to invoke. - A tool definition includes the tool’s name, description, and required input parameters, and can represent anything from external APIs to code executed by a code interpreter. - In a typical flow, the LLM recommends a tool call, the client executes the call (e.g., fetching Miami’s temperature), returns the result to the LLM, and the model produces a final answer. - Traditional tool calling can suffer from hallucinations or incorrect tool calls because the LLM directly dictates which tool to use. - Embedded tool calling mitigates those issues by inserting a library/framework between the application and the LLM to manage tool definitions and execution, offering tighter control and fewer errors. ## Sections - [00:00:00](https://www.youtube.com/watch?v=h8gMhXYAv1k&t=0s) **Tool Calling Workflow Overview** - The passage explains how a client app sends messages and tool definitions to an LLM, which then recommends a tool to invoke, after which the client calls the tool, returns the result to the LLM, and the cycle continues until a final answer is produced. - [00:03:04](https://www.youtube.com/watch?v=h8gMhXYAv1k&t=184s) **Embedded Tool Calling Architecture** - The passage explains how a middleware library defines and executes tools, appends those definitions to LLM prompts, and uses embedded tool calling to reduce hallucinations compared to traditional tool calling. ## Full Transcript
0:00So what is tool calling? 0:01Tool calling is a powerful technique where you make the and context aware of real time data 0:06such as databases or APIs. Typically used to call in via a chat interface. 0:12So you would have your client application in one hand, 0:17And an LLM team on the other side. 0:23For your client application, you would send a set of messages 0:26together with a tool definition to the LLM so you would have your messages here. 0:34Together with your list of tools. 0:37The LLM then look at both your message and the list of tools as going through recommends a tool you should call. 0:46From your client application, you should call this tool and then supply the answer back to the LLM 0:53So it is still response will be interpreted by the LLM. 0:56And this will either tell you the next tool to call or it will give you any final answer. 1:03In your application, you're responsible for creating the tool definition. 1:08So this tool definition includes a couple of things, such as the name of every tool. 1:13It also includes a description for the tool. 1:16So this is where you can give additional information about how to use the tool or when to use it 1:21And it also includes the input parameters needed to make a tool call. 1:25And the tools can be anything. 1:26So the tools could be APIs or databases, 1:31but it could also be code that you interpret via code interpreter. 1:38So let's look at an example. 1:41Assume you want to find the weather in Miami. 1:43You might ask the LLM about the temperature in Miami. 1:49You also provide a list of tools. 1:51And one of these tools is the weather API. 1:56The LLM will look at both your question, which is what is the temperature in Miami? 2:00And we'll also look at the weather API. 2:02And then based on the tool definition for the weather API, it's going to tell you how to call the weather tool. 2:08So in here it's going to create a tool that you can use 2:11right here on this side where you call the API to collect the weather information. 2:16You would then supply the weather information back to the LLM. 2:19So let's say it would be 71 degrees. 2:22The LLM then we'll look at the tool response and then give the final answer, which might be 2:27something in the trends of the weather in Miami is pretty nice. It's 71 degrees. 2:33This has some downsides. 2:34So when you do traditional tool calling, where you have an LLM and a client application, you could see the LLM hallucinate. 2:44Sometimes the LLM can also make up incorrect tool calls. 2:49That's why I also want to look at embedded tool calling. 2:52We just looked at traditional tool calling. 2:54A traditional tool calling has its flaws. 2:56As I mentioned, The LLM could hallucinate or create incorrect tool calls. 3:00That's why I also want to take a embedded tool calling into account. 3:04With a medical calling, you use a library or framework to interact with the LLM and your tool definitions. 3:11The library would be somewhere between your application and the large language model. 3:20In the library, you would do the dual definition, which you would also execute at all goals. 3:26Let's draw a line between these sections here. 3:28So the library will contain your tool definition. 3:33It would also contain the tool execution. 3:38So when you send the message from your application to the large language model, it will go through the library. 3:43So your message could still be what is the temperature in Miami? 3:51The library will then append the tool definition and send your message together with the tools to the LLM 3:56So this will be your message. 4:00Plus your list of tools. 4:02Instead of sending the tool to call to the application or the user, it will be sent to the library, which will then delete all execution. 4:11And this way the library will provide you with the final answer, which could be at 71 degrees in Miami. 4:18When you use embedded tool calling, 4:19the LLM will no longer hallucinate as the library 4:23to help you with it's tool calling or the embedded tool calling is going to take care of the total execution. 4:28And we'll retry the two calls in case it's needed. 4:31So in this video, we looked at both traditional tool calling and also embedded tool calling, 4:35where a specially embedded tool calling will help you to prevent hallucination 4:39or help you with the execution of tools, which could be APIs, databases or code.