# Put a HANRIA check before an agent tool

These three runnable snippets call `https://check.hanria.ai/v1/check` before a tool can run. HANRIA advises. The wrapper, graph route, or hook is what refuses the tool call. A mandate is only as good as the hook that consults it.

Every integration fails closed: `deny`, `escalate`, `error`, an invalid response, and a failed request all stay away from execution. Replace the example mandate and action mapping with rules and fields that match your application.

## OpenAI Agents SDK

Pinned package: `openai-agents==0.23.1`.

```sh
uv run --with openai-agents==0.23.1 python openai_agents.py
```

`openai_agents.py` constructs an `Agent` with a function tool. Each wrapped tool passes the operation it will actually perform, and the wrapper refuses to execute it unless HANRIA returns `permit`. On `deny`, `escalate`, or `error`, it returns a refusal string naming the outcome and reason so the model is not invited to retry blindly.

## LangGraph

Pinned package: `langgraph==1.2.12`.

```sh
uv run --with langgraph==1.2.12 python langgraph.py
```

`langgraph.py` constructs a graph without invoking it or making a live request. When your application invokes the graph, its check node sends `deny`, `escalate`, `error`, and request failures to a refusal node instead of the execution node.

## Claude Agent SDK

Pinned packages: `@anthropic-ai/claude-agent-sdk@0.3.287` and `tsx@4.20.6`.

```sh
npm install --no-save --save-exact @anthropic-ai/claude-agent-sdk@0.3.287 tsx@4.20.6
npx tsx claude_agent_sdk.ts
```

`claude_agent_sdk.ts` constructs a `PreToolUse` hook matcher for the SDK. On `permit` the callback returns no permission decision, leaving the SDK's normal permission flow in place. Every other result returns `deny` before the tool runs. The HTTP check times out after 10 seconds and fails closed.

## Data handling

The hosted check evaluates requests in memory and does not store request content. It keeps daily aggregate counts. Do not send secrets, personal data, or confidential policies. See https://check.hanria.ai/privacy.
