Skip to main content
Harbor makes it easy to evaluate custom agents alongside built-in ones. This guide shows you how to implement your own agent that integrates seamlessly with Harbor’s evaluation framework.

Agent Interface

All agents inherit from BaseAgent and implement these core methods:

Quick Start

Create a simple custom agent:

BaseAgent Methods

name() (Required)

Return a unique identifier for your agent:

version() (Required)

Return the agent version for reproducibility:

setup() (Required)

Install and configure the agent in the environment:

run() (Required)

Execute the agent on the task:

Using the Environment

The BaseEnvironment provides methods to interact with the containerized environment:

Executing Commands

File Operations

Populating Context

The AgentContext tracks execution metrics and results:

AgentContext Fields

  • commands_executed - Number of commands run
  • exit_code - Final exit code
  • n_input_tokens - LLM input tokens used
  • n_output_tokens - LLM output tokens used
  • n_cache_tokens - Cached tokens used
  • cost_usd - Total cost in USD
  • error_message - Error description if failed

Installed Agents Pattern

For agents that require installation, extend BaseInstalledAgent:
Installation template (install-my-agent.sh.j2):

Agent Configuration

Accept configuration through constructor:
Pass configuration via CLI:

MCP Server Support

Access MCP servers provided by tasks:

Skills Support

Access skills provided by tasks:

Trajectory Support (ATIF)

For advanced agents, implement trajectory tracking:

Error Handling

Implement robust error handling:

Testing Your Agent

Unit Tests

tests/test_my_agent.py

Integration Tests

Real-World Example

Here’s a complete example of a custom agent that uses OpenAI’s API:
openai_agent.py
Run it:

Best Practices

  1. Handle timeouts gracefully: Agents may be interrupted
  2. Log extensively: Use self.logger for debugging
  3. Populate context: Track metrics for analysis
  4. Save artifacts: Download important files to self.logs_dir
  5. Use async properly: All environment operations are async
  6. Test thoroughly: Unit test logic, integration test with real tasks
  7. Version your agent: Update version when behavior changes
  8. Document configuration: Explain all constructor parameters

Next Steps

Running Evaluations

Run evaluations with your custom agent

Creating Tasks

Build tasks to test your agent’s capabilities

Benchmark Adapters

Evaluate your agent on standard benchmarks