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 theBaseAgent abstract class, ensuring consistent execution and evaluation across different implementations.
BaseAgent Interface
The foundation of Harbor’s agent system is theBaseAgent 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, orNone 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_dirto the agent’s expected location - Set up any required authentication
run()
Executes the agent to complete the task. Must populate thecontext 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
TheAgentContext model tracks agent execution metadata:
Fields
n_input_tokens: Total input tokens (including cache reads)n_cache_tokens: Tokens served from cachen_output_tokens: Generated tokenscost_usd: Total cost in USDrollout_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 agentopenhands- OpenHands coding agentaider- Aider pair programming toolcodex- Codex CLI toolgoose- Goose AI agentgemini-cli- Google Gemini CLIqwen-coder- Qwen Code assistantopencode- OpenCode agentcursor-cli- Cursor CLI toolcline-cli- Cline CLI agentmini-swe-agent- Lightweight SWE agent
Internal Agents
terminus- Advanced Terminus agentterminus-1- Terminus variant 1terminus-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:setup().
Model Configuration
Agents can be configured with specific models:AgentInfo Metadata
Each trial records information about the agent:ATIF Support
Agents can support the Agent Trajectory Interchange Format (ATIF) for RL optimization: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:ANTHROPIC_API_KEY- For Claude-based agentsOPENAI_API_KEY- For OpenAI-based agents- Custom API keys and configuration
Creating Custom Agents
Step 1: Extend BaseAgent
Step 2: Register the Agent
Add tosrc/harbor/models/agent/name.py:
Step 3: Update Agent Factory
Register insrc/harbor/agents/factory.py:
Step 4: Use Your Agent
Best Practices
Error Handling
Error Handling
- Catch and log exceptions in
run()andsetup() - Don’t let exceptions propagate silently
- Provide meaningful error messages
- Set appropriate timeouts
Resource Management
Resource Management
- Clean up temporary files after execution
- Respect timeout constraints
- Minimize installation time in
setup() - Use efficient logging practices
Context Population
Context Population
- Always populate token counts when possible
- Calculate costs accurately
- Include relevant metadata
- Document custom metadata fields
Reproducibility
Reproducibility
- Pin dependency versions
- Use deterministic configuration
- Document random seed handling
- Make agent behavior predictable
Related Topics
Environments
Execution environments for agents
Trials
How agents are executed in trials
Tasks
Tasks that agents complete
Metrics
Measuring agent performance