Skip to content

tool_called

autogen.beta.eval.scorers.tools.tool_called #

tool_called(name, *, exactly=None)

Pass iff the agent called the tool name.

PARAMETER DESCRIPTION
name

The tool name to look for in ToolCallEvent.name.

TYPE: str

exactly

If set, pass iff the call count equals this value. Default (None) means "at least one call".

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
A

class:Scorer with key "tool_called[<name>]" so multiple

TYPE: Scorer

Scorer

instances coexist in one run without clashing.

Source code in autogen/beta/eval/scorers/tools.py
def tool_called(name: str, *, exactly: int | None = None) -> Scorer:
    """Pass iff the agent called the tool ``name``.

    Args:
        name: The tool name to look for in ``ToolCallEvent.name``.
        exactly: If set, pass iff the call count equals this value.
            Default (``None``) means "at least one call".

    Returns:
        A :class:`Scorer` with key ``"tool_called[<name>]"`` so multiple
        instances coexist in one run without clashing.
    """

    def _check(trace: Trace) -> bool:
        count = len(trace.events_of(ToolCallEvent, name=name))
        if exactly is not None:
            return count == exactly
        return count >= 1

    return Scorer(_check, key=f"tool_called[{name}]")