> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenetlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent integration

> A self-contained spec for AI agents adding Tenet Guardrails to a harness — detection, integration, verification, in one page.

**This page is written for you, the model.** If you are running it as a prompt, your goal is to add Tenet Guardrails to the harness in front of you, then prove they work with the verification checklist at the end. Everything needed is on this page — no other docs required. Humans: paste this page (or its `.md` URL) into your coding agent's context, or copy the prompt below.

Add Tenet Guardrails to this codebase

Add Tenet Guardrails to this codebase. Goal: every agent tool call is judged for compliance risk before it runs (tool\_pre) and after it returns (tool\_post), failing closed for side-effectful tools. If the harness uses LangChain create\_agent, install tenet-langchain and add TenetJudgeMiddleware to the middleware list; otherwise install tenet-client and gate tool dispatch with the @judged decorator or evaluate\_phase(). Construct one TenetCloudJudgeClient per process with from\_env() — it reads TENET\_API\_KEY (a self-serve sk\_tenet\_ key; needs tenet-client>=0.7.2), or TENET\_CLIENT\_ID / TENET\_CLIENT\_SECRET if Tenet issued M2M credentials. If neither is set, stop and ask me for an API key from [https://platform.tenetlabs.com/keys](https://platform.tenetlabs.com/keys) — never sign up on my behalf. Call warmup() at startup — never hardcode credentials, never register the judge as a model-callable tool. Set surface per request to match the action being judged — resume\_triage for screening/filtering, job\_ad\_drafting for job ads, candidate\_ranking for ranking, interview\_question\_gen for interview questions, candidate\_outreach for candidate messages — never hardwire one surface for all traffic; map tool names to surfaces and fall back to resume\_triage for unmapped tools. Branch on the four decisions (allow, caveat, review, block): block and review must stop the tool; for review, ask me whether to hold the call or pause for a person with LangGraph interrupt() ([https://docs.tenetlabs.com/guides/hitl](https://docs.tenetlabs.com/guides/hitl.md)). Verify: a benign tool call succeeds; a resume search for "5+ years Python, must be under 30" does not run (it comes back as review) and the verdict's reason is shown; with credentials unset, side-effectful tools refuse to run; tools of different action kinds send different surfaces.

Or hand the whole page to Claude Code from the harness repo:

```bash theme={null}
claude "$(curl -fsSL https://docs.tenetlabs.com/agent-integration.md)"
```

## Decision procedure

1. **Is the harness LangChain (`create_agent` / `langchain>=1.2.13`)?** → Use `TenetJudgeMiddleware`. Install `tenet-langchain`.
2. **Is it Python but not LangChain?** → Use `@judged` on tool functions, or `evaluate()` at the dispatch choke point. Install `tenet-client`.
3. **Not Python?** → Call the HTTP API directly: `POST https://judge.tenetlabs.com/decide` with `Authorization: Bearer $TENET_API_KEY`. See [API Reference](https://docs.tenetlabs.com/api-reference/introduction.md).

## Invariants — do not violate

* **Never register the judge as a model-callable tool.** A model can choose not to call a tool; middleware, decorators, and dispatch-loop gates run unconditionally. A guardrail the model can skip is not a guardrail. Wire the judge *around* tools, never *as* one.
* **Fail closed for side effects.** If the judge is unreachable, tools that write, send, or post must not run. Catch `JudgeUnavailableError` and stop the call. Failing open is permitted only for read-only tools, and must be logged.
* **Construct one client per process**, at startup, then `warmup()`. Never construct per request.
* **Credentials come from env**: `TENET_API_KEY` (from [platform.tenetlabs.com](https://platform.tenetlabs.com)), or `TENET_CLIENT_ID` + `TENET_CLIENT_SECRET` if Tenet issued M2M credentials. Set one or the other, not both. Never hardcode, commit or log them. If neither is set, ask the user for a key.
* **Set `surface` per request, never per application.** The surface names the recruiting action being judged — `resume_triage` (screening/filtering), `job_ad_drafting`, `candidate_ranking`, `interview_question_gen`, `candidate_outreach` — and the judge reads it to frame the ask. Map tool names to surfaces; fall back to `resume_triage` (the default) for unmapped tools. Hardwiring one surface for all traffic is the canonical integration mistake — see [Surfaces](https://docs.tenetlabs.com/concepts/surfaces.md).
* **Populate `context.recruiter_prompt` with the user's verbatim ask** (required for full safety-pattern coverage) and `context.candidate_content` with the resume/candidate text whenever the action involves one (omitting it disables candidate-side protections). The SDK derives `recruiter_prompt` from a string `tool_input` automatically; dict inputs should carry the keys explicitly.
* **On tool phases, send the facts of the call — not its name.** Pass the arguments you're about to call with as `tool_input`, and what the tool requires (`tool_description`) and any lawful-basis facts in `context=`; the judge evaluates those. `tool_name` alone moves no verdict, and no caller-asserted field exempts a call — caller signals can tighten a guardrail, never loosen one. Say what the action is for — the role, the process stage, the consent basis — so the judge can evaluate it. See [Tool context](https://docs.tenetlabs.com/concepts/tool-context.md).
* **Field casing is snake\_case** on the wire and in the SDK (`tool_name`, `session_id`, `risk_labels`). Don't camelCase.
* **Show a clear message, never a stack trace.** Use the verdict's `reason` (the finding's evidence), else a fixed fallback string.
* **Pass `session_id` and `prior_user_turns`** when the harness is conversational — single-call judging misses multi-turn risk.

## Canonical integration (LangChain)

```python theme={null}
from langchain.agents import create_agent
from tenet_client import TenetCloudJudgeClient, JudgePolicy, JudgeAction
from tenet_langchain import TenetJudgeMiddleware

judge = TenetCloudJudgeClient.from_env()
judge.warmup()

policy = JudgePolicy(
    on_block=lambda ctx, v: JudgeAction.retry_nudge_from_verdict(v),
    # review: the default on_review lets the call proceed with a tenet_review
    # marker. To pause for a person, call interrupt() in on_review — /guides/hitl.
)

agent = create_agent(
    model=MODEL,
    tools=TOOLS,
    middleware=[TenetJudgeMiddleware(
        judge,
        policy=policy,
        check_user_messages=True,   # users type free-form requests
        send_history=True,          # multi-turn risk context
    )],
)
```

## Canonical integration (non-LangChain Python)

```python theme={null}
from tenet_client import JudgePolicy, TenetCloudJudgeClient

judge = TenetCloudJudgeClient.from_env()
judge.warmup()
policy = JudgePolicy()

# Tool → surface: tells the judge which recruiting action it's judging. Adapt
# the keys to this harness's tools; unmapped tools get the default surface.
SURFACE_BY_TOOL = {
    "search_resumes": "resume_triage",
    "draft_job_ad": "job_ad_drafting",
    "rank_candidates": "candidate_ranking",
    "generate_interview_questions": "interview_question_gen",
    "draft_outreach_email": "candidate_outreach",
}

def gate_tool_call(tool_name: str, tool_input: dict, session_id: str,
                   prior_user_turns: list[str]) -> str | None:
    """Call before every tool dispatch. None = run the tool; str = don't, show this instead."""
    verdict, _ = judge.evaluate_phase(
        policy=policy,
        phase="tool_pre", tool_name=tool_name, tool_input=tool_input,
        surface=SURFACE_BY_TOOL.get(tool_name, "resume_triage"),
        session_id=session_id, prior_user_turns=prior_user_turns,
    )
    if verdict.decision == "block":  # also what you get if the judge is unreachable
        return verdict.reason or "Blocked by compliance check."
    if verdict.decision == "review":
        # Pause for a person here — see /guides/hitl. Until they approve, don't run the tool.
        return f"Held for human review: {verdict.reason}"
    return None  # allow, or caveat (verdict.caveat carries an advisory note)
```

`review` is where a human comes in. This harness holds the call; a LangGraph harness can pause the run with `interrupt()` and resume on approval — see [Human-in-the-loop review](https://docs.tenetlabs.com/guides/hitl.md).

Mirror the same call with `phase="tool_post"` and `tool_output=` after execution when tool output re-enters model context.

## Verification checklist

After integrating, confirm each item by running the harness:

* [ ] A benign tool call succeeds and is judged (`latency_ms` on the response shows the added time).
* [ ] A violating call doesn't run — test input: a resume search for `"5+ years Python, must be under 30"` comes back as `review` (`age` guard, `tool_pre`) and the tool is not executed.
* [ ] A `review` either holds the call or pauses for a person, per the harness's choice — never proceeds silently.
* [ ] The message shown to the model/user comes from the verdict's `reason`, not a stack trace.
* [ ] With the credential unset or wrong (`TENET_API_KEY`, or `TENET_CLIENT_SECRET` for M2M), side-effectful tools refuse to run (fail-closed path works).
* [ ] Tools of different action kinds send different `surface` values — a job-ad drafting call must not go out as `resume_triage`. Grep the integration for a single hardwired `surface` and fix it if found.
* [ ] `context.recruiter_prompt` carries the user's actual ask on every judged call; `context.candidate_content` is populated when the action involves a resume.
* [ ] Tool-phase calls carry `tool_input` (and `tool_description` in `context=` where the tool has legal or policy preconditions) — routine tool calls routing to a human is the symptom of omitting them.
* [ ] `session_id` is stable across one conversation and changes across conversations.
* [ ] No credentials appear in code, logs, or version control.
* [ ] The test calls are listed on **Decision traces** at [platform.tenetlabs.com](https://platform.tenetlabs.com), under the account that owns the key. Ask the user to check; don't sign in on their behalf.

## Key facts

| Fact | Value |
| - | - |
| Base URL | `https://judge.tenetlabs.com` |
| Auth | `Authorization: Bearer <key>` with an API key from [platform.tenetlabs.com](https://platform.tenetlabs.com), or an M2M token (audience `https://sdk.tenetlabs.com`) |
| Domains | `eeo`, `pii`, `safety` bundle (disclosure + injection). Which domains enforce depends on your plan. PII detection always runs, and the spans it detects are redacted before any model reads the request — within a [documented scope](https://docs.tenetlabs.com/concepts/multi-verdict.md#pii-redaction-posture). See [Multi-verdict](https://docs.tenetlabs.com/concepts/multi-verdict.md) |
| Phases | `agent_input`, `tool_pre`, `tool_post`, `agent_output` |
| Surfaces | `resume_triage` · `job_ad_drafting` · `candidate_ranking` · `interview_question_gen` · `candidate_outreach` — per request, by current action ([Surfaces](https://docs.tenetlabs.com/concepts/surfaces.md)) |
| Decisions | `allow` · `caveat` · `review` · `block` |
| Severity | `none` \< `info` \< `low` \< `medium` \< `high` \< `critical` |
| SDK timeout | 3.0s default. Guard hits make no model call; other requests wait on one judge call — size from `latency_ms` |
| Failure mode | Fail-closed: `JudgeUnavailableError`, never silent allow |
| Packages | `tenet-client` (PyPI) · `tenet-langchain` (PyPI, needs `langchain>=1.2.13`) |
| These docs, machine-readable | `/llms.txt` (index) · `/llms-full.txt` (full text) · any page + `.md` · MCP server at `/mcp` |

## Links

* [Quickstart](https://docs.tenetlabs.com/quickstart.md) — human-paced version of this page
* [Policies](https://docs.tenetlabs.com/guides/policies.md) — full action vocabulary
* [API Reference](https://docs.tenetlabs.com/api-reference/introduction.md) — wire schemas for non-Python integration


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.