Repository navigation
Description
Defect Summary
In src/ragas/metrics/_tool_call_accuracy.py (lines 146–178), ToolCallAccuracy is designed to handle length mismatches between predicted tool calls and reference tool calls by comparing the overlapping portion (compared_count = min(len(pred_tool_calls), len(reference_tool_calls))) and applying a proportional coverage penalty:
# From docstring:
# - Length mismatch: compares only the overlapping portion and applies coverage penaltyHowever, line 157 evaluates sequence alignment using the full un-sliced sequences:
tool_call_pred_sequence = [tool_call.name for tool_call in pred_tool_calls]
tool_call_ref_sequence = [tool_call.name for tool_call in reference_tool_calls]
sequence_aligned = int(
self.is_sequence_aligned(tool_call_pred_sequence, tool_call_ref_sequence)
)Because is_sequence_aligned checks:
if self.strict_order:
return pred_sequence == ref_sequence
else:
return sorted(pred_sequence) == sorted(ref_sequence)Whenever len(pred_tool_calls) != len(reference_tool_calls), comparing the lists of unequal lengths will always return False (0), regardless of whether strict_order is True or False.
Then at line 178:
return score * sequence_alignedThe entire computed argument score and coverage penalty are multiplied by 0, resulting in a return value of 0.0. This causes any agent that makes an extra tool call (or misses a tool call) to falsely receive a flat 0.0 accuracy score.
Minimal Reproducible Example
import asyncio
from ragas.messages import AIMessage, ToolCall
from ragas.dataset_schema import MultiTurnSample
from ragas.metrics import ToolCallAccuracy
async def test_length_mismatch():
metric = ToolCallAccuracy()
# Ground truth: expects 1 tool call
ref = [ToolCall(name="get_weather", args={"city": "Mumbai"})]
# Prediction: Agent executed the tool perfectly, plus a subsequent formatting call
pred = [
ToolCall(name="get_weather", args={"city": "Mumbai"}),
ToolCall(name="format_reply", args={"tone": "casual"})
]
sample = MultiTurnSample(
user_input=[AIMessage(content="", tool_calls=pred)],
reference_tool_calls=ref
)
score = await metric._multi_turn_ascore(sample, callbacks=None)
# Expected: 1.0 (or coverage penalty score > 0)
# Actual: 0.0 (wiped out because is_sequence_aligned evaluated on lists of length 2 vs 1)
print("Computed Score:", score)
asyncio.run(test_length_mismatch())Proposed Fix
Evaluate sequence alignment over the overlapping slice ([:compared_count]):
compared_count = min(len(pred_tool_calls), len(reference_tool_calls))
# Check sequence alignment on the overlapping compared portion
tool_call_pred_sequence = [tool_call.name for tool_call in pred_tool_calls[:compared_count]]
tool_call_ref_sequence = [tool_call.name for tool_call in reference_tool_calls[:compared_count]]
sequence_aligned = int(
self.is_sequence_aligned(tool_call_pred_sequence, tool_call_ref_sequence)
)
score = 0.0
for ref_tool_call, pred_tool_call in zip(reference_tool_calls[:compared_count], pred_tool_calls[:compared_count]):
if ref_tool_call.name == pred_tool_call.name:
arg_score = await self._get_arg_score(
pred_tool_call.args, ref_tool_call.args, callbacks
)
score += arg_score
if compared_count > 0:
avg_arg_accuracy = score / compared_count
coverage_factor = compared_count / len(reference_tool_calls)
return avg_arg_accuracy * coverage_factor * sequence_aligned
return 0.0
Activity
Atharva3131 commentedon Nov 6, 2026
Hi @k39139215-gif,
I'd like to contribute to this issue.
I've gone through the reported implementation and understand the problem with evaluating sequence alignment against the full predicted and reference tool-call sequences when their lengths differ.
I'd like to investigate the scoring logic, add regression tests covering both extra and missing tool calls, and verify that strict-order and unordered evaluation continue to behave correctly.
Would the maintainers be open to me working on this and submitting a PR?
Thanks!