Skip to main content

Kiji Inspector: Mechanistic Interpretability for AI Agent Tool Selection

Kiji Inspector Workflow

CI Core CI Extras License: Apache 2.0 GitHub Stars GitHub Issues

Python Version Open In Colab

Responsible AI Contributions Welcome PRs Welcome

Status

This project is under heavy active development. We are planning to release a stable version of the framework in the coming weeks.

In the meantime, join our Slack Community

Learn more about our approach and early results:


What This Project Does

This project trains Sparse Autoencoders (SAEs) on the internal activations of an AI agent to understand why it selects specific tools. Given a user request like "Search our docs for API limits," the agent must choose between tools (e.g., internal_search vs web_search). We extract the model's hidden representations at the moment of that decision, decompose them into interpretable features using a JumpReLU SAE, and validate the resulting explanations through automated fuzzing and causal ablation experiments.

The key insight: train the SAE on raw activations (not difference vectors), then use contrastive pairs post-hoc to identify which learned features correspond to specific tool-selection decisions. This preserves the SAE's general feature dictionary while enabling targeted analysis of decision-relevant features.

Install

For loading and running pretrained SAEs:

pip install kiji-inspector

For the HuggingFace-based training and analysis extras (accelerate etc.):

pip install 'kiji-inspector[full]'

The vLLM extraction path is not covered by any extra: upstream vLLM wheels do not ship the hidden-states connector, so it requires the Docker image built from the repository Dockerfile, which compiles vLLM from the Davidnet/vllm fork.

Quick Start

from kiji_inspector import SAE

sae, feature_descriptions = SAE.from_pretrained(
    base_model="nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16",
    layer=20,
)

features = sae.encode(activations)
reconstruction = sae.decode(features)

Training and data-generation entrypoints live under the package namespace:

python -m kiji_inspector.generate_pairs 1300
python -m kiji_inspector.pipeline --layers 10 20 30

vLLM hidden-state extraction (native connector)

Activation extraction uses vLLM's native extract_hidden_states speculator method together with the ExampleHiddenStatesConnector, which writes captured hidden states to safetensors files that the extractor loads and cleans up per request. This capability ships in the 575lab/kiji-inspector:dev image, which builds the Davidnet/vllm fork (branch hidden-states-inline-return-squashed); the public v0.19.0 wheel does not contain the connector.

Run all extraction, tests, and API checks inside that image:

docker pull 575lab/kiji-inspector:dev

# Smoke test the connector (Qwen3-8B):
samples/run_hidden_states_test.sh 575lab/kiji-inspector:dev

# Iterate on the checked-out source with a bind mount:
docker run --rm --gpus all \
  -v "$PWD:/workspace" \
  -v "${HF_CACHE:-$HOME/.cache/huggingface}:/root/.cache/huggingface" \
  -e HF_HOME=/root/.cache/huggingface \
  -e PYTHONPATH=/workspace/src \
  -w /workspace \
  575lab/kiji-inspector:dev \
  python -m pytest tests/test_activation_extractors.py

The historical patches/ directory (applied against a stock v0.19.0 wheel) predates the fork-based image and is retained for reference only; the current image bakes those changes into the fork and does not run apply-patch.sh. See patches/README_PATCH.md for the legacy workflow.

To run the pipeline against a Qwen3.6 subject model (a reasoning model), pass --no-thinking so the decision token sits at the final-answer position:

python -m kiji_inspector.pipeline --subject-model Qwen/Qwen3.6-35B-A3B --no-thinking

📓 Examples

Two end-to-end notebooks demonstrate the library. Both run on Colab — the first works on a free T4, the second needs an A100 high-RAM runtime.

Notebook What it shows Open
quickstart_colab.ipynb Minimal walkthrough: capture a hidden state from google/gemma-4-E4B-it via a forward hook, load a pretrained SAE with SAE.from_pretrained, and describe the top features firing on a single prompt. Also covers the vLLM extraction path. Open In Colab
home_repair_colab.ipynb Full agent demo: a Nemotron-3-Nano-30B home repair advisor calls four tools across three appliance problems, the residual stream is captured at every decision point, and a trained JumpReLU SAE decomposes those activations into themed features. Includes the interactive index.html viewer served from Colab. Open In Colab

🤝 Contributing

We welcome contributions! Whether you're fixing a bug, improving documentation, or proposing a new feature, your help is appreciated.

Ways to Contribute

  • Report Bugs - Open an issue with steps to reproduce
  • Improve Docs - Documentation PRs are always welcome
  • Submit Features - Open an issue to discuss your idea before submitting a PR
  • Share Feedback - Start a discussion

Community


📄 License

Copyright (c) 2026 Dataiku SAS

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kiji_inspector-0.5.0.tar.gz (117.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kiji_inspector-0.5.0-py3-none-any.whl (125.0 kB view details)

Uploaded Python 3

File details

Details for the file kiji_inspector-0.5.0.tar.gz.

File metadata

  • Download URL: kiji_inspector-0.5.0.tar.gz
  • Upload date:
  • Size: 117.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kiji_inspector-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c79b59a951caf9e7fea34cf79b4f283ac233b105fdbcc7488b3abd64d96af720
MD5 a8664719dbbbb7146467a57b00395595
BLAKE2b-256 b5bca4ea874543dcfafef45bfcb088f5ce6546de0a352e144faa8ed7d26acd72

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiji_inspector-0.5.0.tar.gz:

Publisher: publish-kiji-inspector.yml on dataiku/kiji-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kiji_inspector-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: kiji_inspector-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 125.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kiji_inspector-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5dd45b491614f84167819a1b6ff6e03d80d60db323eaf8f9068ba38e95145da8
MD5 1d69a3fe7e60b3e47c33390e84cd1472
BLAKE2b-256 b9693ed55dd08b76a79a8a75cb3c9b4d017ab9d564cb3edd6b65a9542b8e8b77

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiji_inspector-0.5.0-py3-none-any.whl:

Publisher: publish-kiji-inspector.yml on dataiku/kiji-inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

This release

0.5.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page