Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ANative Lab EvoAgentX Evaluation Functions

From Leeroopedia
Knowledge Sources
Domains Evaluation, RAG
Last Updated 2026-10-21 00:00 GMT

Overview

Interface specification for user-defined collate and postprocess functions consumed by the Evaluator, plus built-in QA evaluation metrics.

Description

This is a Pattern Doc documenting two user-defined callables that the Evaluator consumes: collate_func and output_postprocess_func. The `collate_func` receives a raw benchmark example dict and returns a inputs dict matching the workflow's input parameters. The `output_postprocess_func` receives the raw workflow output (string for WorkFlowGraph, dict for ActionGraph) and returns a prediction for `benchmark.evaluate()`. Additionally, built-in QA metrics (`f1_score`, `exact_match_score`, `acc_score`) from `evoagentx/benchmark/measures.py` are documented for custom evaluation.

Usage

  • Benchmark evaluation: Define `collate_func` and `output_postprocess_func` when creating an `Evaluator`.
  • RAG evaluation: Use custom metric functions (precision@k, recall@k, F1, MRR) computed from `RagResult` fields.
  • Custom metrics: Subclass `Benchmark` and implement `evaluate()` with custom metrics.

Code Reference

Source Location

  • Repository: EvoAgentX
  • Metrics File: evoagentx/benchmark/measures.py
  • Consumed at: evoagentx/evaluators/evaluator.py (L56-57, L172, L187)

Interface Specification

collate_func

def collate_func(example: dict) -> dict:
    """
    Convert a benchmark example into a dict of workflow inputs.

    Args:
        example: A raw benchmark example dict (e.g., HotPotQA example
                 with "question", "answer", "context" keys).

    Returns:
        A dict whose keys match the workflow's input parameter names.
        For WorkFlowGraph, keys must match graph.workflow_inputs.
        For ActionGraph, keys must match the execute() signature.
    """
    ...

output_postprocess_func

def output_postprocess_func(output: Union[str, dict]) -> Any:
    """
    Extract a prediction from the raw workflow output.

    Args:
        output: For WorkFlowGraph, a string (extract_output=True).
                For ActionGraph, a dict (e.g., {"answer": "..."}).

    Returns:
        The prediction value to pass to benchmark.evaluate(prediction=...).
    """
    ...

Built-in QA Metrics

from evoagentx.benchmark.measures import f1_score, exact_match_score, acc_score

# f1_score(prediction: str, ground_truth: str) -> float
# exact_match_score(prediction: str, ground_truth: str) -> float (0.0 or 1.0)
# acc_score(prediction: str, ground_truths: List[str]) -> float

Usage Examples

Collate and Postprocess for HotPotQA

from evoagentx.evaluators.evaluator import Evaluator

def collate_func(example):
    """Convert HotPotQA example to workflow inputs."""
    paragraphs = [item[1] for item in example["context"] if isinstance(item[1], list)]
    context_str = "\n".join(" ".join(p) for p in paragraphs)
    return {"question": example["question"], "context": context_str}

def output_postprocess_func(output):
    """Extract answer from WorkFlowGraph string output."""
    return output

evaluator = Evaluator(
    llm=llm,
    collate_func=collate_func,
    output_postprocess_func=output_postprocess_func,
)

RAG Evaluation Metrics

from evoagentx.rag.rag import RAGEngine

def evaluate_retrieval(engine, query, ground_truth_chunks, corpus_id, k=5):
    """Compute precision@k and recall@k for RAG retrieval."""
    result = engine.query(query=query, corpus_id=corpus_id)
    retrieved_ids = [chunk.chunk_id for chunk in result.corpus.chunks[:k]]
    relevant_ids = {chunk.chunk_id for chunk in ground_truth_chunks}

    retrieved_relevant = len(set(retrieved_ids) & relevant_ids)
    precision = retrieved_relevant / len(retrieved_ids) if retrieved_ids else 0
    recall = retrieved_relevant / len(relevant_ids) if relevant_ids else 0
    return {"precision@k": precision, "recall@k": recall}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment