📍 Join the 1st DeepEval meetup in SF, this Friday 5pm PT. RSVP on Luma →
💥 Introducing JevEval: Jev-as-a-Judge for LLM evaluation. Read the post →
Multi-Turn

Conversation Tool Correctness

Multi-turn
Reference-based
Agent

The conversation tool correctness metric is a multi-turn agentic metric that evaluates whether your AI agent called the tools it was expected to call over a conversation. It is the multi-turn version of tool correctness, and is fully deterministic.

Required Arguments

To use the ConversationToolCorrectnessMetric, you'll have to provide the following arguments when creating a ConversationalTestCase:

  • turns
  • expected_tools

expected_tools are the tools the assistant should call anywhere in the conversation. To require a tool on a specific turn, set turn on its ToolCall to that assistant turn's index in turns.

You can learn more about how it is calculated here.

Usage

The ConversationToolCorrectnessMetric() can be used for end-to-end multi-turn evaluation:

from deepeval.test_case import Turn, ConversationalTestCase, ToolCall
from deepeval.metrics import ConversationToolCorrectnessMetric
from deepeval import evaluate

convo_test_case = ConversationalTestCase(
    turns=[
        Turn(role="user", content="Find me a flight to Tokyo."),
        Turn(role="assistant", content="Here are three options.", tools_called=[ToolCall(name="search_flights")]),
        Turn(role="user", content="Book the first one."),
        Turn(role="assistant", content="Done, you're booked."),
    ],
    expected_tools=[
        ToolCall(name="search_flights"),
        ToolCall(name="book_flight", turn=3),
    ],
)
metric = ConversationToolCorrectnessMetric(threshold=0.5)

# To run metric as a standalone
# metric.measure(convo_test_case)
# print(metric.score, metric.reason)

evaluate(test_cases=[convo_test_case], metrics=[metric])

There are NINE optional parameters when creating a ConversationToolCorrectnessMetric:

  • [Optional] threshold: a number representing the minimum passing threshold. Can also be set to None to run the metric in score-only mode. Defaulted to 0.5.
  • [Optional] evaluation_params: a list of ToolCallParams to compare besides the tool name, ToolCallParams.INPUT_PARAMETERS and/or ToolCallParams.OUTPUT. Defaulted to an empty list.
  • [Optional] should_consider_ordering: a boolean which when set to True, requires the expected tools to be called in order. Defaulted to False.
  • [Optional] should_exact_match: a boolean which when set to True, requires the tools called to exactly match the expected tools. Defaulted to False.
  • [Optional] include_reason: a boolean which when set to True, will include a reason for its evaluation score. Defaulted to True.
  • [Optional] strict_mode: a boolean which when set to True, enforces a binary metric score: 1 for perfection, 0 otherwise. It also overrides the current threshold and sets it to 1. Defaulted to False.
  • [Optional] async_mode: a boolean which when set to True, enables concurrent execution within the measure() method. Defaulted to True.

  • [Optional] verbose_mode: a boolean which when set to True, prints the intermediate steps used to calculate said metric to the console, as outlined in the How Is It Calculated section. Defaulted to False.
  • [Optional] flaky: a boolean which when set to True, marks the metric as flaky. Defaulted to False.

As a standalone

You can also run the ConversationToolCorrectnessMetric on a single test case as a standalone, one-off execution.

...

metric.measure(convo_test_case)
print(metric.score, metric.reason)

How Is It Calculated?

The conversation tool correctness metric score is calculated using the following steps:

  1. Group the expected tools into checks: one for each turn that has pinned tools, and one for the unpinned tools. A pinned turn is compared with its own tool calls, and the unpinned tools are compared with the tool calls of every other assistant turn.

  2. Score each check with the tool correctness equation:

Check Score=Number of Correctly Used Tools (or Correct Input Parameters/Outputs)Total Number of Tools Called\text{Check Score} = \frac{\text{Number of Correctly Used Tools (or Correct Input Parameters/Outputs)}}{\text{Total Number of Tools Called}}
  1. Average the check scores:
Conversation Tool Correctness=∑Check ScoresNumber of Checks\text{Conversation Tool Correctness} = \frac{\sum \text{Check Scores}}{\text{Number of Checks}}

In the example above, book_flight is pinned to turn 3 but never called, so that check scores 0, the unpinned search_flights check scores 1, and the final score is 0.5.

On this page