Conversation Tool Correctness
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 toNoneto run the metric in score-only mode. Defaulted to0.5. - [Optional]
evaluation_params: a list ofToolCallParamsto compare besides the tool name,ToolCallParams.INPUT_PARAMETERSand/orToolCallParams.OUTPUT. Defaulted to an empty list. - [Optional]
should_consider_ordering: a boolean which when set toTrue, requires the expected tools to be called in order. Defaulted toFalse. - [Optional]
should_exact_match: a boolean which when set toTrue, requires the tools called to exactly match the expected tools. Defaulted toFalse. - [Optional]
include_reason: a boolean which when set toTrue, will include a reason for its evaluation score. Defaulted toTrue. - [Optional]
strict_mode: a boolean which when set toTrue, enforces a binary metric score: 1 for perfection, 0 otherwise. It also overrides the current threshold and sets it to 1. Defaulted toFalse. -
[Optional]
async_mode: a boolean which when set toTrue, enables concurrent execution within themeasure()method. Defaulted toTrue. - [Optional]
verbose_mode: a boolean which when set toTrue, prints the intermediate steps used to calculate said metric to the console, as outlined in the How Is It Calculated section. Defaulted toFalse. - [Optional]
flaky: a boolean which when set toTrue, marks the metric as flaky. Defaulted toFalse.
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:
-
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.
-
Score each check with the tool correctness equation:
- Average the check scores:
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.