Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions harbor_cookbook/gepa/optimize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# /// script
# dependencies = ["harbor", "gepa"]
# dependencies = ["harbor", "gepa @ git+https://github.com/gepa-ai/gepa.git@feat/async-evaluator-support"]
# requires-python = ">=3.12"
# ///
"""GEPA prompt optimization for MedAgentBench.
Expand Down Expand Up @@ -65,12 +65,12 @@
_environment: str = DEFAULT_ENVIRONMENT


def evaluate(candidate, example):
async def evaluate(candidate, example):
"""Run one Harbor trial and return (score, side_info)."""
task_id = example.id.name
log.info("Evaluating %s ...", task_id)

result = run_trial(
result = await run_trial(
candidate,
example.downloaded_path,
agent_name=_agent_name,
Expand Down Expand Up @@ -205,7 +205,6 @@ def main():
engine=EngineConfig(
max_metric_calls=args.max_evals,
max_candidate_proposals=args.max_iterations,
max_workers=args.max_workers,
run_dir=args.output_dir,
),
reflection=ReflectionConfig(
Expand Down
8 changes: 2 additions & 6 deletions harbor_cookbook/gepa/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""Utilities for downloading MedAgentBench tasks and running Harbor trials."""

import asyncio
import logging
import os
import shutil
import tempfile
import threading
from collections import defaultdict
from pathlib import Path

Expand All @@ -26,8 +24,6 @@
DEFAULT_MODEL = "openai/gpt-5-nano"
DEFAULT_ENVIRONMENT = EnvironmentType.DOCKER

_loop = asyncio.new_event_loop()
threading.Thread(target=_loop.run_forever, daemon=True).start()
_queue: TrialQueue | None = None


Expand Down Expand Up @@ -76,7 +72,7 @@ def _read_trial_file(trials_dir: Path, relative: str, limit: int = 3000) -> str:
return ""


def run_trial(
async def run_trial(
prompt: str,
task_path: Path,
agent_name: str = DEFAULT_AGENT,
Expand Down Expand Up @@ -111,7 +107,7 @@ def run_trial(
)

log.debug("Starting trial for %s", task_dir.name)
result = asyncio.run_coroutine_threadsafe(_queue.submit(config), _loop).result()
result = await _queue.submit(config)

rewards = result.verifier_result.rewards if result.verifier_result else {}
exc = result.exception_info
Expand Down
Loading