HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
fast-agent is told what the turn's model reads, so Claude gets attach_media and sees images (#600)
github-actions[bot]1f39e3f335c6
diff --git a/runner/server.py b/runner/server.pyindex 99ddfbc3..82e4fd04 100644--- a/runner/server.py+++ b/runner/server.py@@ -13226,6 +13226,84 @@ def _fast_agent_drop_media(cwd: str, session_id: str, model: str) -> int:return removed+# What fast-agent itself believes a model id reads, as `--model generic.<id>` resolves it with no overlay:+# its input types and its limits, or None for an id its table does not have. MEASURED on 0.10.47+# (2026-10-27): an id it does not know is text only to it (ModelInfo's fallback, tokenizes+# ["text/plain"]), so `enable_attach_media: auto` hid attach_media and every image was filtered out of+# the messages. 65 of the ids this base sends were unknown, among them every dotted Claude id+# (claude-opus-5.5; its table spells claude-opus-5-5) and gemini, grok, qwen, mistral and deepseek ids+# whose channels take images: Claude on fast-agent never saw an image. Asked of fast-agent's own python+# and table, once per id per process (0.8 s).+_FA_PROBE = (+ "import json, os, sys, tempfile\n"+ "os.environ['FAST_AGENT_HOME'] = tempfile.mkdtemp()\n"+ "from fast_agent.llm.model_factory import ModelFactory\n"+ "r = ModelFactory.resolve_model_spec('generic.' + sys.argv[1])\n"+ "i = r.build_model_info() if r.model_params is not None else None\n"+ "print(json.dumps(None if i is None else {'tokenizes': list(i.tokenizes or [])}))\n")+_FA_KNOWN: dict[str, dict | None] = {}+# The image types a model whose channel takes images is declared to read (the gateway's `vision`).+_FA_IMAGES = ("image/png", "image/jpeg", "image/gif", "image/webp")+# Limits for an id fast-agent does not know. Its overlay is used only when it names both, and it then+# sends the cap as max_tokens, which an id it does not know never carried: the turn's route drops it+# again, so the provider's own default applies as before. The window only sets where its compaction+# starts, which for an unknown id was never: one no model here reaches keeps it there.+_FA_UNKNOWN_LIMITS = {"context_window": 2_000_000, "max_output_tokens": 128_000}+# One file, rewritten every turn: a resumed session names the same `generic.<id>`, so it reads this+# turn's file, never a stale one.+_FA_OVERLAY_FILE = "harness-turn.yaml"+++def _fast_agent_known(model: str) -> dict | None | bool:+ """fast-agent's own view of `model` (see _FA_PROBE); False when it could not be asked, which leaves+ the turn exactly as it was before overlays."""+ if model in _FA_KNOWN:+ return _FA_KNOWN[model]+ try:+ out = subprocess.run([FAST_AGENT_PYTHON, "-I", "-c", _FA_PROBE, model], capture_output=True,+ text=True, timeout=60, cwd=tempfile.gettempdir())+ view = json.loads(out.stdout.strip().splitlines()[-1]) if out.returncode == 0 else False+ except (OSError, subprocess.SubprocessError, ValueError, IndexError):+ view = False+ if view is not False and not (view is None or isinstance(view, dict)):+ view = False+ if view is not False:+ _FA_KNOWN[model] = view+ return view+++def _fast_agent_overlay(home: pathlib.Path, model: str, vision: bool) -> bool:+ """Declare what this turn's model reads to fast-agent, where its own table says otherwise.++ The gateway knows whether the model's channel takes images (`vision`, from _TEXT_ONLY_INPUT);+ fast-agent decides from its own table whether to offer attach_media and whether to keep an image in+ a message. Where the two disagree, a model overlay named exactly as the runner's `--model`+ (`generic.<id>`) in `<home>/model-overlays/` carries the gateway's answer: fast-agent resolves the+ name to the overlay and the id it sends upstream is unchanged (measured on 0.10.47). An id it+ knows keeps its own limits and every other type it reads; an id it does not know gets+ _FA_UNKNOWN_LIMITS. Where they agree, no overlay is written and an earlier one is removed.+ Returns True when the overlay carries those made-up limits, so the route drops the cap."""+ path = home / "model-overlays" / _FA_OVERLAY_FILE+ known = _fast_agent_known(model)+ takes = list(known["tokenizes"]) if isinstance(known, dict) else ["text/plain"]+ if vision:+ # a model it already lets read images keeps its own list+ want = takes if any(str(t).startswith("image/") for t in takes) else takes + list(_FA_IMAGES)+ else:+ # a channel that refuses images: text alone, as _fast_agent_drop_media leaves the history+ want = ["text/plain"]+ if known is False or want == takes:+ path.unlink(missing_ok=True)+ return False+ doc = {"name": f"generic.{model}", "provider": "generic", "model": model,+ "metadata": {"tokenizes": want, **({} if known else _FA_UNKNOWN_LIMITS)}}+ path.parent.mkdir(parents=True, exist_ok=True)+ tmp = path.with_suffix(".yaml.hr-tmp")+ tmp.write_text(json.dumps(doc), encoding="utf-8") # JSON is YAML; fast-agent reads it with yaml+ os.replace(tmp, path)+ return not known++def _fast_agent_config(cwd: str, tools_disabled: list[str] | None,mcp_servers: list[dict] | None, base_url: str = "") -> tuple[pathlib.Path, list[str]]:"""Write the fastagent.config.yaml this turn runs with, and name the servers it declares.@@ -13325,11 +13403,16 @@ def _build_fast_agent(provider: str, auth: Auth, model: str, prompt: str, cwd: sf"(one of {sorted(FAST_AGENT_PROVIDERS)})")if not auth.base_url:raise HTTPException(400, f"fast-agent provider '{pr}' needs a base_url (none configured)")- if auth.api_key:- relay_base, relay_tok = _hermes_relay_route(auth.base_url, auth.api_key, chat_cache=True)- auth = auth.model_copy(update={"base_url": relay_base, "api_key": relay_tok})home = _fast_agent_home(cwd)home.mkdir(parents=True, exist_ok=True)+ if auth.api_key:+ # what the model reads, declared where fast-agent's own table disagrees (_fast_agent_overlay);+ # only through the relay, which takes back the cap made-up limits would add+ made_up = _fast_agent_overlay(home, model, vision)+ relay_base, relay_tok = _hermes_relay_route(+ auth.base_url, auth.api_key, chat_cache=True,+ drop_fields=("max_tokens", "max_completion_tokens") if made_up else ())+ auth = auth.model_copy(update={"base_url": relay_base, "api_key": relay_tok})cfg, server_names = _fast_agent_config(cwd, tools_disabled, mcp_servers, base_url=auth.base_url or "")env["FAST_AGENT_HOME"] = str(home)env[_FA_BASE_ENV] = (auth.base_url or "").rstrip("/")diff --git a/runner/tests/test_fast_agent_overlay.py b/runner/tests/test_fast_agent_overlay.pynew file mode 100644index 00000000..fe3bf311--- /dev/null+++ b/runner/tests/test_fast_agent_overlay.py@@ -0,0 +1,112 @@+"""fast-agent is told what the turn's model reads where its own table says otherwise (_fast_agent_overlay).++MEASURED on fast-agent 0.10.47 (2026-10-27): an id its table does not have is text only to it, so+attach_media is not offered and images are filtered out of the messages; claude-opus-5.5 was one of 65+such ids. A model overlay named `generic.<id>` in the home's model-overlays/ is what `--model+generic.<id>` resolves to, with the id sent upstream unchanged. These tests pin the decision and what+reaches the relay; fast-agent's own view is stubbed (its python is not on a test machine)."""+import json+import pathlib+import subprocess+import sys+import tempfile++import pytest++sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))+import server # noqa: E402+from server import Auth, FAST_AGENT_DRIVER, _build_fast_agent, _fast_agent_home # noqa: E402++UP = "https://up.example/v1"+GPT = ["text/plain", "image/jpeg", "image/png", "image/webp", "application/pdf"]+++def _ws() -> str:+ d = tempfile.mkdtemp()+ (pathlib.Path(d) / ".harness" / "home").mkdir(parents=True)+ return d+++def view(monkeypatch):+ """fast-agent's own answer per id: a dict (known), None (unknown) or False (could not be asked)."""+ answers: dict = {}+ monkeypatch.setattr(server, "_fast_agent_known", lambda m: answers.get(m, None))+ return answers+++def _turn(model: str, vision: bool, ws: str | None = None):+ ws = ws or _ws()+ env: dict = {}+ cmd = _build_fast_agent("openai-api", Auth(base_url=UP, api_key="k"), model, "hi", ws, env, vision=vision)+ assert cmd[1] == FAST_AGENT_DRIVER+ argv = json.loads(cmd[2])["argv"]+ route = server._HERMES_RELAY["routes"][env["GENERIC_API_KEY"]]+ path = _fast_agent_home(ws) / "model-overlays" / server._FA_OVERLAY_FILE+ doc = json.loads(path.read_text()) if path.exists() else None+ return argv, route[2], doc, ws+++def test_an_id_it_does_not_know_reads_images_when_its_channel_does(view):+ argv, flags, doc, _ = _turn("claude-opus-5.5", vision=True)+ assert argv[argv.index("--model") + 1] == "generic.claude-opus-5.5" # the id it sends is unchanged+ assert doc["name"] == "generic.claude-opus-5.5" and doc["provider"] == "generic" and doc["model"] == "claude-opus-5.5"+ assert doc["metadata"]["tokenizes"] == ["text/plain", *server._FA_IMAGES]+ # its overlay needs limits, and the cap it would send as max_tokens never went before: the route drops it+ assert doc["metadata"]["context_window"] and doc["metadata"]["max_output_tokens"]+ assert {"max_tokens", "max_completion_tokens"} <= set(flags["drop_fields"])+++def test_an_id_it_knows_with_images_is_left_to_its_own_table(view):+ view["gpt-5.4"] = {"tokenizes": GPT}+ _, flags, doc, _ = _turn("gpt-5.4", vision=True)+ assert doc is None and "max_tokens" not in flags["drop_fields"]+++def test_a_text_only_channel_reads_text_alone_whatever_the_table_says(view):+ view["glm-5.3-flash"] = {"tokenizes": GPT}+ _, flags, doc, _ = _turn("glm-5.3-flash", vision=False)+ # its own limits stay: no made-up ones, nothing dropped+ assert doc["metadata"] == {"tokenizes": ["text/plain"]} and "max_tokens" not in flags["drop_fields"]+ # an id it does not know is already text only to it: nothing to declare+ _, _, doc, _ = _turn("qwen3.7-max", vision=False)+ assert doc is None+++def test_a_known_text_only_id_whose_channel_takes_images_gets_them(view):+ view["some-model"] = {"tokenizes": ["text/plain", "application/pdf"]}+ _, flags, doc, _ = _turn("some-model", vision=True)+ assert doc["metadata"] == {"tokenizes": ["text/plain", "application/pdf", *server._FA_IMAGES]}+ assert "max_tokens" not in flags["drop_fields"]+++def test_the_file_is_this_turns_and_an_earlier_one_goes_when_none_is_needed(view):+ view["gpt-5.4"] = {"tokenizes": GPT}+ _, _, doc, ws = _turn("claude-sonnet-5.5", vision=True)+ assert doc["model"] == "claude-sonnet-5.5"+ _, _, doc, _ = _turn("gpt-5.4", vision=True, ws=ws) # a switch to a model its table knows+ assert doc is None+++def test_when_it_cannot_be_asked_the_turn_is_as_before(view):+ view["claude-opus-5.5"] = False+ _, flags, doc, _ = _turn("claude-opus-5.5", vision=True)+ assert doc is None and "max_tokens" not in flags["drop_fields"]+++def test_its_view_is_asked_once_per_id(monkeypatch):+ calls = []++ def run(cmd, **kw):+ calls.append(cmd[-1])+ out = json.dumps(None if cmd[-1] == "claude-opus-5.5" else {"tokenizes": GPT})+ return subprocess.CompletedProcess(cmd, 0, stdout=out + "\n", stderr="")+ monkeypatch.setattr(server, "_FA_KNOWN", {})+ monkeypatch.setattr(server.subprocess, "run", run)+ assert server._fast_agent_known("claude-opus-5.5") is None+ assert server._fast_agent_known("gpt-5.4") == {"tokenizes": GPT}+ assert server._fast_agent_known("claude-opus-5.5") is None+ assert calls == ["claude-opus-5.5", "gpt-5.4"]+ # a probe that fails is not remembered: the next turn asks again+ monkeypatch.setattr(server.subprocess, "run", lambda cmd, **kw: subprocess.CompletedProcess(cmd, 1, "", "boom"))+ assert server._fast_agent_known("kimi-k3") is False and "kimi-k3" not in server._FA_KNOWN