Skip to main content

A structural reasoning inspector for modular recursive systems (MRS). Provides tracing, phases, exception capture, and graph visualization.

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 Recursion 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 Recursion 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_name
  • phase (“call”, “phase”, “root”)
  • inputs
  • outputs
  • exception
  • parent_id
  • depth
  • timestamp

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

mrs_inspector-0.1.1.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

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

mrs_inspector-0.1.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file mrs_inspector-0.1.1.tar.gz.

File metadata

  • Download URL: mrs_inspector-0.1.1.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mrs_inspector-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8b3b812224dc077212b28ed87b58d237b8f855dcea4bf27243ba860b74fbebda
MD5 28cc1434d87a33fd10a376db08f6e09b
BLAKE2b-256 39c38cadd5f633d62cf429c9f5ee9c159e50fc67c2fe194446e81b2d153e403f

See more details on using hashes here.

File details

Details for the file mrs_inspector-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mrs_inspector-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mrs_inspector-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 75892075ea73154f712f8cf80ff0ecf2639ca7e88cdf8581c03f25e6908ca100
MD5 8519b348b5b42b41b4baf7e6a40773bf
BLAKE2b-256 b458b0c7d17531bc3c895bdec678ce7a1a1138d837c0cfb58df86b7161480ef1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page