Undercurrent: Live Activation Probing in Production vLLM Inference

Undercurrent (Apache-2.0, arXiv:2611.37983) is an open-source Python library that executes trained activation probes on transformer residual streams, attention outputs, or MLP layers during live generation. It ships Hugging Face and vLLM continuous-batching adapters with inline abort gates, circuit breakers, and zero-latency async queues.
Undercurrent: Live Activation Probing in Production vLLM Inference: Undercurrent (Apache-2.0, arXiv:2611.37983) is an open-source Python library that executes trained activation probes on transformer residual streams, attention outputs, or MLP layers during live generation. It ships Hugging Face and vLLM continuous-batching adapters with inline abort gates, circuit breakers, and zero-latency async queues. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Declarative YAML Extraction Spec: Target `residual_stream`, `attn_out`, `mlp_out`, or `final_norm` at `prompt[-1]` or `generated[*]` without model forks.
- vLLM Continuous-Batching Attribution: Worker extension maps interleaved prefill/decode forward rows back to individual request token positions (<10^-3 error).
- Inline Abort & Circuit Breakers: Inline probes enforce `timeout_ms` budgets with fail-open/fail-closed policies and automatic circuit-breaker isolation.
- Zero-Latency Async Observability: Bounded per-request queues (`queue_depth`) offload trajectory probes to background worker threads with explicit drop policies.
import { createAgent } from '@smoke-monkey/harness';// Point Smoke Monkey Harness at a vLLM server instrumented with Undercurrent inline probesconst probedAgent = createAgent({agentId: 'undercurrent-probed-runner',provider: 'openai-compatible',model: 'meta-llama/Llama-3.1-8B-Instruct',baseUrl: 'http://127.0.0.1:8000/v1',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'ask',run_command: 'ask',},});async function executeWithInlineProbe() {try {const res = await probedAgent.run('Inspect repository webhook handlers for SSRF vulnerabilities and draft a safe patch.');console.log('Probe-cleared response:', res.summary);} catch (err) {console.error('Aborted by Undercurrent inline activation guard or runtime error:', err);}}executeWithInlineProbe().catch(console.error);
Watch: Related Video Guides
An Introduction to Mechanistic Interpretability – Neel Nanda | IASEAI 2025
Hacking LLMs: An Introduction to Mechanistic Interpretability — Jenny Vega
What Is Undercurrent? Production Activation Probing Architecture
Undercurrent is an Apache-2.0 Python library (github.com/wrynx/undercurrent) that runs user-supplied activation probes inside live LLM serving engines. Rather than running offline notebooks like TransformerLens or pyvene, Undercurrent maps continuously batched vLLM tensor rows back to per-request token positions for real-time inline aborts or asynchronous telemetry.
Text classifiers like Llama Guard can only react after harmful tokens are emitted. Because deception, sleeper-agent triggers, and harmful intent appear in intermediate residual streams during prefill (prompt[-1]), Undercurrent captures specified tensors and dispatches ActivationRecord objects across six decoupled subpackages (spec, core, router, sinks, adapters, model).
| Benchmark Scenario (GPT-2 124M CPU, 16x64) | Throughput (tok/s) | Median TTLT (s) | Inline Overhead / Token | Execution Path Behavior |
|---|---|---|---|---|
| Unprobed Baseline (`model.generate`) | 21.3 ± 1.1 | 2.96 s | — | Plain generation without hooks |
| Probed-0 (Empty Spec) | 21.9 ± 0.1 | 2.84 s | — | Adapter wrapper overhead within run variance |
| Inline-8 (8x L2 Norm Probes) | 22.7 ± 1.3 | 2.76 s | 0.19 ms (~24 µs/act) | Negligible vs decode step; supports instant abort |
| Inline-8-MLP (`768->256->1` Head) | 20.5 ± 1.6 | 3.13 s | 1.28 ms (~160 µs/act) | ~2.7% of 47 ms CPU decode step |
| Async-8-MLP (`queue_depth=8`) | 21.6 ± 0.5 | 2.91 s | 0 ms on critical path | Spends 2.0 s off-thread; max queue depth <= 1 |
Continuous Batch Attribution & Fail-Closed Inline Policies
In vLLM, a single forward pass interleaves prefill chunks and decode tokens across dozens of active requests, shifting tensor row indices on every step. Undercurrent's vLLM worker extension tracks per-request token offsets across batch steps and passes a GPU equivalence release gate on NVIDIA L4 (vLLM 0.28.0, PyTorch 2.13.0, CUDA 13.0), matching Hugging Face float32 residual_stream captures within < 10^-3 relative error.
Under slow-probe stress tests (100 ms sleep per activation, queue_depth=4), async drop policies kept median TTLT at 2.67–2.69 s vs 2.96 s baseline, proving generation stays decoupled from downstream telemetry stalls.
Match Probe Tensor Type & Backend Precision Before Deploying
Always verify hook points with `undercurrent inspect-model` and `undercurrent validate spec.yaml`. Capturing `mlp_out` instead of `residual_stream` introduces order-1.0 relative error and invalidates linear probes trained on residual states.
Reproducible Installation, YAML Validation & Probe Launch
Install Undercurrent from PyPI, inspect hookable layers on your target checkpoint, validate your declarative YAML extraction spec against the bundled JSON Schema, and launch an inline ProbedModel guard.
# 1. Install Undercurrent with vLLM adapter support
pip install undercurrent
# 2. Inspect model hookable layers and validate extraction YAML offline
undercurrent inspect-model meta-llama/Llama-3.1-8B-Instruct
undercurrent validate probe_spec.yaml
# 3. Run an inline prompt[-1] guard + async generated[*] trajectory monitor
python - <<'PY'
from undercurrent import ProbedModel, probe
SPEC = """
version: "1"
extraction_points:
- name: prefill_guard
layers: 16
tensor_type: residual_stream
position: "prompt[-1]"
probe_type: norm_gate
probe_kind: single_shot
execution_mode: inline
intervention:
mode: block_until_signal
timeout_ms: 250
on_timeout: abort
"""
@probe("norm_gate", threshold=500.0)
def norm_gate(record) -> float:
return float(record.tensor.norm())
with ProbedModel.from_pretrained("openai-community/gpt2", spec=SPEC, probes={"norm_gate": norm_gate}) as m:
out = m.generate("The quick brown fox", max_new_tokens=20)
print("Aborted:", out.aborted, "Verdict:", out.probe_results["prefill_guard"].verdict)
PYCombining Activation Guards with Smoke Monkey Tool Permissions
Deploying Smoke Monkey Harness against an Undercurrent-instrumented vLLM backend adds white-box defense-in-depth beneath tool permission gates. Even when an adversarial prompt injection slips past input regex filters in retrieved RAG documents, an inline prompt[-1] probe inspects the model's internal state and aborts the turn before a malicious write_file or run_command tool call is ever sampled.
Frequently Asked Questions
Q:How does Undercurrent differ from TransformerLens or pyvene?
TransformerLens and pyvene target offline single-batch research notebooks, whereas Undercurrent integrates directly with vLLM continuous batching, attributing interleaved tensor rows to individual requests with inline timeouts, circuit breakers, and async queues.
Q:Does asynchronous activation probing slow down token generation?
No. Async extraction points push records onto bounded per-request queues consumed by background worker threads, adding 0 ms to the critical decode path even when downstream probe evaluation lags.
Q:What happens if an inline activation probe times out under load?
Each inline extraction point configures explicit fallback policies—such as fail-closed (`on_timeout: abort`) or fail-open—alongside a circuit breaker to isolate misbehaving probes.
Q:Does Undercurrent include pre-trained safety probes out of the box?
No. Undercurrent focuses strictly on production tensor capture, request routing, and fault isolation under Apache-2.0; teams plug in their own trained linear or MLP probes via the `@probe` interface.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.