Notebooks
A
Arize AI
Evaluate Agent Tool Selection Classifications

Evaluate Agent Tool Selection Classifications

agentsllmsLlamaIndexarize-phoenixopenaitutorialsevalsllmopsai-monitoringaiengineeringprompt-engineeringdatasetsllm-evalai-observabilityllm-evaluationsmolagentsanthropiclangchain

Open In Colab

phoenix logo
phoenix logo
Docs | GitHub | Community

Agent Tool Selection Classification Evals

The purpose of this notebook is:

  • to evaluate the performance of an LLM-assisted approach to evaluating agent tool selection,
  • to provide an experimental framework for users to iterate and improve on the default agent tool calling template.

Install Dependencies and Import Libraries

[ ]
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 50.3/50.3 kB 1.8 MB/s eta 0:00:00
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 72.3/72.3 kB 3.2 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.3/64.3 kB 4.3 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 70.9/70.9 kB 4.6 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.5/118.5 kB 7.9 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.8/65.8 kB 4.3 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 196.2/196.2 kB 12.7 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 235.6/235.6 kB 14.3 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.4/76.4 kB 4.7 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 610.4/610.4 kB 25.6 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 48.0 MB/s eta 0:00:00
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
google-genai 1.24.0 requires httpx<1.0.0,>=0.28.1, but you have httpx 0.27.2 which is incompatible.
firebase-admin 6.9.0 requires httpx[http2]==0.28.1, but you have httpx 0.27.2 which is incompatible.
Requirement already satisfied: opentelemetry-sdk in /usr/local/lib/python3.11/dist-packages (1.34.1)
Requirement already satisfied: arize[Datasets] in /usr/local/lib/python3.11/dist-packages (7.47.0)
Requirement already satisfied: googleapis-common-protos<2,>=1.51.0 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (1.70.0)
Requirement already satisfied: pandas<3,>=0.25.3 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (2.2.2)
Requirement already satisfied: protobuf<6,>=4.21.0 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (5.29.5)
Requirement already satisfied: pyarrow>=0.15.0 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (18.1.0)
Requirement already satisfied: pydantic<3,>=2.0.0 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (2.11.7)
Requirement already satisfied: requests-futures==1.0.0 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (1.0.0)
Requirement already satisfied: tqdm<5,>=4.60.0 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (4.67.1)
Collecting deprecated (from arize[Datasets])
  Downloading Deprecated-1.2.18-py2.py3-none-any.whl.metadata (5.7 kB)
Collecting openinference-semantic-conventions<1,>=0.1.6 (from arize[Datasets])
  Downloading openinference_semantic_conventions-0.1.21-py3-none-any.whl.metadata (1.2 kB)
Collecting opentelemetry-exporter-otlp<2,>=1.25.0 (from arize[Datasets])
  Downloading opentelemetry_exporter_otlp-1.34.1-py3-none-any.whl.metadata (2.4 kB)
Requirement already satisfied: opentelemetry-semantic-conventions<1,>=0.43b0 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (0.55b1)
Requirement already satisfied: typing-extensions<5,>=4 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (4.14.1)
Requirement already satisfied: wrapt<2,>=1.12.1 in /usr/local/lib/python3.11/dist-packages (from arize[Datasets]) (1.17.2)
Requirement already satisfied: requests>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from requests-futures==1.0.0->arize[Datasets]) (2.32.3)
Requirement already satisfied: opentelemetry-api==1.34.1 in /usr/local/lib/python3.11/dist-packages (from opentelemetry-sdk) (1.34.1)
Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in /usr/local/lib/python3.11/dist-packages (from opentelemetry-api==1.34.1->opentelemetry-sdk) (8.7.0)
Collecting opentelemetry-exporter-otlp-proto-grpc==1.34.1 (from opentelemetry-exporter-otlp<2,>=1.25.0->arize[Datasets])
  Downloading opentelemetry_exporter_otlp_proto_grpc-1.34.1-py3-none-any.whl.metadata (2.4 kB)
Collecting opentelemetry-exporter-otlp-proto-http==1.34.1 (from opentelemetry-exporter-otlp<2,>=1.25.0->arize[Datasets])
  Downloading opentelemetry_exporter_otlp_proto_http-1.34.1-py3-none-any.whl.metadata (2.3 kB)
Requirement already satisfied: grpcio<2.0.0,>=1.63.2 in /usr/local/lib/python3.11/dist-packages (from opentelemetry-exporter-otlp-proto-grpc==1.34.1->opentelemetry-exporter-otlp<2,>=1.25.0->arize[Datasets]) (1.73.1)
Collecting opentelemetry-exporter-otlp-proto-common==1.34.1 (from opentelemetry-exporter-otlp-proto-grpc==1.34.1->opentelemetry-exporter-otlp<2,>=1.25.0->arize[Datasets])
  Downloading opentelemetry_exporter_otlp_proto_common-1.34.1-py3-none-any.whl.metadata (1.9 kB)
Collecting opentelemetry-proto==1.34.1 (from opentelemetry-exporter-otlp-proto-grpc==1.34.1->opentelemetry-exporter-otlp<2,>=1.25.0->arize[Datasets])
  Downloading opentelemetry_proto-1.34.1-py3-none-any.whl.metadata (2.4 kB)
Requirement already satisfied: numpy>=1.23.2 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=0.25.3->arize[Datasets]) (2.0.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=0.25.3->arize[Datasets]) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=0.25.3->arize[Datasets]) (2025.2)
Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=0.25.3->arize[Datasets]) (2025.2)
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=2.0.0->arize[Datasets]) (0.7.0)
Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=2.0.0->arize[Datasets]) (2.33.2)
Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=2.0.0->arize[Datasets]) (0.4.1)
Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.11/dist-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api==1.34.1->opentelemetry-sdk) (3.23.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas<3,>=0.25.3->arize[Datasets]) (1.17.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=1.2.0->requests-futures==1.0.0->arize[Datasets]) (3.4.2)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=1.2.0->requests-futures==1.0.0->arize[Datasets]) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=1.2.0->requests-futures==1.0.0->arize[Datasets]) (2.4.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests>=1.2.0->requests-futures==1.0.0->arize[Datasets]) (2025.6.15)
Downloading openinference_semantic_conventions-0.1.21-py3-none-any.whl (10 kB)
Downloading opentelemetry_exporter_otlp-1.34.1-py3-none-any.whl (7.0 kB)
Downloading opentelemetry_exporter_otlp_proto_grpc-1.34.1-py3-none-any.whl (18 kB)
Downloading opentelemetry_exporter_otlp_proto_http-1.34.1-py3-none-any.whl (17 kB)
Downloading opentelemetry_exporter_otlp_proto_common-1.34.1-py3-none-any.whl (18 kB)
Downloading opentelemetry_proto-1.34.1-py3-none-any.whl (55 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.7/55.7 kB 2.8 MB/s eta 0:00:00
Downloading Deprecated-1.2.18-py2.py3-none-any.whl (10.0 kB)
Installing collected packages: opentelemetry-proto, openinference-semantic-conventions, deprecated, opentelemetry-exporter-otlp-proto-common, opentelemetry-exporter-otlp-proto-http, opentelemetry-exporter-otlp-proto-grpc, opentelemetry-exporter-otlp
Successfully installed deprecated-1.2.18 openinference-semantic-conventions-0.1.21 opentelemetry-exporter-otlp-1.34.1 opentelemetry-exporter-otlp-proto-common-1.34.1 opentelemetry-exporter-otlp-proto-grpc-1.34.1 opentelemetry-exporter-otlp-proto-http-1.34.1 opentelemetry-proto-1.34.1
Requirement already satisfied: openai in /usr/local/lib/python3.11/dist-packages (1.93.0)
Requirement already satisfied: pandas in /usr/local/lib/python3.11/dist-packages (2.2.2)
Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.11/dist-packages (from openai) (4.9.0)
Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.11/dist-packages (from openai) (1.9.0)
Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.11/dist-packages (from openai) (0.27.2)
Requirement already satisfied: jiter<1,>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from openai) (0.10.0)
Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.11/dist-packages (from openai) (2.11.7)
Requirement already satisfied: sniffio in /usr/local/lib/python3.11/dist-packages (from openai) (1.3.1)
Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.11/dist-packages (from openai) (4.67.1)
Requirement already satisfied: typing-extensions<5,>=4.11 in /usr/local/lib/python3.11/dist-packages (from openai) (4.14.1)
Requirement already satisfied: numpy>=1.23.2 in /usr/local/lib/python3.11/dist-packages (from pandas) (2.0.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas) (2025.2)
Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas) (2025.2)
Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.11/dist-packages (from anyio<5,>=3.5.0->openai) (3.10)
Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (from httpx<1,>=0.23.0->openai) (2025.6.15)
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx<1,>=0.23.0->openai) (1.0.9)
Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.16.0)
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=1.9.0->openai) (0.7.0)
Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=1.9.0->openai) (2.33.2)
Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=1.9.0->openai) (0.4.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)
Collecting anthropic>=0.18.0
  Downloading anthropic-0.57.1-py3-none-any.whl.metadata (27 kB)
Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.11/dist-packages (from anthropic>=0.18.0) (4.9.0)
Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.11/dist-packages (from anthropic>=0.18.0) (1.9.0)
Requirement already satisfied: httpx<1,>=0.25.0 in /usr/local/lib/python3.11/dist-packages (from anthropic>=0.18.0) (0.27.2)
Requirement already satisfied: jiter<1,>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from anthropic>=0.18.0) (0.10.0)
Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.11/dist-packages (from anthropic>=0.18.0) (2.11.7)
Requirement already satisfied: sniffio in /usr/local/lib/python3.11/dist-packages (from anthropic>=0.18.0) (1.3.1)
Requirement already satisfied: typing-extensions<5,>=4.10 in /usr/local/lib/python3.11/dist-packages (from anthropic>=0.18.0) (4.14.1)
Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.11/dist-packages (from anyio<5,>=3.5.0->anthropic>=0.18.0) (3.10)
Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (from httpx<1,>=0.25.0->anthropic>=0.18.0) (2025.6.15)
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx<1,>=0.25.0->anthropic>=0.18.0) (1.0.9)
Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx<1,>=0.25.0->anthropic>=0.18.0) (0.16.0)
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=1.9.0->anthropic>=0.18.0) (0.7.0)
Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=1.9.0->anthropic>=0.18.0) (2.33.2)
Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<3,>=1.9.0->anthropic>=0.18.0) (0.4.1)
Downloading anthropic-0.57.1-py3-none-any.whl (292 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 292.8/292.8 kB 5.6 MB/s eta 0:00:00
Installing collected packages: anthropic
Successfully installed anthropic-0.57.1

ℹ️ To enable async request submission in notebook environments like Jupyter or Google Colab, optionally use nest_asyncio. nest_asyncio globally patches asyncio to enable event loops to be re-entrant. This is not required for non-notebook environments.

Without nest_asyncio, eval submission can be much slower, depending on your organization's rate limits. Speed increases of about 5x are typical.

[3]
[ ]

Download Benchmark Dataset

We'll evaluate the evaluation system consisting of a few example user prompts, with corresponding tool choices and ground truth answers, in addition to an evaluation prompt template against benchmark datasets of user queries and the corresponding tools called with ground-truth labels. We will be using the Berkely Function-Calling Leaderboard dataset. This dataset is commonly used for Agent applications that call tools as a benchmark.

[5]
--2025-07-10 16:15:44--  https://huggingface.co/datasets/gorilla-llm/Berkeley-Function-Calling-Leaderboard/blob/main/BFCL_v3_exec_multiple.json
Resolving huggingface.co (huggingface.co)... 3.166.152.44, 3.166.152.65, 3.166.152.110, ...
Connecting to huggingface.co (huggingface.co)|3.166.152.44|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1201626 (1.1M) [text/html]
Saving to: ‘exec_simple.json’

exec_simple.json    100%[===================>]   1.15M  --.-KB/s    in 0.1s    

2025-07-10 16:15:44 (11.3 MB/s) - ‘exec_simple.json’ saved [1201626/1201626]

[ ]

Modify Benchmark Dataset

The BFCL Dataset does not have any negative examples, i.e. only question, available_tools, and ground_truth are present. In order to accurately benchmark our LLM-as-a-Judge, this code snippet appends some incorrect examples to our dataset, by adding 20 rows of data where the incorrect tool is selected.

[7]

Display Agent Tool Selection Prompt Template

View the default template used to evaluate agent tool calling. You can tweak this template and evaluate its performance relative to the default.

[ ]

You are an evaluation assistant assessing whether a tool call correctly matches a user's question. 
Your task is to decide if the tool selected is the best choice to answer the question,
using only the list of available tools provided below. You are not responsible for checking the 
parameters or arguments passed to the tool. You are evaluating **only** whether the correct tool 
was selected based on the content of the question. Think like a grading rubric. Be strict. If the
selected tool is not clearly correct based on the question alone, label it "incorrect". Do not 
make assumptions or infer information that is not explicitly stated in the question. 
Only use the information provided.

Your response must be a **single word**: either `"correct"` or `"incorrect"`. 
Do not include any explanation, punctuation, or other characters. The output will be parsed
programmatically.

---

Label the tool call as `"correct"` if **all** of the following are true:
- The selected tool is clearly the best fit to answer the user's question
- The tool is among those available in the tool list
- The question contains enough explicit information to justify selecting this tool

Label the tool call as `"incorrect"` if **any** of the following are true:
- A more appropriate tool exists to answer the question
- The tool is not clearly justified by the question content
- The tool would not produce a relevant or meaningful answer to the question

---

[BEGIN DATA]
************
[Question]: {question}
************
[Tool Called]: {tool_call}
[END DATA]

[Tool Definitions]: {tool_definitions}

Eval template variables:

  • question : The question the user poses
  • tool_call : The tool that is actually called (ground truth)
  • tool_definitions : All the available tools to the agent

Configure the LLM

Configure your API keys.

[9]
🔑 Enter your OpenAI API key: ··········
🔑 Enter your Anthropic API key: ··········

Evaluate the Dataset Using Phoenix

[ ]

Evaluate Anthropic Models

[ ]
  0%|          | 0/5 [00:00<?, ?it/s]

🧪 Evaluating Anthropic model: claude-3-opus-20240229
llm_classify |          | 0/50 (0.0%) | ⏳ 00:00<? | ?it/s
 20%|██        | 1/5 [00:22<01:29, 22.33s/it]

🧪 Evaluating Anthropic model: claude-3-sonnet-20240229
llm_classify |          | 0/50 (0.0%) | ⏳ 00:00<? | ?it/s
 40%|████      | 2/5 [00:35<00:51, 17.12s/it]

🧪 Evaluating Anthropic model: claude-3-haiku-20240307
llm_classify |          | 0/50 (0.0%) | ⏳ 00:00<? | ?it/s
 60%|██████    | 3/5 [00:51<00:32, 16.42s/it]

🧪 Evaluating Anthropic model: claude-opus-4-20250514
llm_classify |          | 0/50 (0.0%) | ⏳ 00:00<? | ?it/s
 80%|████████  | 4/5 [01:05<00:15, 15.64s/it]

🧪 Evaluating Anthropic model: claude-sonnet-4-20250514
llm_classify |          | 0/50 (0.0%) | ⏳ 00:00<? | ?it/s
100%|██████████| 5/5 [01:20<00:00, 16.13s/it]

Show Results

Let's see how well different models performed as a Judge! We'll show:

  • Confusion Matrix for one model (GPT 4o)
  • F1 score per model benchmarked, to compare how different models perform as a judge vs the ground truth
  • An agreement matrix to see which models agree with each other as judges.
[12]
/tmp/ipython-input-12-2317285331.py:48: FutureWarning: 

Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `y` variable to `hue` and set `legend=False` for the same effect.

  ax = sns.barplot(
OutputOutputOutput