|
| 1 | +--- |
| 2 | +name: kya |
| 3 | +description: Govern and review autonomous agents with veldt-kya (Know Your Agents) — risk-score an agent, run multi-judge consensus, detect configuration drift, and emit compliance evidence — then turn the result into a verdict that labnb's loop can act on. Use when a run needs a trust/authorization/policy check, not just a resource or metric check. |
| 4 | +--- |
| 5 | + |
| 6 | +# Know Your Agents (KYA) Governance Review |
| 7 | + |
| 8 | +Use this skill to answer a different question from "is the run fast?" (see [`duct`](../duct/SKILL.md)) or "is the metric improving within budget?" (see [`labnb`](../labnb/SKILL.md)): **is the agent authorized, policy-compliant, and uncompromised?** |
| 9 | + |
| 10 | +It wraps [`veldt-kya`](https://github.com/veldtlabs/veldt-kya) ("Know Your Agents", Apache-2.0), a governance SDK that risk-scores agents, runs consensus judges over their behavior, detects drift from an approved definition, and produces regulator-grade compliance evidence. |
| 11 | + |
| 12 | +This is the third review axis in this repo: `duct` = resource accounting, `labnb` = budget / experimental-validity accounting, `kya` = trust / authorization / compliance accounting. |
| 13 | + |
| 14 | +## When To Use |
| 15 | + |
| 16 | +- Before granting an agent a privileged action (writing outside scope, executing SQL, calling external services), score or consensus-check it first. |
| 17 | +- When a long-running labnb experiment should stop if the agent drifts from its approved configuration or trips a policy judge — not only when the metric stalls. |
| 18 | +- When a run touches regulated or PII-bearing data and needs auditable authorization evidence (GDPR, HIPAA, EU AI Act, and similar). |
| 19 | + |
| 20 | +Skip it for ordinary, low-stakes local iteration; governance has real cost (see Guardrails). |
| 21 | + |
| 22 | +## Install |
| 23 | + |
| 24 | +```bash |
| 25 | +pip install veldt-kya # Apache-2.0 |
| 26 | +``` |
| 27 | + |
| 28 | +`veldt-kya` is a heavier, pre-1.0 dependency (database, identity bindings, optional external judges). Keep it **optional** — it is never required by the `labnb` core. Install it only in environments that need governance. |
| 29 | + |
| 30 | +## Core Capabilities |
| 31 | + |
| 32 | +```python |
| 33 | +from kya import score_agent, normalize_agent_def |
| 34 | +from kya import canonical_hash, detect_drift |
| 35 | +from kya.scorer_orchestrator import check_consensus, register_available_adapters |
| 36 | +from kya import compliance_summary |
| 37 | +``` |
| 38 | + |
| 39 | +- **Pre-deployment scoring** — `score_agent(...)` returns an object with `score`, a severity `bucket` (e.g. `"critical"`), and per-factor `factors` (each with `.name` / `.delta`). |
| 40 | +- **Runtime consensus** — `check_consensus(...)` runs multiple judges in parallel and returns `consensus` (`OK` / `SPLIT` / `UNCLEAR` / `BREACH`), `per_dimension` scores (input_safety, safety, faithfulness), and per-`judges` detail. |
| 41 | +- **Drift detection** — `canonical_hash(definition)` plus `detect_drift(...)` flag unauthorized configuration changes against an approved baseline. |
| 42 | +- **Compliance evidence** — `compliance_summary(...)` emits model cards / breach-notification artifacts across many regimes. |
| 43 | + |
| 44 | +## Producing A labnb Governance Verdict |
| 45 | + |
| 46 | +`labnb`'s `monitor_slice.py check` can break a slice on a **governance** signal, but it stays dependency-free: it reads a small JSON **verdict file** rather than importing KYA. This skill's job is to run a governance check and write that verdict. |
| 47 | + |
| 48 | +Canonical verdict schema (all keys optional): |
| 49 | + |
| 50 | +```json |
| 51 | +{ |
| 52 | + "decision": "allow | warn | block", |
| 53 | + "trust_score": 0.0, |
| 54 | + "drift": false, |
| 55 | + "reasons": ["short human-readable reasons"] |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +Map a KYA result onto it, then write it with the bundled helper: |
| 60 | + |
| 61 | +```python |
| 62 | +from kya.scorer_orchestrator import check_consensus |
| 63 | +verdict = check_consensus(...) # consensus: OK | SPLIT | UNCLEAR | BREACH |
| 64 | +decision = "block" if verdict.consensus == "BREACH" else ( |
| 65 | + "warn" if verdict.consensus in ("SPLIT", "UNCLEAR") else "allow") |
| 66 | +``` |
| 67 | + |
| 68 | +```bash |
| 69 | +python skills/kya/scripts/write_verdict.py \ |
| 70 | + --output "$EXPERIMENT_DIR/artifacts/governance.json" \ |
| 71 | + --decision "$decision" \ |
| 72 | + --trust-score 0.41 \ |
| 73 | + --reason "consensus=BREACH on faithfulness judge" |
| 74 | +``` |
| 75 | + |
| 76 | +`write_verdict.py` is deterministic and tool-agnostic: it validates the fields and writes the canonical schema, so you can drive it from KYA, `detect_drift`, or any other governance source. |
| 77 | + |
| 78 | +## Feeding It Into The Loop |
| 79 | + |
| 80 | +Point `labnb`'s monitor at the verdict so a compromised or unauthorized slice breaks (with the highest break priority — governance outranks budget, engineering, and validity): |
| 81 | + |
| 82 | +```bash |
| 83 | +python skills/labnb/scripts/monitor_slice.py check \ |
| 84 | + --experiment-dir "$EXPERIMENT_DIR" \ |
| 85 | + --governance-file "$EXPERIMENT_DIR/artifacts/governance.json" \ |
| 86 | + --min-trust-score 0.6 --break-on-drift |
| 87 | +``` |
| 88 | + |
| 89 | +A `block` decision, a `trust_score` below `--min-trust-score`, or `drift: true` (with `--break-on-drift`) breaks the slice and moves the entry to `blocked`; a `warn` decision is advisory. This also fits `labnb`'s Action Gate: run the check before any write-bearing or privileged step. |
| 90 | + |
| 91 | +The gate fails closed: once `--governance-file` is set, if the verdict file is missing, unreadable, or malformed the monitor treats it as a `block`. So always write a verdict before the check — including a conservative one (e.g. `decision: "warn"` or `"block"`) when KYA or its judges are unavailable — rather than leaving the file absent. |
| 92 | + |
| 93 | +## Guardrails |
| 94 | + |
| 95 | +1. Respect any parent constitution, project policy, or task-level write constraint already in scope. |
| 96 | +2. Keep `veldt-kya` optional. Never make it a hard dependency of the `labnb` core or of offline CI; the verdict-file seam exists precisely so labnb stays dependency-free. |
| 97 | +3. Governance has cost. Consensus judging may call LLMs or external services (e.g. Fiddler, Presidio); count that time and spend against the same labnb budget, per labnb's budget policy. |
| 98 | +4. Handle a degraded/offline path: if KYA or its judges are unavailable, emit a conservative verdict (for example `decision: "warn"`) rather than silently treating the run as authorized. |
| 99 | +5. Treat the project as pre-1.0 and verify its behavior before relying on it for real compliance decisions; do not present its output as legal/regulatory advice. |
| 100 | +6. Do not send secrets or unminimized PII to external judges; use KYA's PII scanning and scrub before sharing. |
0 commit comments