Skip to content

Fix: Add optional detailed logging to AgentEvaluator #1619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/google/adk/evaluation/agent_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async def evaluate_eval_set(
criteria: dict[str, float],
num_runs=NUM_RUNS,
agent_name=None,
log_detailed_results: bool = False,
):
"""Evaluates an agent using the given EvalSet.

Expand All @@ -109,6 +110,7 @@ async def evaluate_eval_set(
num_runs: Number of times all entries in the eval dataset should be
assessed.
agent_name: The name of the agent.
log_detailed_results: Logs detailed results. All invocation results will be logged if true.
"""
eval_case_responses_list = await EvaluationGenerator.generate_responses(
eval_set=eval_set,
Expand Down Expand Up @@ -139,6 +141,15 @@ async def evaluate_eval_set(
)
)

if log_detailed_results:
logger.info(f"Detailed results for {metric_name} for {agent_module}:")
for per_invocation_result in evaluation_result.per_invocation_results:
logger.info(f"Actual invocation: '{per_invocation_result.actual_invocation}'")
logger.info(f"Expected invocation: '{per_invocation_result.expected_invocation}'")
logger.info(f"Score: {per_invocation_result.score}")
logger.info(f"Eval Status: {per_invocation_result.eval_status}")
logger.info("-" * 100)

assert evaluation_result.overall_eval_status == EvalStatus.PASSED, (
f"{metric_name} for {agent_module} Failed. Expected {threshold},"
f" but got {evaluation_result.overall_score}."
Expand All @@ -151,6 +162,7 @@ async def evaluate(
num_runs: int = NUM_RUNS,
agent_name: Optional[str] = None,
initial_session_file: Optional[str] = None,
log_detailed_results: bool = False,
):
"""Evaluates an Agent given eval data.

Expand All @@ -166,6 +178,7 @@ async def evaluate(
agent_name: The name of the agent.
initial_session_file: File that contains initial session state that is
needed by all the evals in the eval dataset.
log_detailed_results: Logs detailed results. All invocation results will be logged if true.
"""
test_files = []
if isinstance(eval_dataset_file_path_or_dir, str) and os.path.isdir(
Expand All @@ -192,6 +205,7 @@ async def evaluate(
criteria=criteria,
num_runs=num_runs,
agent_name=agent_name,
log_detailed_results=log_detailed_results,
)

@staticmethod
Expand Down