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
8 changes: 8 additions & 0 deletions agentcore/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,14 @@ fn spawn_cli_turn(p: &TurnParams) -> io::Result<Child> {
"--permission-mode",
"bypassPermissions",
]);
if !p
.extra_args
.iter()
.any(|a| a == "--setting-sources" || a.starts_with("--setting-sources="))
{
// Avoid blocking headless turns on user-installed interactive SessionStart hooks.
cmd.args(["--setting-sources", ""]);
}
if let Some(m) = &p.model {
cmd.args(["--model", m]);
}
Expand Down
38 changes: 29 additions & 9 deletions evals/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,23 @@ def watch_timeout() -> None:
timer.start()

turn_idx = 0
pending_prompt_idx: int | None = None
start_req_id: str | None = None
mcp_script = Path(__file__).resolve().parent / "mock_mcp.py"

def send_prompt(idx: int) -> None:
turn = task.turns[idx]
prompt_op: dict[str, Any] = {
"type": "prompt",
"nonce": f"n{idx + 1}",
"text": turn.prompt,
}
if check:
prompt_op["check"] = True
send(prompt_op)

def start_session_and_prompt(idx: int) -> None:
nonlocal pending_prompt_idx, start_req_id
turn = task.turns[idx]
if idx == 0 or turn.new_session:
if task.needs_mcp:
Expand All @@ -223,22 +237,18 @@ def start_session_and_prompt(idx: int) -> None:
],
}
)
send({"type": "start", "bot": f"eval-{task.id}"})
if not acp_command and not cli_command:
send({"type": "set_model", "model": effective_model})
if fallback_model:
send({"type": "fallback_model", "model": fallback_model})
send({"type": "step_limit", "steps": steps})
elif cli_command and effective_model and effective_model != "default":
send({"type": "set_model", "model": effective_model})
prompt_op: dict[str, Any] = {
"type": "prompt",
"nonce": f"n{idx + 1}",
"text": turn.prompt,
}
if check:
prompt_op["check"] = True
send(prompt_op)
pending_prompt_idx = idx
send({"type": "start", "bot": f"eval-{task.id}"})
start_req_id = f"e{req_n}"
return
send_prompt(idx)

with trace_path.open("w", encoding="utf-8") as trace_f:
for line in proc.stdout:
Expand All @@ -255,6 +265,16 @@ def start_session_and_prompt(idx: int) -> None:

if et == "ready":
start_session_and_prompt(0)
elif et == "session":
if pending_prompt_idx is not None:
idx = pending_prompt_idx
pending_prompt_idx = None
start_req_id = None
send_prompt(idx)
elif et == "response" and ev.get("error") and ev.get("id") == start_req_id:
turn_reasons.append("error")
turn_errors.append(str(ev.get("error")))
break
elif et == "token":
tok: dict[str, Any] = {
"type": "token",
Expand Down
43 changes: 31 additions & 12 deletions evals/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ def handle_ctl(self, cmd: dict[str, Any]) -> dict[str, Any]:
def base_url(self) -> str:
return f"http://{self.host}:{self.port}/v1"

def _call_omp_stdio(self, path: str, body: dict[str, Any]) -> tuple[int, dict[str, Any]]:
def _call_omp_stdio(
self, path: str, body: dict[str, Any] | None = None, method: str = "POST"
) -> tuple[int, dict[str, Any]]:
with self._omp_lock:
if self._omp_proc is None or self._omp_proc.poll() is not None:
omp_bin = shutil.which("omp") or "omp"
Expand All @@ -444,21 +446,34 @@ def _call_omp_stdio(self, path: str, body: dict[str, Any]) -> tuple[int, dict[st
)
assert self._omp_proc.stdin is not None and self._omp_proc.stdout is not None
self._omp_req_id += 1
req_frame = {"id": self._omp_req_id, "path": path, "body": {**body, "stream": False}}
req_id = self._omp_req_id
req_frame: dict[str, Any] = {"id": req_id, "method": method, "path": path}
if body is not None:
req_frame["body"] = {**body, "stream": False}
self._omp_proc.stdin.write(json.dumps(req_frame) + "\n")
self._omp_proc.stdin.flush()
line = self._omp_proc.stdout.readline()
if not line:
return 502, {"error": {"message": "omp auth-gateway stdio closed unexpectedly"}}
resp = json.loads(line)
status = int(resp.get("status", 200))
payload = resp.get("body", resp)
if isinstance(payload, str):
# Skip startup banners (e.g. `{"ready":true,"version":...}`) until matching `id`.
while True:
line = self._omp_proc.stdout.readline()
if not line:
return 502, {"error": {"message": "omp auth-gateway stdio closed unexpectedly"}}
line = line.strip()
if not line:
continue
try:
payload = json.loads(payload)
resp = json.loads(line)
except json.JSONDecodeError:
payload = {"error": {"message": payload}}
return status, payload if isinstance(payload, dict) else {"data": payload}
continue
if resp.get("id") != req_id:
continue
status = int(resp.get("status", 200))
payload = resp.get("body", resp)
if isinstance(payload, str):
try:
payload = json.loads(payload)
except json.JSONDecodeError:
payload = {"error": {"message": payload}}
return status, payload if isinstance(payload, dict) else {"data": payload}

def _dispatch_chat(
self, req_body: dict[str, Any], target: RouteTarget
Expand Down Expand Up @@ -645,6 +660,10 @@ def do_GET(self) -> None:
self._send(200, "application/json", json.dumps(gw.status_snapshot()).encode("utf-8"))
return
if self.path.rstrip("/") in ("/v1/models", "/models"):
if gw.default_target.backend == "omp":
code, payload = gw._call_omp_stdio("/v1/models", body=None, method="GET")
self._send(code, "application/json", json.dumps(payload).encode("utf-8"))
return
models = [{"id": k, "object": "model"} for k in gw.routes] or [
{"id": gw.default_target.model_override or "default", "object": "model"}
]
Expand Down
Loading