Custom Code Evaluator
Custom code evaluators let you write your own evaluation logic in Python, JavaScript, or TypeScript. Your code has access to the application inputs, outputs, and the full execution trace (spans, latency, token usage, costs).
On self-hosted Agenta, custom evaluator code runs server-side. By default it runs with no sandbox in the services process (trusted, single-tenant use). Operators can change the runner with the AGENTA_SERVICES_CODE_SANDBOX_RUNNER environment variable: restricted runs code in an in-process Python sandbox (no filesystem, network, or host access), daytona runs it in an isolated remote sandbox. Set restricted or daytona to harden a shared/multi-tenant deployment. See environment configuration. Agenta Cloud is unaffected. It isolates evaluator execution.
Function signature
Your code must define an evaluate function with the following signature:
from typing import Dict, Any
def evaluate(
inputs: Dict[str, Any],
outputs: Any,
trace: Dict[str, Any],
) -> float:
Parameters
| Parameter | Type | Description |
|---|---|---|
inputs | Dict[str, Any] | In batch evaluation: the testcase data (all columns). In online evaluation: the application's input from the trace. |
outputs | Any | The application's output (string or dict). |
trace | Dict[str, Any] | The full execution trace with spans, metrics (latency, token counts, costs), and child spans. |
Return value
The function can return one of:
dict— a dictionary of metrics, such as{"score": 0.8, "success": True}or{"relevance": 0.9, "tone": 0.4, "reason": "missed the greeting"}. Each key becomes a separate metric in the evaluation results. Values must be JSON-serializable. Nested dictionaries are flattened into dotted metric names.float(0.0 to 1.0) — a single score where 0.0 is worst and 1.0 is best. Agenta normalizes it to{"score": <value>, "success": <value >= threshold>}.bool— normalized to{"success": <value>}.
Examples
Exact match
from typing import Dict, Any
def evaluate(
inputs: Dict[str, Any],
outputs: Any,
trace: Dict[str, Any],
) -> dict:
success = outputs == inputs.get("correct_answer")
return {
"score": 1.0 if success else 0.0,
"success": success,
}