This project has been archived by its maintainers, and is no longer receiving any updates.
MRS-Inspector v1.0 — Structured Reasoning Trace Engine
A companion module to the Modular Reasoning Scaffold (MRS), providing full visibility into reasoning steps, execution flow, and exceptions.
Overview
MRS-Inspector records every step of a function’s execution — calls, nested calls, phases, inputs, outputs, and exceptions — into a structured trace object.
It is designed to work alongside Modular Reasoning Scaffold (MRS) as its interpretability and debugging layer.
Where MRS provides structure,
MRS-Inspector provides visibility.
You can use MRS-Inspector to:
- instrument any Python function
- view internal reasoning flow
- collect nested call hierarchies
- capture exceptions with full traceback
- export traces to JSON
- reload traces for offline analysis or visualization
This enables research-grade transparency for small models, agents, recursive systems, or any code where reasoning steps matter.
1. Core Concepts
1.1 State Nodes
Every recorded event is a State — a dataclass containing:
id(UUID)module_namephase(“call”, “phase”, “root”)inputsoutputsexceptionparent_iddepthtimestamp
States form a tree that mirrors actual execution.
1.2 Trace Object
The Trace class stores all states and provides:
- ordered state list
- lookup by ID
- JSON save/load
- compatibility with visualization tools
1.3 Call Stack Model
A lightweight stack keeps track of active states.
Nested calls automatically become children of their callers.
2. Instrumentation Modes
2.1 @inspector.wrap — Function Instrumentation
Wrap any function to automatically record:
- its inputs
- its output
- nested calls inside it
- exceptions
Example:
@inspector.wrap
def compute(x):
return x * 2
Nested functions wrapped with .wrap automatically chain into the same trace.
2.2 Phases — with inspector.phase(name)
Phases are logical reasoning segments inside a function.
with inspector.phase("retrieve"):
docs = index.search(query)
Each phase becomes its own State node, allowing semantic segmentation of reasoning.
2.3 Root Execution — inspector.inspect(fn)
Runs a top-level function and returns (result, trace):
result, trace = inspector.inspect(main_fn)
This creates the root of the trace tree.
3. Exception Capture
All exceptions — including nested ones — are captured with:
- type
- message
- full traceback
Example stored format:
{
"type": "ZeroDivisionError",
"message": "division by zero",
"traceback": "Traceback (most recent call last)..."
}
Exceptions do not break the trace.
They become part of it.
4. JSON Export / Import
Save any trace:
trace.save_json("trace.json")
Load a trace:
loaded = Trace.load_json("trace.json")
Useful for:
- offline analysis
- visualization tools
- interpretability experiments
- dataset generation
5. Minimal Example
from mrs_inspector import Inspector
inspector = Inspector()
@inspector.wrap
def squared(x):
return x * x
def main():
with inspector.phase("setup"):
value = squared(3)
return value + 1
result, trace = inspector.inspect(main)
trace.save_json("trace.json")
Resulting trace will contain:
- root execution
- setup phase
- call to
squared - returned values
- timestamps and structure
6. What MRS-Inspector Enables
Interpretability
A structured understanding of how a model, agent, or recursive system produced its output.
Debugging
Exact reproduction of:
- the call structure
- intermediate values
- exceptions
- execution order
Reasoning Analysis
Turn any function (or agent) into a transparent reasoning pipeline.
Reusability & Offline Work
Share traces across systems or store them as part of datasets.
7. Roadmap
v1.0 (Current)
- full call tracing
- nested call support
- exception recording
- phases
- JSON export/import
- stable state tree representation
v1.1
- performance profiling
- time-delta metrics
- per-state memory footprint
v2.0
- graph visualization tools
- HTML trace viewer
- integration with MRS advanced recursion mode
License
Apache 2.0
Citation
RJ Sabouhi (2025). MRS-Inspector v1.0 — Structured Reasoning Trace Engine.
Metadata
Release files for mrs-inspector 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mrs_inspector-1.0.0.tar.gz | 17.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mrs_inspector-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.2 kB
Release files / mrs_inspector-1.0.0.tar.gz
| Download URL | mrs_inspector-1.0.0.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db11beccbf35bbcdbfaa29272a5c4350e771bed373c95971c28ce9486846d447
|
|
BLAKE2b-256 checksum How to use checksums |
343a5930317e67e01708d01ffd4e293d332236e4561ae9d257b9be655e6ed1f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / mrs_inspector-1.0.0-py3-none-any.whl
| Download URL | mrs_inspector-1.0.0-py3-none-any.whl |
|---|---|
| Size | 18.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72afc8baeca77d8a1c871c833a185dc4528cad7b77da782dd594a0a63291b7d7
|
|
BLAKE2b-256 checksum How to use checksums |
76f067d5f96dfa1657ee261832e803e9297fd6de173d909006775346365f07fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for mrs-inspector 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.