Skip to main content
Harbor’s metric system allows you to define custom aggregation functions for evaluating agent performance beyond simple success rates. This guide shows you how to implement and use custom metrics.

Overview

Custom metrics enable:
  • Domain-specific evaluation: Track metrics relevant to your use case
  • Partial credit: Reward partial success
  • Multi-dimensional scoring: Combine multiple criteria
  • Statistical analysis: Compute percentiles, distributions, etc.

Built-in Metrics

Harbor includes several built-in metrics:

Creating Custom Metrics

Method 1: Python Class

Implement the BaseMetric interface:
metrics/custom_metric.py
Use in job configuration:

Method 2: UvScript

For simpler metrics, use inline Python:
job-config.yaml
UvScript metrics receive a trials list with all trial results and must set a result variable.

Example Custom Metrics

Percentile Metrics

Usage:

Weighted Metrics

Cost Efficiency

Time-Based Metrics

Multi-Metric Evaluation

Track multiple metrics simultaneously:
job-config.yaml
Access results:
Output:

Category-Specific Metrics

Track metrics per category:

Best Practices

  1. Handle edge cases: Empty trials, missing metadata, etc.
  2. Reset properly: Clear state between jobs
  3. Document behavior: Explain what your metric measures
  4. Type hints: Use proper type annotations
  5. Test thoroughly: Validate on sample data first
  6. Consider efficiency: Avoid expensive computations in update()
  7. Return appropriate types: Float for scalar, dict for breakdowns

Debugging Metrics

Test metric implementation:

Advanced: Confidence Intervals

Next Steps

Verifiers

Learn about reward generation

Parameter Sweeps

Use metrics in sweeps

Job Results

Understand result structure

BaseMetric API

Full metric API reference