eval: gobang as a Track B native agent
gobang, the Aji-native harness, joins Codex, Claude Code and OpenCode in ajieval native. Like them it is an agent product: its runs are never evidence for H4. Model ids choose the provider: claude-* the Anthropic API, any other GLM via z.ai, fixture:PATH a scenario without network (self-tests). gobang reaches the model over its API, so the key's variable is passed into the sandbox environment; NativeAgent.env supplies it, its value never enters the run record, and a missing key stops the run before anything is created. Tool processes run in gobang's own networkless bubblewrap sandbox, so no shell wrapper is used. The transcript is gobang's journal: usage, tool calls and the model come from its events, the repair metrics from its toolchain tools (aji_check, aji_run, run_tests with aji's exit codes), and its documentation tools count as reads of /docs files. Checked end to end on dev-echo (aji_source) with a fixture model: the dev evaluator accepts the solution, the workspace holds only the solution, and the first-check and first-test metrics are exact. With a fake key the run reaches z.ai from the sandbox and ends INFRA_FAILED (auth) without the key in any file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
762c5abe7b
commit
0e98638bc6
4 files changed
+246
-2
No files matched your search
@@ -71,6 +71,11 @@ class NativeAgent:
|
||||
"""Writes the agent's minimal configuration into the fresh HOME."""
|
||||
return {}
|
||||
|
||||
def env(self, model):
|
||||
"""Environment variables the agent needs inside the sandbox (an API
|
||||
key). Their values are never written to the run record."""
|
||||
return {}
|
||||
|
||||
def argv(self, model, effort, prompt):
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -234,7 +239,118 @@ class OpenCode(NativeAgent):
|
||||
return facts
|
||||
|
||||
|
||||
AGENTS = {a.name: a for a in (Codex(), Claude(), OpenCode())}
|
||||
|
||||
GOBANG_ZAI_URL = "https://api.z.ai/api/coding/paas/v4"
|
||||
|
||||
|
||||
class Gobang(NativeAgent):
|
||||
"""gobang, the Aji-native harness (a sibling repository). The
|
||||
scaffold is the agent product here too, so these runs
|
||||
are never evidence for H4 (protocol §39b); they measure the harness
|
||||
against the other agents on the same model where possible.
|
||||
|
||||
The model gives no shell commands: gobang runs aji and test commands
|
||||
itself, in its own networkless bubblewrap sandbox nested in this one,
|
||||
so no shell wrapper is needed. It reaches the model over its API, so
|
||||
the key is passed as an environment variable; the configuration names
|
||||
only the variable.
|
||||
|
||||
Model ids: `claude-*` uses the Anthropic API (ANTHROPIC_API_KEY); any
|
||||
other id uses GLM via z.ai (ZAI_API_KEY); `fixture:PATH` replays a
|
||||
gobang scenario file without a network (harness self-tests)."""
|
||||
|
||||
name = "gobang"
|
||||
binary = "gobang"
|
||||
credentials = []
|
||||
command_network = "disabled (gobang's own bubblewrap sandbox; the model has no shell)"
|
||||
netless_shell = False
|
||||
|
||||
def _provider(self, model):
|
||||
if model.startswith("fixture:"):
|
||||
return "fixture", None, None
|
||||
if model.startswith("claude"):
|
||||
return "anthropic", "ANTHROPIC_API_KEY", None
|
||||
return "openai", "ZAI_API_KEY", GOBANG_ZAI_URL
|
||||
|
||||
def account_mode(self):
|
||||
return "API key from the environment (ZAI_API_KEY or ANTHROPIC_API_KEY)"
|
||||
|
||||
def configure(self, home, model, effort):
|
||||
provider, key_env, base = self._provider(model)
|
||||
d = os.path.join(home, ".config", "gobang")
|
||||
os.makedirs(d, exist_ok=True)
|
||||
lines = ["version = 1", "", "[toolchain]", 'aji = "aji"', "", "[model]", f'provider = "{provider}"']
|
||||
if provider == "fixture":
|
||||
shutil.copyfile(model[len("fixture:"):], os.path.join(d, "scenario.jsonl"))
|
||||
lines.append('fixture = "scenario.jsonl"')
|
||||
else:
|
||||
lines += [f'model = "{model}"', f'key_env = "{key_env}"']
|
||||
if base:
|
||||
lines.append(f'base_url = "{base}"')
|
||||
if effort:
|
||||
lines.append(f'extra = {{ reasoning_effort = "{effort}" }}')
|
||||
lines += ["", "[sandbox]", 'mode = "required"', "", "[context]", 'docs = "/docs"', ""]
|
||||
cfg = "\n".join(lines)
|
||||
with open(os.path.join(d, "gobang.toml"), "w") as f:
|
||||
f.write(cfg)
|
||||
return {".config/gobang/gobang.toml": cfg}
|
||||
|
||||
def env(self, model):
|
||||
_, key_env, _ = self._provider(model)
|
||||
if key_env is None:
|
||||
return {}
|
||||
key = os.environ.get(key_env)
|
||||
if not key:
|
||||
raise SystemExit(f"gobang: {key_env} is not set")
|
||||
return {key_env: key}
|
||||
|
||||
def argv(self, model, effort, prompt):
|
||||
return [self.binary, "run", "--json-events", "--in-place", "/work", "--state-dir", "/tmp/gobang",
|
||||
"--config", "/home/agent/.config/gobang/gobang.toml", "--task", prompt]
|
||||
|
||||
def parse(self, path):
|
||||
facts = {"tool_calls": 0, "usage": {"input_tokens": 0, "cached_input_tokens": 0, "output_tokens": 0}}
|
||||
for e in _jsonl(path):
|
||||
t, d = e.get("type"), e.get("data") or {}
|
||||
if t == "TOOL_REQUESTED":
|
||||
facts["tool_calls"] += 1
|
||||
elif t == "MODEL_RESPONDED":
|
||||
r = d.get("response") or {}
|
||||
u = r.get("usage") or {}
|
||||
facts["usage"]["input_tokens"] += u.get("input", 0)
|
||||
facts["usage"]["cached_input_tokens"] += u.get("cache_read", 0)
|
||||
facts["usage"]["output_tokens"] += u.get("output", 0)
|
||||
if r.get("model_reported"):
|
||||
facts["model"] = r["model_reported"]
|
||||
elif t == "SESSION_CREATED":
|
||||
facts["prompt_sha256"] = d.get("prompt_sha256")
|
||||
elif t == "SESSION_FINISHED":
|
||||
facts["gobang_state"] = d.get("state")
|
||||
facts["gobang_reason"] = d.get("reason")
|
||||
return facts
|
||||
|
||||
|
||||
# aji exit codes for gobang's run outcomes (AGENTS.md of the aji repository).
|
||||
_GOBANG_OUTCOME_CODE = {"accepted": 0, "returned": 0, "rejected": 1, "trapped": 4, "limit_exceeded": 5, "not_instantiated": 6, "blocked": 7}
|
||||
|
||||
|
||||
def gobang_events(transcript_path):
|
||||
"""(tool, arguments, result) for every tool call in a gobang transcript,
|
||||
and the test commands of the session."""
|
||||
calls, results, tests = {}, [], []
|
||||
for e in _jsonl(transcript_path):
|
||||
t, d = e.get("type"), e.get("data") or {}
|
||||
if t == "CONFIG_RESOLVED":
|
||||
tests = d.get("test_command_argv") or []
|
||||
elif t == "TOOL_REQUESTED":
|
||||
calls[d.get("call_id")] = (d.get("tool"), d.get("arguments") or "")
|
||||
elif t == "TOOL_COMPLETED" and d.get("call_id") in calls:
|
||||
tool, args = calls.pop(d.get("call_id"))
|
||||
results.append((tool, args, d.get("output") or ""))
|
||||
return results, tests
|
||||
|
||||
|
||||
AGENTS = {a.name: a for a in (Codex(), Claude(), OpenCode(), Gobang())}
|
||||
|
||||
|
||||
def available():
|
||||
@@ -317,12 +433,31 @@ def command_events(agent_name, transcript_path):
|
||||
m = re.match(r"Exit code (\d+)", text)
|
||||
code = int(m.group(1)) if m else (1 if b.get("is_error") else 0)
|
||||
out.append((pending.pop(b.get("tool_use_id")), code, text))
|
||||
elif agent_name == "gobang":
|
||||
continue # handled below from whole tool calls
|
||||
elif agent_name == "opencode":
|
||||
part = e.get("part") or {}
|
||||
if e.get("type") == "tool_use" and part.get("tool") == "bash":
|
||||
st = part.get("state") or {}
|
||||
meta = st.get("metadata") or {}
|
||||
out.append(((st.get("input") or {}).get("command", ""), meta.get("exit"), st.get("output") or meta.get("output") or ""))
|
||||
if agent_name == "gobang":
|
||||
# gobang's model gives no shell commands; its toolchain tools stand
|
||||
# for the commands they run, with aji's exit code for their outcome.
|
||||
results, tests = gobang_events(transcript_path)
|
||||
for tool, _, output in results:
|
||||
try:
|
||||
o = json.loads(output)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
outcome = o.get("outcome")
|
||||
if tool == "aji_check":
|
||||
out.append(("aji check", _GOBANG_OUTCOME_CODE.get(outcome, 2), output))
|
||||
elif tool == "aji_run":
|
||||
out.append(("aji run", _GOBANG_OUTCOME_CODE.get(outcome, 2), output))
|
||||
elif tool == "run_tests" and o.get("ok"):
|
||||
bad = (o.get("failed") or 0) + (o.get("errors") or 0)
|
||||
out.append(("aji run; " + "; ".join(tests), 0 if bad == 0 else 1, output))
|
||||
return out
|
||||
|
||||
|
||||
@@ -427,6 +562,7 @@ def run_native(task_dir, lang_name, agent_name, model, out_dir, effort=None, see
|
||||
if shutil.which("bwrap") is None:
|
||||
raise SystemExit("native runs need bubblewrap")
|
||||
ag = AGENTS[agent_name]
|
||||
agent_env = ag.env(model) # fails before anything is created when a key is missing
|
||||
task = task_mod.Task(task_dir)
|
||||
profile = languages.load(lang_name)
|
||||
lang = task.language(lang_name)
|
||||
@@ -467,7 +603,9 @@ def run_native(task_dir, lang_name, agent_name, model, out_dir, effort=None, see
|
||||
|
||||
message = PREAMBLE.format(language=profile["instructions"]) + agent.task_message(task, workspace)
|
||||
argv = ag.argv(model, effort, message)
|
||||
sb = sandbox_argv(workspace, home, binds, path_dirs, docs, profile.get("env", {}))
|
||||
env = dict(profile.get("env", {}))
|
||||
env.update(agent_env) # values never enter the run record
|
||||
sb = sandbox_argv(workspace, home, binds, path_dirs, docs, env)
|
||||
for src, dst in cred_binds:
|
||||
sb[sb.index("--chdir"):sb.index("--chdir")] = ["--bind", src, dst]
|
||||
if ag.netless_shell:
|
||||
|
||||
Reference in new issue
Block a user