Requirements
Before starting, ensure you have the following packages installed:Setup
Start by setting up LangWatch to monitor your RAG application:Metrics
To start evaluating, you need to do 3 things:- Define the tools that your model can call
- Define an evaluation dataset of queries and corresponding expected tool calls
- Define a function to calculate precision and recall.
- Precision: The ratio of correct tool calls to total tool calls
- Recall: The ratio of correct tool calls to total possible tool calls
Defining Tools
Let’s start by defining our tools. When starting out, you can define a small set of 3-4 tools to evaluate. Once the evaluation framework is set in place, you can scale the number of tools to evaluate. For this application, I’ll be looking at 3 tools: get calendar events, create reminder, and send email about the event.Define an Eval Set
Now that we have our tools defined, we can define an eval set. I’ll test the model for its ability to call a single and a combination of two tools.Run the Tests
Our evaluation reveals interesting patterns in the model’s tool selection behavior: The model demonstrates good precision in tool selection - when it chooses to invoke a tool, it’s typically the right one for the task. This suggests the model has a strong understanding of each tool’s use cases. However, we observe lower recall scores in scenarios requiring multiple tool coordination. The model sometimes fails to recognize when a complex query necessitates multiple tools working together.
Consider the query: “Look at my team meeting schedule and send the agenda to all participants.” This requires:
- Retrieving calendar information (
get_calendar_events) - Composing and sending an email (
send_email)
The model shows a clear preference hierarchy, with calendar queries being handled most reliably, followed by reminders, and then emails. This suggests that:
- The
send_emailtool may need improved descriptions or examples to better match user query patterns - Multi-tool coordination needs enhancement, particularly for action-oriented tools
Conclusion
In this cookbook, we’ve demonstrated how to evaluate tool calling capabilities using objective metrics like precision and recall. By systematically analyzing tool selection performance, we’ve gained valuable insights into where our model excels and where it needs improvement. Our evaluation revealed that the model achieves high precision (consistently selecting appropriate tools when it does make a selection) but struggles with recall for certain tools, particularly when multiple tools need to be coordinated. Thesend_email tool showed the lowest recall (0.33), indicating it’s frequently overlooked even when needed.
This data-driven approach to tool evaluation offers several advantages over traditional methods:
- It provides objective metrics that can be tracked over time
- It identifies specific tools that need improvement rather than general system issues
- It highlights patterns in the model’s decision-making process that might not be obvious from manual testing