--- name: intentrax-integrate-agent-actions description: >- Use when the user asks to add Intentrax, add proof or audit evidence to agent actions, find the risky or consequential things their agent or LLM tool calls do, or wire admission, execution evidence, and verification into an existing codebase. Walks through discovering consequential agent actions, proposing an integration plan for the user to approve, and implementing admit → execute → verify wrappers with the Intentrax SDK — without bypassing policy, signing anything, or calling execute without explicit approval. license: Apache-2.0 --- # Integrate Intentrax into an agent codebase Work in three phases, with an explicit stop for user approval between phase 2 and phase 3. Read `intentrax-execution-assurance` first if you have not already — it defines what a proof does and does not establish. ## Phase 1 — Discover consequential agent actions (read-only) Find every place where an agent, LLM tool call, or automated workflow causes a side effect. Search, do not guess. **Start with the scan.** Run it from the repository root: ```bash npx @intentrax/sdk scan --json ``` It needs SDK 1.8.0 or later. It is static and local: it reads files only, never imports or runs the project's code, makes no network call, and needs no key. It lists the actions an agent can reach (MCP configs and servers, OpenAI/Anthropic tool definitions, LangChain/LangGraph, Vercel AI SDK, shell tools), each with a heuristic classification and its reasons, and prints one line per finding: - `EXPOSED`: a consequential action reachable with a credential whose name suggests broad reach, or one credential shared by read and severe tools. - `UNGATED`: a consequential action with no gate or approval step in front of it. - `SELF-REPORTED`: a consequential action that reports success without reading the result back. Exit code 0 means no findings, 20 means findings, 2 means a scan error. It names credentials only by variable or config name and file location; never print or copy a credential value yourself either. The scan is a starting list, not the answer. It is a heuristic over names and can miss actions (dynamic registration, code outside the repository, dispatchers in another file) or misclassify them. Then search with the patterns in [references/discovery-patterns.md](references/discovery-patterns.md), read the code behind every scan finding, and add what the scan missed. If the SDK is older than 1.8.0 or `npx` is unavailable, skip the scan and search. Each scan finding recommends least privilege **before** any Intentrax step: narrow or split the credential first, then gate the action. Keep that order in your plan. For each candidate, record: | Field | Example | | --- | --- | | Location | `src/agent/tools/refund.ts:42` | | Trigger | LLM tool call `issue_refund` (agent-initiated) | | Effect | Moves money via Stripe `refunds.create` | | Reversibility | Hard to reverse | | Who might dispute it | Customer, payment processor, auditor | | Score | Count of: consequential domain, agent-initiated, untrusted verifier, hard to reverse | Only actions scoring **2 or more** are candidates. Reads, search, drafting, UI state, and trivially undoable actions are out of scope — list them as "excluded" so the user sees you considered them. ### Report-only mode If the user asks for an assessment, an audit, or "where are we exposed", stop after phase 1 and write a report instead of changing code. Write it to `INTENTRAX_ASSURANCE_GAPS.md` (or show it in chat if they prefer) with: 1. **Scan result** — the `npx @intentrax/sdk scan` finding lines (`EXPOSED` / `UNGATED` / `SELF-REPORTED`) and its fixed note, "Heuristic, static scan. It can miss actions and misclassify names." Mark each finding you confirmed or rejected after reading the code. Omit this section if the scan was not run, and say why. 2. **Scope searched** — directories, languages, and the search patterns used, and anything skipped (generated code, vendored code, other repositories). 3. **Candidates** — the table above, each marked `UNPROTECTED`, `ADMISSION_ONLY`, `ADMITTED_AND_RECORDED`, or `UNKNOWN`, based only on code you actually read. 4. **Least privilege first** — for each candidate reachable with a broad or shared credential, the narrower credential to use instead (the scan's first recommendation), listed before any Intentrax step. 5. **Excluded actions** with one-line reasons. 6. **Coverage statement**, verbatim: "This report lists consequential actions found by static search of the scope above. It does not establish that every consequential action was found, that wrapped actions are wrapped on every code path, or that any real-world effect occurred." Never call a codebase "covered" or "fully assured". Report-only mode makes no code changes, needs no key, and sends nothing anywhere. ## Phase 2 — Propose a plan, then stop Present a short plan and **wait for the user to approve it** before editing code: 1. The ranked list of candidate actions, with the excluded list. 2. The adapter that matches their stack — one of `claude-code`, `cursor`, `mcp`, `langchain`, `langgraph`, `vercel-ai-sdk`, `crewai`, `autogen`, `n8n`, `openclaw`, `deepflow`, or `custom-agent`. 3. Where the wrapper goes (one choke point per action, ideally the tool dispatcher rather than every call site). 4. What the user must provide later, outside the repo: a tenant ID and API key in their secret store. Admission needs a key with the `agent.gateway.admit` scope. Execute needs a separately issued, execute-capable pilot key and an allowlisted tenant; until then the execute lane answers `423`/`403`, which is expected. 5. What the result will and will not prove (decision record; no independent effect confirmation today). 6. Optionally, a free local trial before any key exists: for one action, a read-only `my-check.mjs` (export `expected`, the state the action should produce, and a default async function that **reads** that state) for `npx @intentrax/sdk sandbox --check ./my-check.mjs`. The user runs their own action first; the sandbox never calls the write path. The result is labelled `SELF_REPORTED` and capped at `LOCAL_NON_TRUST_BEARING`: a trial, not evidence. Running it executes the user's module, so it needs the user's approval like any other run. ## Phase 3 — Implement (after approval) 1. **Scaffold offline.** Run `npx @intentrax/sdk init ` in the repo, then `npx @intentrax/sdk check-init --output-dir .`. Both work with no key and no network. Commit the generated `.intentrax/` files; they contain no secrets. 2. **Wire admission before the action.** Call the generated hook (or `admitAgentGatewayHttp` from `@intentrax/sdk/http`) at the choke point *before* the side effect. If admission is denied or errors, the action must not run. Fail closed. 3. **Carry one idempotency key.** Use the hook's `execute_idempotency_key` (or `createIdempotencyKey`) as the execute `idempotency_key`; admission already carries its SHA-256. Never derive them independently. 4. **Record execution evidence.** After the action, call `executeIntentHttp` with that key, and store the returned `registry_proof_id` beside the action's own result (database row, log record, or response metadata). 5. **Add verification.** Add a test or script that exports the proof and runs `npx @intentrax/sdk verify-proof --json`, and a code path that links to `https://verify.intentrax.com/verify/proof/`. 6. **Configure secrets by reference only.** Read `INTENTRAX_API_KEY` and `INTENTRAX_TENANT_ID` (or the user's own names) from the environment or a secret manager. Never write values into code, config, tests, or fixtures. Recipes for each step are in [references/wiring-recipes.md](references/wiring-recipes.md). ## Hard boundaries - **Never bypass policy.** Do not add flags, retries, or fallbacks that run the action when admission is denied, unreachable, or misconfigured. - **Never sign or fabricate proof material.** Do not generate keys, sign payloads, construct proof JSON, or mock a `VALID` verdict outside clearly labeled unit-test fixtures. The Intentrax engine is the sole signer of production proofs. (The local sandbox signs with throwaway keys it generates itself; never present its output as an Intentrax proof.) - **Never call execute or real side effects on the user's behalf** while integrating. Running the user's tests that hit live endpoints, or calling `/v1/intents/execute`, needs the user's explicit approval for that specific run. - **Never claim effect confirmation.** Describe the result as "admitted and recorded in a signed, verifiable proof." - **Least privilege.** Suggest separate keys for admission, execute, and read-only verification, and a read-only key for any MCP tool. ## Done means - Every candidate action is either wrapped or explicitly excluded by the user. - `check-init` passes, and a test proves a denied admission blocks the action. - No secret appears in the diff (`git diff | grep -i "api[_-]key"` shows only environment-variable names). - The README or PR description states what is proven and what is not.