diff --git a/CHANGELOG.md b/CHANGELOG.md index 637e257..a9270c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ trace, study, receipt, API and database schema versions. Markdown, and HTML. Per-attempt timing identifies the clock source. Paired summaries show medians and coverage for completed, correct attempts. Latency gates continue to use the trace measurement. +- Guided comparisons can require a trusted local Python verifier selected by + the developer. The frozen session binds the script and timeout, and both + sides must pass the verifier and their built-in quality checks. ## [0.2.3] - 2026-11-17 diff --git a/agentloop/improvement.py b/agentloop/improvement.py index ba65a67..18a9140 100644 --- a/agentloop/improvement.py +++ b/agentloop/improvement.py @@ -17,6 +17,7 @@ from agentloop.experiment_artifacts import local_path, read_json, write_once from agentloop.experiment_types import fingerprint from agentloop.findings import build_diagnosis +from agentloop.improvement_verifier import DEFAULT_TIMEOUT, LocalVerifier, resume_verifier from agentloop.interventions import build_intervention from agentloop.quality import build_quality_report, validate_quality_fixtures from agentloop.repetitions import add_repetition_findings @@ -389,15 +390,25 @@ def _completed(manifest, traces): return {key: trace for key, trace in traces.items() if key in done} -def _quality(task, baseline, candidate): - return build_quality_report( - [ +def _quality(task, baseline, candidate, verification=None): + fixtures = [ + { + "id": task["id"], + "expected": task["expected"], + "scorer": task.get("scorer", {"type": "exact_match"}), + } + ] + if verification is not None: + fixtures.append( { - "id": task["id"], - "expected": task["expected"], - "scorer": task.get("scorer", {"type": "exact_match"}), + "id": f"{task['id']}:local-verifier", + "expected": True, + "baseline_output": verification["baseline"]["passed"], + "candidate_output": verification["candidate"]["passed"], } - ], + ) + return build_quality_report( + fixtures, baseline_trace=baseline, candidate_trace=candidate, min_score=1.0, @@ -413,9 +424,12 @@ def start( objective="latency", minimum_improvement=0, decision="per_pair", + verifier=None, + verifier_timeout=DEFAULT_TIMEOUT, ): workload = read_workload(workload_path) manifest, traces = read_capture(baseline_path, workload) + verifier = LocalVerifier.read(verifier, verifier_timeout) if verifier is not None else None require(objective in {"latency", "cost"}, "Objective must be latency or cost") decision = decision.replace("-", "_") if isinstance(decision, str) else decision require(decision in DECISIONS, "Decision must be per-pair or aggregate") @@ -473,6 +487,13 @@ def start( else [], } ) + if verifier is not None: + cases[-1]["baseline_verifier"] = verifier.check( + task, + repetition, + trace, + usable=row["status"] == "completed" and trace is not None and _trace_usable(trace), + ) specification = { "schema_version": VERSION, "frozen_at": now(), @@ -484,6 +505,8 @@ def start( "cases": cases, "baseline_capture": manifest, } + if verifier is not None: + specification["verifier"] = verifier.declaration() write_once( root, "session.json", @@ -647,7 +670,7 @@ def _aggregate_decision(rows, objective, gates): } -def finish(session_path, candidate_path, root, *, change): +def finish(session_path, candidate_path, root, *, change, verifier=None): session_path = Path(session_path).resolve() saved = load_json(session_path) specification = saved["specification"] @@ -657,6 +680,7 @@ def finish(session_path, candidate_path, root, *, change): ) require(specification.get("schema_version") == VERSION, "Unsupported frozen session version") workload = validate_workload(specification["workload"]) + verifier = resume_verifier(specification.get("verifier"), verifier) require(specification.get("objective") in {"latency", "cost"}, "Unsupported frozen objective") # Sessions frozen before 0.2.3 have no decision field and keep per-pair judgment. decision = specification.get("decision", "per_pair") @@ -791,6 +815,28 @@ def finish(session_path, candidate_path, root, *, change): frozen_baseline_status=case["capture_status"], control_ran_first=baseline_row.get("order") == 0, ) + verification = None + if verifier is not None: + verification = { + side: verifier.check( + task, + key[1], + trace, + usable=( + trace is not None + and row[f"{side}_status"] == "completed" + and _trace_usable(trace) + ), + ) + for side, trace in (("baseline", baseline), ("candidate", candidate)) + } + row["verifier"] = verification + for side, result in verification.items(): + if not result["passed"]: + side_label = label if side == "baseline" else "Candidate" + row["reasons"].append( + f"{side_label} local verification failed: {result['detail']}" + ) if baseline is None or candidate is None: row["reasons"].append(f"A planned {label.lower()} or candidate trace is unavailable") for side, status, diagnostic in ( @@ -802,7 +848,7 @@ def finish(session_path, candidate_path, root, *, change): f"{side} attempt is {status}. {diagnostic or 'Recapture this task with --show-runner-output to inspect the failure.'}" ) else: - quality = _quality(task, baseline, candidate) + quality = _quality(task, baseline, candidate, verification) replay = build_replay_report(baseline, candidate, gates=gates, quality_report=quality) completed = baseline_status == candidate_row["status"] == "completed" and all( _trace_usable(trace) for trace in (baseline, candidate) @@ -819,12 +865,12 @@ def finish(session_path, candidate_path, root, *, change): row["reasons"].append( f"{label} and candidate must both pass the declared quality checks" ) - for result in quality["cases"]: - for side in ("baseline", "candidate"): - if not result[side]["passed"]: - row["reasons"].append( - f"{label if side == 'baseline' else 'Candidate'} answer failed the declared {task.get('scorer', {}).get('type', 'exact_match')} criterion: {result[side]['detail']}" - ) + fixture_result = quality["cases"][0] + for side in ("baseline", "candidate"): + if not fixture_result[side]["passed"]: + row["reasons"].append( + f"{label if side == 'baseline' else 'Candidate'} answer failed the declared {task.get('scorer', {}).get('type', 'exact_match')} criterion: {fixture_result[side]['detail']}" + ) # Aggregate decisions judge speed and cost across all pairs after # this loop; every other gate still applies to each pair. judged = [ @@ -894,10 +940,10 @@ def finish(session_path, candidate_path, root, *, change): source_trace_hash=fingerprint(trace.to_dict()), ) if row["quality"]: - result = row["quality"]["cases"][0][side] + quality_cases = row["quality"]["cases"] viewed["metadata"].update( - quality_score=result["score"], - success=result["passed"] + quality_score=row["quality"][f"{side}_score"], + success=all(result[side]["passed"] for result in quality_cases) and _trace_usable(trace) and row[f"{side}_status"] == "completed", ) @@ -954,6 +1000,8 @@ def finish(session_path, candidate_path, root, *, change): "timing_summary": _timing_summary(rows), "study": study, } + if verifier is not None: + report["verifier"] = verifier.declaration() from agentloop.improvement_report import export_report export_report(root, report) diff --git a/agentloop/improvement_cli.py b/agentloop/improvement_cli.py index c2d6210..3aaac7e 100644 --- a/agentloop/improvement_cli.py +++ b/agentloop/improvement_cli.py @@ -11,6 +11,7 @@ from agentloop import improvement from agentloop.improvement_init import initialize, project_tasks from agentloop.improvement_report import comparison_label, decision_objective, timing_summary_rows +from agentloop.improvement_verifier import DEFAULT_TIMEOUT improve_app = typer.Typer( help="Capture fixed tasks, review baseline findings, and verify an applied change." @@ -108,6 +109,13 @@ def start_command( help="per-pair requires every pair to improve; aggregate judges the median " "paired improvement for noisy agents. Correctness is checked per pair in both.", ), + verifier: Path | None = typer.Option(None, help="Explicit trusted local Python verifier file."), + verifier_timeout: float = typer.Option( + DEFAULT_TIMEOUT, + min=0.01, + max=3600, + help="Seconds per verifier execution, frozen in the session.", + ), ): """Freeze task checks and original findings before editing the agent.""" try: @@ -119,6 +127,8 @@ def start_command( objective=objective, minimum_improvement=minimum_improvement, decision=decision, + verifier=verifier, + verifier_timeout=verifier_timeout, ) except (OSError, ValueError, TypeError, KeyError) as exc: raise typer.BadParameter(str(exc)) from exc @@ -130,6 +140,12 @@ def start_command( markup=False, ) console.print(f"Frozen session written to {out / 'session.json'}", markup=False) + if verifier is not None: + passed = sum(case["baseline_verifier"]["passed"] for case in specification["cases"]) + total = len(specification["cases"]) + console.print( + f"Local verifier passed on {passed} of {total} baseline attempts.", markup=False + ) @improve_app.command("finish") @@ -138,10 +154,13 @@ def finish_command( candidate: Path = typer.Option(..., help="Candidate capture.json recorded after start."), change: str = typer.Option(..., help="Describe the change you applied."), out: Path = typer.Option(..., help="Fresh report directory."), + verifier: Path | None = typer.Option( + None, help="Explicit trusted Python verifier matching the frozen session." + ), ): """Compare every planned attempt and write JSON, Markdown and HTML results.""" try: - report = improvement.finish(session, candidate, out, change=change) + report = improvement.finish(session, candidate, out, change=change, verifier=verifier) except (OSError, ValueError, TypeError, KeyError) as exc: raise typer.BadParameter(str(exc)) from exc verdict = report["decision"] diff --git a/agentloop/improvement_report.py b/agentloop/improvement_report.py index 26a240c..a23191b 100644 --- a/agentloop/improvement_report.py +++ b/agentloop/improvement_report.py @@ -43,10 +43,14 @@ def plan_markdown(specification): else "The frozen decision requires every pair to improve the objective.", "", ] + if specification.get("verifier"): + lines.extend([_verifier_scope(specification["verifier"]), ""]) for case in specification["cases"]: lines.extend( [f"## {markdown_heading(case['task_id'])}, repetition {case['repetition']}", ""] ) + if verification := case.get("baseline_verifier"): + lines.extend([f"Local verification: {markdown_text(verification['detail'])}.", ""]) diagnosis = case["diagnosis"] quality = case.get("baseline_quality") lines.extend( @@ -244,6 +248,8 @@ def _measurement_rows(row): measurements.extend( [label, *(_metric(replay[side], key) for side in sides)] for label, key in _MEASUREMENTS ) + if verification := row.get("verifier"): + measurements.append(["Local verifier", *(verification[side]["detail"] for side in sides)]) return measurements @@ -280,6 +286,13 @@ def decision_objective(verdict): return "trace latency" if verdict["objective"] == "latency" else verdict["objective"] +def _verifier_scope(verifier): + return ( + f"Local verifier SHA-256 {verifier['sha256']}. Each execution has a " + f"{verifier['timeout_s']:g}-second timeout. Both sides must pass." + ) + + def _decision_lines(report): verdict = report.get("decision") or {"mode": "per_pair"} if verdict["mode"] != "aggregate": @@ -336,6 +349,8 @@ def report_markdown(report): "", ] ) + if report.get("verifier"): + lines.extend([_verifier_scope(report["verifier"]), ""]) timing_rows = timing_summary_rows(report) if timing_rows: headers = _timing_headers(comparison) @@ -407,6 +422,8 @@ def export_report(root, report): sections.append( '

This comparison includes synthetic evidence. Results apply to the supplied fixtures.

' ) + if report.get("verifier"): + sections.append(f"

{_text(_verifier_scope(report['verifier']))}

") timing_rows = timing_summary_rows(report) if timing_rows: sections.extend( diff --git a/agentloop/improvement_verifier.py b/agentloop/improvement_verifier.py new file mode 100644 index 0000000..d5d1506 --- /dev/null +++ b/agentloop/improvement_verifier.py @@ -0,0 +1,95 @@ +"""Explicit local verifier snapshots for guided comparisons.""" + +from __future__ import annotations + +import hashlib +import math +import sys +from dataclasses import dataclass, field +from pathlib import Path +from tempfile import TemporaryDirectory + +from agentloop.quality import _MISSING, _trace_output + +DEFAULT_TIMEOUT = 30.0 +_MAX_SOURCE_BYTES = 1024 * 1024 + + +@dataclass(frozen=True) +class LocalVerifier: + source: bytes = field(repr=False) + sha256: str + timeout_s: float + + @classmethod + def read(cls, path, timeout_s): + if ( + type(timeout_s) not in (int, float) + or not 0 < timeout_s <= 3600 + or not math.isfinite(timeout_s) + ): + raise ValueError("Verifier timeout must be positive and at most 3600 seconds") + path = Path(path) + if not path.is_file() or path.suffix.lower() != ".py": + raise ValueError("Select an existing Python verifier file with --verifier") + with path.open("rb") as handle: + source = handle.read(_MAX_SOURCE_BYTES + 1) + if not source or len(source) > _MAX_SOURCE_BYTES: + raise ValueError("Verifier source must be between 1 byte and 1 MiB") + return cls(source, hashlib.sha256(source).hexdigest(), float(timeout_s)) + + def declaration(self): + return {"sha256": self.sha256, "timeout_s": self.timeout_s} + + def check(self, task, repetition, trace, *, usable): + if not usable: + return { + "status": "unavailable", + "passed": False, + "detail": "Attempt has no usable trace", + } + output = _trace_output(trace) + if output is _MISSING: + return { + "status": "unavailable", + "passed": False, + "detail": "Trace has no output for verification", + } + from agentloop.improvement import _invoke + + request = { + "schema_version": "1.0", + "task_id": task["id"], + "repetition": repetition, + "input": task["input"], + "output": output, + } + with TemporaryDirectory(prefix="agentloop-verifier-") as directory: + # Execute the exact checked bytes even if the selected file changes. + snapshot = Path(directory) / "verifier.py" + snapshot.write_bytes(self.source) + result = _invoke([sys.executable, "-I", str(snapshot)], request, self.timeout_s) + state = result["status"] + detail = { + "completed": "Verifier exited successfully", + "failed": f"Verifier exited with code {result['exit_code']}", + "timed_out": f"Verifier exceeded its {self.timeout_s:g}-second timeout", + "cancelled": "Verifier was interrupted", + "runner_error": "Could not start the verifier", + }[state] + return {"status": state, "passed": state == "completed", "detail": detail} + + +def resume_verifier(declaration, path): + if declaration is None and path is None: + return None + if path is None: + raise ValueError("This session requires an explicit --verifier matching the frozen source") + if not isinstance(declaration, dict) or set(declaration) != {"sha256", "timeout_s"}: + raise ValueError("The session must freeze the local verifier in improve start") + verifier = LocalVerifier.read(path, declaration["timeout_s"]) + if verifier.declaration() != declaration: + raise ValueError( + "Verifier source changed since improve start. Freeze a new session to change it" + ) + return verifier diff --git a/docs/GUIDED_OPTIMIZATION.md b/docs/GUIDED_OPTIMIZATION.md index b7fcb5f..3ffe10b 100644 --- a/docs/GUIDED_OPTIMIZATION.md +++ b/docs/GUIDED_OPTIMIZATION.md @@ -252,6 +252,47 @@ baseline. The control must pass the same quality checks. Intervention records link the control's matching findings. The report states which comparison basis it used, and each case records whether the control ran first. +## Run an existing correctness check + +Builds after 0.2.3 can require a trusted local Python verifier alongside the +task's built-in scorer. Use the built-in scorer for basic output shape and the +verifier for application behavior, such as checking a code change against your +tests or checking that a retrieval answer cites the expected document. + +Save this simple citation check as `verify_citation.py`. It assumes the task +input names the expected source and the trace output includes its citation. + +```python +import json +import sys + +request = json.load(sys.stdin) +output = request["output"] +passed = isinstance(output, dict) and output.get("source") == request["input"]["source"] +raise SystemExit(0 if passed else 1) +``` + +```bash +agentloop improve start --tasks tasks.json --baseline runs/baseline/capture.json --out runs/optimization --verifier verify_citation.py +agentloop improve finish --session runs/optimization/session.json --candidate runs/candidate/capture.json --change "Reuse one lookup per request" --out runs/results --verifier verify_citation.py +``` + +Capture the candidate after `start`, as usual. The verifier receives one JSON +object on stdin with `schema_version`, `task_id`, zero-based `repetition`, +`input`, and the recorded `output`. It can call your own test code. Exit zero +means pass. Nonzero exit, timeout, cancellation, or unavailable output fails +verification. Output from the verifier process is discarded. Reports show the +status and the exit code or timeout reason. + +`start` checks baseline outputs and freezes the entry script's SHA-256 and +`--verifier-timeout` (30 seconds by default). `finish` requires explicit +selection of matching source and rechecks the comparison baseline or control +and the candidate. The task manifest and session metadata contain only data. +The verifier runs with your account's permissions and working directory using +the AgentLoop Python environment. Pin the test fixtures and dependencies +separately. Their contents are outside the entry-script hash. Verification +runs after capture, outside trace and runner timing. + ## Failures, evidence and execution `capture` retains every planned attempt, including failed, timed-out, cancelled, diff --git a/scripts/smoke_guided_wheel.py b/scripts/smoke_guided_wheel.py index 6e32fc4..75f323d 100644 --- a/scripts/smoke_guided_wheel.py +++ b/scripts/smoke_guided_wheel.py @@ -112,6 +112,11 @@ def capture(mode, expected=0): ) capture("baseline") + verifier = root / "verify.py" + verifier.write_text( + 'import json, sys\nraise SystemExit(0 if json.load(sys.stdin)["output"] == "correct" else 1)\n', + encoding="utf-8", + ) for objective in ("latency", "cost"): cli( "improve", @@ -124,6 +129,7 @@ def capture(mode, expected=0): objective, "--out", root / ("session-" + objective), + *(["--verifier", verifier] if objective == "latency" else []), ) for mode in ("candidate", "wrong", "incomplete", "missing-usage", "cancelled"): capture(mode, 1 if mode == "cancelled" else 0) @@ -138,6 +144,8 @@ def capture(mode, expected=0): "Synthetic fixture comparison", "--out", root / ("report-" + mode), + "--verifier", + verifier, expected=0 if mode in {"candidate", "missing-usage"} else 1, ) report = json.loads((root / ("report-" + mode) / "report.json").read_text(encoding="utf-8")) @@ -148,6 +156,9 @@ def capture(mode, expected=0): if not (root / ("report-" + mode) / "report.html").is_file(): raise RuntimeError("Installed guided HTML report missing") timing = report["cases"][0]["timing"]["candidate"] + verified = report["cases"][0]["verifier"]["candidate"] + if verified["passed"] is not (mode in {"candidate", "missing-usage"}): + raise RuntimeError("Installed guided local verifier lost its outcome") if timing["runner_clock"] != "monotonic" or timing["runner_elapsed_ms"] <= 0: raise RuntimeError("Installed guided capture lost process timing") if report["timing_summary"]["runner_elapsed_ms"]["paired_count"] != int(report["passed"]): diff --git a/tests/test_guided_verifier.py b/tests/test_guided_verifier.py new file mode 100644 index 0000000..d11c2e9 --- /dev/null +++ b/tests/test_guided_verifier.py @@ -0,0 +1,169 @@ +from __future__ import annotations + +import json +import sys + +import pytest +from typer.testing import CliRunner + +from agentloop.entrypoint import app +from agentloop.experiment_types import fingerprint +from agentloop.improvement import capture, finish, start +from agentloop.improvement_verifier import LocalVerifier +from agentloop.tracer import AgentTrace + + +@pytest.fixture +def study(tmp_path): + tasks = tmp_path / "tasks.json" + tasks.write_text( + json.dumps( + { + "schema_version": "1.0", + "name": "Source attribution", + "tasks": [ + { + "id": "one", + "input": {"source": "guide.md"}, + "expected": {"answer": "yes"}, + "scorer": {"type": "json_subset"}, + } + ], + } + ), + encoding="utf-8", + ) + runner = tmp_path / "runner.py" + runner.write_text( + """import json,sys +from agentloop.tracer import AgentTrace +request = json.load(sys.stdin) +mode = sys.argv[1] +trace = AgentTrace("example", started_at="2026-01-01T00:00:00+00:00", + ended_at="2026-01-01T00:00:00.080+00:00", elapsed_ms=80 if mode == "baseline" else 10, + metadata={"synthetic": True, "output": {"answer": "yes", "source": "wrong.md" if mode == "wrong" else request["input"]["source"]}}) +trace.export_json(request["trace_path"]) +""", + encoding="utf-8", + ) + verifier = tmp_path / "verify.py" + verifier.write_text( + """import json,sys +request = json.load(sys.stdin) +assert set(request) == {"schema_version", "task_id", "repetition", "input", "output"} +assert request["output"]["source"] == request["input"]["source"] +""", + encoding="utf-8", + ) + capture(tasks, tmp_path / "baseline", [sys.executable, str(runner), "baseline"]) + return tasks, runner, verifier + + +@pytest.mark.parametrize("mode,accepted", [("good", True), ("wrong", False)]) +def test_cli_verifies_both_sides_and_rejects_a_faster_wrong_source(tmp_path, study, mode, accepted): + tasks, runner, verifier = study + cli = CliRunner() + frozen = cli.invoke( + app, + [ + "improve", + "start", + "--tasks", + str(tasks), + "--baseline", + str(tmp_path / "baseline/capture.json"), + "--out", + str(tmp_path / "session"), + "--verifier", + str(verifier), + ], + ) + assert frozen.exit_code == 0, frozen.output + assert "Local verifier passed on 1 of 1 baseline attempts" in frozen.output + capture( + tasks, + tmp_path / "candidate", + [sys.executable, str(runner), mode], + control=[sys.executable, str(runner), "baseline"], + ) + result = cli.invoke( + app, + [ + "improve", + "finish", + "--session", + str(tmp_path / "session/session.json"), + "--candidate", + str(tmp_path / "candidate/capture.json"), + "--change", + "Recorded change", + "--out", + str(tmp_path / "results"), + "--verifier", + str(verifier), + ], + ) + assert result.exit_code == (0 if accepted else 1), result.output + report = json.loads((tmp_path / "results/report.json").read_bytes()) + assert report["passed"] is accepted + [case] = report["cases"] + assert case["verifier"]["baseline"]["passed"] is True + assert case["verifier"]["candidate"]["passed"] is accepted + assert case["quality"]["cases"][0]["passed"] is True + assert case["quality"]["cases"][1]["passed"] is accepted + assert case["replay"]["deltas"]["latency_improvement_pct"] == 87.5 + assert case["timing"]["eligible"] is accepted + if not accepted: + assert "Candidate local verification failed" in result.output + html = (tmp_path / "results/report.html").read_text(encoding="utf-8") + assert "Local verifier SHA-256" in html and "Local verifier" in html + + +def test_saved_session_cannot_authorize_or_change_a_verifier(tmp_path, study): + tasks, _, verifier = study + path = tmp_path / "session/session.json" + start(tasks, tmp_path / "baseline/capture.json", path.parent, verifier=verifier) + original = verifier.read_bytes() + with pytest.raises(ValueError, match="explicit --verifier"): + finish(path, tmp_path / "unused.json", tmp_path / "results", change="Missing selection") + verifier.write_bytes(original + b"\n# Changed after start\n") + with pytest.raises(ValueError, match="Verifier source changed"): + finish( + path, + tmp_path / "unused.json", + tmp_path / "results", + change="Changed verifier", + verifier=verifier, + ) + saved = json.loads(path.read_bytes()) + saved["specification"]["verifier"]["script"] = str(verifier) + saved["session_hash"] = fingerprint(saved["specification"]) + path.write_text(json.dumps(saved), encoding="utf-8") + with pytest.raises(ValueError, match="explicit --verifier"): + finish(path, tmp_path / "unused.json", tmp_path / "results", change="Untrusted path") + assert not (tmp_path / "results").exists() + + +def test_verifier_uses_checked_bytes_and_fails_on_timeout(tmp_path): + verifier = tmp_path / "verify.py" + verifier.write_text("import time\ntime.sleep(60)\n", encoding="utf-8") + snapshot = LocalVerifier.read(verifier, 0.2) + verifier.write_text("raise SystemExit(0)\n", encoding="utf-8") + trace = AgentTrace("fixture", metadata={"output": {"value": 1}}) + result = snapshot.check({"id": "one", "input": None}, 0, trace, usable=True) + assert result["status"] == "timed_out" and result["passed"] is False + assert "timeout" in result["detail"] + + +def test_missing_output_never_reaches_verifier(tmp_path): + marker = tmp_path / "marker" + verifier = tmp_path / "verify.py" + verifier.write_text( + f"from pathlib import Path\nPath({str(marker)!r}).touch()\n", encoding="utf-8" + ) + trace = AgentTrace("fixture", metadata={"output_unavailable": True, "output": 1}) + result = LocalVerifier.read(verifier, 30).check( + {"id": "one", "input": None}, 0, trace, usable=True + ) + assert result["status"] == "unavailable" and result["passed"] is False + assert not marker.exists()