0
0
Prompt Engineering / GenAIml~6 mins

Tool usage (function calling) in Prompt Engineering / GenAI - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine you want to get help from a smart assistant that can do many tasks for you. To get the right help, you need to tell it exactly what you want by calling the right tool or function. This concept explains how to use these tools by calling functions correctly.
Explanation
What is a function call
A function call is like asking a tool to do a specific job for you. You give it a name and some information it needs to work. The tool then uses this information to give you a result or perform an action.
A function call is a clear request to a tool to perform a task using given information.
Why use function calls in tools
Using function calls helps organize tasks so the assistant knows exactly what to do. It avoids confusion by separating different jobs into clear commands. This makes the assistant more reliable and efficient.
Function calls help the assistant understand and perform tasks clearly and efficiently.
How to structure a function call
A function call usually has a name and some inputs called arguments. The name tells which tool to use, and the arguments provide details needed to complete the task. The structure must be correct for the tool to understand and respond properly.
Correct structure with name and arguments is essential for successful function calls.
What happens after a function call
Once the function is called, the tool processes the request and returns a result. This result can be information, an action confirmation, or data. The assistant then uses this result to continue the conversation or complete your request.
Function calls lead to results that help complete tasks or provide information.
Real World Analogy

Imagine you are at a restaurant and want to order food. You tell the waiter exactly what dish you want and any special instructions. The waiter then takes your order to the kitchen and brings back your meal. Calling a function is like placing your order with clear details.

What is a function call → Telling the waiter the name of the dish you want
Why use function calls in tools → Using a waiter to clearly communicate your order instead of shouting in the kitchen
How to structure a function call → Giving the waiter the dish name plus any special instructions like 'no onions'
What happens after a function call → The kitchen prepares the meal and the waiter brings it back to you
Diagram
Diagram
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ User Request  │──────▶│ Function Call │──────▶│ Tool Processes│
└───────────────┘       └───────────────┘       └───────────────┘
                                   │                      │
                                   ▼                      ▼
                           ┌───────────────┐       ┌───────────────┐
                           │ Arguments     │       │ Result Returned│
                           └───────────────┘       └───────────────┘
This diagram shows the flow from a user request to a function call, tool processing, and returning a result.
Key Facts
Function callA request to a tool to perform a specific task using given inputs.
ArgumentsThe information or data provided to a function to help it complete its task.
Function nameThe identifier that tells which tool or action to use.
ResultThe output or response returned by the tool after processing a function call.
Common Confusions
Thinking a function call works without correct arguments
Thinking a function call works without correct arguments A function call must include the right arguments; otherwise, the tool cannot perform the task correctly.
Believing the function name can be anything
Believing the function name can be anything The function name must match exactly the tool's expected name to trigger the correct action.
Summary
Function calls are clear requests to tools to perform tasks using specific information.
Correct structure with function name and arguments ensures the tool understands and responds properly.
The tool processes the call and returns a result that helps complete your request.