Skip to main content

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_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.4.tar.gz (17.7 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.4-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mrs_inspector-0.1.4.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

Hashes for mrs_inspector-0.1.4.tar.gz
Algorithm Hash digest
SHA256 0ef52c94e04a1d7cd9101053263a13079b324fb1add075adc31c5457d2417409
MD5 9ca68bc89c867bf350dd1837fed26b34
BLAKE2b-256 1545e269302a20ed84373ee22fb6af3099251421b067fcffdfb8e1d227ec7ca9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mrs_inspector-0.1.4-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

Hashes for mrs_inspector-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 84dfc53e3b883fe759b4579bc20fab2ec72aafa50e586f3c242fc3f4893d15e7
MD5 8a6f6b3ab7fce0fced044b9d25b6639f
BLAKE2b-256 51810456fb76f4e14e1e17b8427f343358f9dfde1e54e99569d84d2b08ddde25

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