A lightweight tracing and reasoning-structure capture utility.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mrs_inspector-1.0.0.tar.gz.
File metadata
- Download URL: mrs_inspector-1.0.0.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db11beccbf35bbcdbfaa29272a5c4350e771bed373c95971c28ce9486846d447
|
|
| MD5 |
b2e15e8837062d8a29eb1cd9f0a53029
|
|
| BLAKE2b-256 |
343a5930317e67e01708d01ffd4e293d332236e4561ae9d257b9be655e6ed1f5
|
File details
Details for the file mrs_inspector-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mrs_inspector-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72afc8baeca77d8a1c871c833a185dc4528cad7b77da782dd594a0a63291b7d7
|
|
| MD5 |
4689cf876de1e9b664f4eb1efa4783e3
|
|
| BLAKE2b-256 |
76f067d5f96dfa1657ee261832e803e9297fd6de173d909006775346365f07fa
|