Navigate docs

/instrument — Claude Code Skill

The /instrument skill brings AgentLattice governance to any agent codebase from inside Claude Code. It works with frameworks that al-instrument and al-instrument-ts do not cover — CrewAI, AutoGen, LangChain JS, LlamaIndex, raw SDK usage, and custom patterns.

When to use this vs. the CLIs

Tool Best for
al-instrument LangChain Python agents in CI/CD pipelines
al-instrument-ts Claude Agent SDK, Vercel AI SDK, OpenAI SDK TS agents in CI/CD
/instrument skill Everything else: CrewAI, AutoGen, LangChain JS, raw SDKs, custom frameworks, or any codebase where you want Claude to read context before instrumenting

The CLIs are deterministic — they parse ASTs and apply known transforms. The skill is AI-assisted — Claude reads the full codebase, understands intent, and instruments accordingly. Use the CLIs for automation; use the skill for onboarding and unfamiliar frameworks.

Install

The skill ships with @agentlattice/cli. Install it with one command:

npm install -g @agentlattice/cli
al install-skill

This copies the skill to ~/.claude/skills/instrument/SKILL.md. Claude Code picks it up automatically — no restart required.

Usage

Open Claude Code in your agent project directory and run:

/instrument                    # scan current directory
/instrument agent.py           # single Python file
/instrument agent.ts           # single TypeScript file
/instrument src/agents/        # directory scan

What it does

1. Detects frameworks automatically. The skill reads your imports and identifies which agent framework you're using — no configuration required.

2. Classifies every tool. Each tool or action is assigned an action type using the {domain}.{verb} taxonomy. Classification uses Claude's judgment based on tool names, descriptions, and surrounding code context — no additional API keys required.

3. Injects governance calls. For each tool:

  • Python sync code: al.gate_sync("action.type")
  • Python async code: await al.gate("action.type")
  • TypeScript: await al.gate("action.type")

4. Explains every change. Each injected call includes an inline comment explaining the action type, risk level, and default policy — so the diff is the tutorial.

5. Offers to register. After instrumenting, the skill offers to run al register to activate governance immediately.

Supported frameworks

Framework Language How it's instrumented
LangChain Python Uses al-instrument CLI (falls back to AI-assisted if not installed)
Claude Agent SDK TypeScript Uses al-instrument-ts CLI (falls back to AI-assisted)
Vercel AI SDK TypeScript Uses al-instrument-ts CLI (falls back to AI-assisted)
OpenAI SDK TypeScript Uses al-instrument-ts CLI (falls back to AI-assisted)
CrewAI Python AI-assisted: gate_sync() injected into _run / _arun
AutoGen Python AI-assisted: gate_sync() injected into tool functions
LangChain JS TypeScript AI-assisted: gate() injected into tool handler functions
LlamaIndex Python AI-assisted: gate_sync() injected into FunctionTool functions
Raw Anthropic SDK Python / TS AI-assisted: gate() injected into dispatch handler
Raw OpenAI SDK Python / TS AI-assisted: gate() injected into dispatch handler
Custom frameworks Any AI-assisted: Claude reads and instruments based on context

Action type taxonomy

Action types follow {domain}.{verb} format. Risk is determined by the verb:

Verb Risk Default policy
query, read read Auto-approved
write, send, execute, create, update write Logged
delete delete Requires human approval

Domains: api, code, db, email, file, payment, system, user, web

Example output

════════════════════════════════════════════════════
  /instrument report
════════════════════════════════════════════════════

  FILE:      crew_agent.py
  FRAMEWORK: CrewAI
  METHOD:    AI-assisted (Claude)

  TOOLS INSTRUMENTED: 3
    search_web      → web.query      (read, auto-approved)
    send_email      → email.send     (write, logged)
    delete_records  → db.delete      (delete, requires approval)

  CHANGES: written to crew_agent.py

  NEXT STEPS:
    1. Review the diff: git diff crew_agent.py
    2. Set AL_API_KEY in your environment
    3. Run your agent — governance is active
    4. Visit https://www.agentlattice.io/dashboard to configure policies

════════════════════════════════════════════════════

Prerequisites

  • Claude Code installed
  • pip install agentlattice (Python agents) or npm install @agentlattice/sdk (TypeScript agents)
  • AL_API_KEY set in your environment (obtained after al register)