Skip to main content

Overview

Agents are AI systems that attempt to complete tasks in Harbor. Harbor provides a unified interface for evaluating diverse agents, from commercial products like Claude Code to open-source tools like Aider and OpenHands. All agents in Harbor implement the BaseAgent abstract class, ensuring consistent execution and evaluation across different implementations.

BaseAgent Interface

The foundation of Harbor’s agent system is the BaseAgent abstract class defined in src/harbor/agents/base.py:

Required Methods

name()

Returns the agent’s identifier as a string.
This is a static method, so it can be called without instantiating the agent.

version()

Returns the agent’s version, or None if not applicable.

setup()

Prepares the agent for execution. This is where you:
  • Install the agent and its dependencies
  • Configure MCP servers from self.mcp_servers
  • Copy skills from self.skills_dir to the agent’s expected location
  • Set up any required authentication
The setup() method is called once per trial. Keep it efficient to minimize overhead.

run()

Executes the agent to complete the task. Must populate the context parameter with execution results.
Populate the context: The AgentContext object should be updated with token usage, costs, and any other relevant metadata. This data is saved in trial results.

AgentContext

The AgentContext model tracks agent execution metadata:

Fields

  • n_input_tokens: Total input tokens (including cache reads)
  • n_cache_tokens: Tokens served from cache
  • n_output_tokens: Generated tokens
  • cost_usd: Total cost in USD
  • rollout_details: Trajectory data for RL training (ATIF format)
  • metadata: Additional agent-specific data

Built-in Agents

Harbor includes many pre-built agents:

Installed Agents

These agents are installed in the environment at runtime:
  • claude-code - Anthropic’s Claude Code agent
  • openhands - OpenHands coding agent
  • aider - Aider pair programming tool
  • codex - Codex CLI tool
  • goose - Goose AI agent
  • gemini-cli - Google Gemini CLI
  • qwen-coder - Qwen Code assistant
  • opencode - OpenCode agent
  • cursor-cli - Cursor CLI tool
  • cline-cli - Cline CLI agent
  • mini-swe-agent - Lightweight SWE agent

Internal Agents

  • terminus - Advanced Terminus agent
  • terminus-1 - Terminus variant 1
  • terminus-2 - Terminus variant 2

Utility Agents

  • oracle - Perfect agent for testing (uses reference solutions)
  • nop - No-operation agent (does nothing)

Agent Installation

Many agents use Jinja2 templates for installation scripts:
The template is rendered with agent-specific variables during setup().

Model Configuration

Agents can be configured with specific models:
The model name is parsed into provider and name:

AgentInfo Metadata

Each trial records information about the agent:
This is automatically populated from the agent:

ATIF Support

Agents can support the Agent Trajectory Interchange Format (ATIF) for RL optimization:
When SUPPORTS_ATIF = True, the agent should populate context.rollout_details with trajectory data including:
  • Token IDs
  • Loss masks
  • Log probabilities

Environment Variables

Pass environment variables to agents at runtime:
Common variables:
  • ANTHROPIC_API_KEY - For Claude-based agents
  • OPENAI_API_KEY - For OpenAI-based agents
  • Custom API keys and configuration

Creating Custom Agents

Step 1: Extend BaseAgent

Step 2: Register the Agent

Add to src/harbor/models/agent/name.py:

Step 3: Update Agent Factory

Register in src/harbor/agents/factory.py:

Step 4: Use Your Agent

Best Practices

  • Catch and log exceptions in run() and setup()
  • Don’t let exceptions propagate silently
  • Provide meaningful error messages
  • Set appropriate timeouts
  • Clean up temporary files after execution
  • Respect timeout constraints
  • Minimize installation time in setup()
  • Use efficient logging practices
  • Always populate token counts when possible
  • Calculate costs accurately
  • Include relevant metadata
  • Document custom metadata fields
  • Pin dependency versions
  • Use deterministic configuration
  • Document random seed handling
  • Make agent behavior predictable

Environments

Execution environments for agents

Trials

How agents are executed in trials

Tasks

Tasks that agents complete

Metrics

Measuring agent performance