Overview
Concrete tool for evaluating workflow performance against benchmark datasets with configurable collation, postprocessing, and parallel execution.
Description
The Evaluator class orchestrates benchmark evaluation of both WorkFlowGraph and ActionGraph instances. It applies a user-defined `collate_func` to convert benchmark examples into workflow inputs, executes the workflow, applies `output_postprocess_func` to extract predictions, and calls `benchmark.evaluate()` to compute metrics. Supports both single-threaded and parallel evaluation (`num_workers > 1`), with thread-specific agent managers for safe concurrent execution. Maintains per-example evaluation records accessible via `get_all_evaluation_records()`.
Usage
- Benchmark evaluation: Pass a graph, benchmark, and collate/postprocess functions to `evaluate()`.
- AFlow evaluation: The `AFlowOptimizer` internally uses evaluation utilities that follow the same pattern.
- Async evaluation: Use `async_evaluate()` for concurrent evaluation with asyncio semaphores.
Code Reference
Source Location
- Repository: EvoAgentX
- File: evoagentx/evaluators/evaluator.py (L20-527)
Signature
class Evaluator:
def __init__(
self,
llm: BaseLLM,
num_workers: int = 1,
agent_manager: Optional[AgentManager] = None,
collate_func: Optional[Callable] = None, # default: identity
output_postprocess_func: Optional[Callable] = None, # default: identity
verbose: Optional[bool] = None,
**kwargs
)
def evaluate(
self,
graph: Union[WorkFlowGraph, ActionGraph],
benchmark: Benchmark,
eval_mode: str = "test",
indices: Optional[List[int]] = None,
sample_k: Optional[int] = None,
seed: Optional[int] = None,
verbose: Optional[bool] = None,
update_agents: Optional[bool] = False,
**kwargs
) -> dict
async def async_evaluate(
self,
graph: Union[WorkFlowGraph, ActionGraph],
benchmark: Benchmark,
eval_mode: str = "test",
indices: Optional[List[int]] = None,
sample_k: Optional[int] = None,
seed: Optional[int] = None,
verbose: Optional[bool] = None,
**kwargs
) -> dict
def get_all_evaluation_records(self) -> dict
Import
from evoagentx.evaluators.evaluator import Evaluator
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| llm |
BaseLLM |
Yes |
LLM for workflow execution
|
| graph |
ActionGraph |
Yes |
Workflow to evaluate
|
| benchmark |
Benchmark |
Yes |
Benchmark to evaluate against
|
| collate_func |
Callable |
No |
Converts benchmark example to workflow inputs dict
|
| output_postprocess_func |
Callable |
No |
Converts workflow output to prediction
|
| num_workers |
int |
No |
Parallel workers (default: 1)
|
| eval_mode |
str |
No |
"test", "dev", or "train" (default: "test")
|
| sample_k |
int |
No |
Random sample size
|
Outputs
| Name |
Type |
Description
|
| evaluate returns |
Average metrics (e.g., {"f1": 0.72, "em": 0.55, "acc": 0.68})
|
| _evaluation_records |
Per-example predictions, labels, metrics, trajectories
|
Usage Examples
Evaluate WorkFlowGraph on HotPotQA
from evoagentx.evaluators.evaluator import Evaluator
from evoagentx.benchmark.hotpotqa import HotPotQA
# Define collate function to convert HotPotQA example to workflow inputs
def collate_func(example):
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):
# WorkFlowGraph returns a string when extract_output=True
return output
evaluator = Evaluator(
llm=llm,
agent_manager=agent_manager,
collate_func=collate_func,
output_postprocess_func=output_postprocess_func,
num_workers=4,
verbose=True,
)
benchmark = HotPotQA(mode="dev")
metrics = evaluator.evaluate(graph=workflow_graph, benchmark=benchmark, eval_mode="dev", sample_k=50)
print(f"Average metrics: {metrics}")
Related Pages
Implements Principle
Requires Environment