Skip to main content

R3Con

The code of the paper Realize What Matters: Principled Context Representation for Large-Scale Reasoning. Continued development lives at r3trace.

Context representation for large-scale reasoning.

Ask a question whose evidence is scattered across many documents. r3con organizes that context into a representation built for that question, then reasons over it.

How r3con works

Install

pip install r3context

Version 1.0.0 is the code in this repository. It needs Python 3.11 or newer, and imports as r3con.

Set the key your provider expects:

export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...

Or put them in a .env in your working directory.

Use

Command line — point it at a folder, a glob, or files:

r3con run "Which supplier missed the most delivery windows?" ./reports \
  --model openai/gpt-5.6-luna

--model takes any litellm model string, e.g. anthropic/claude-sonnet-5, gemini/gemini-3.8-flash, hosted_vllm/Qwen/Qwen3.5-35B-A3B. The default is openai/gpt-5.6-luna.

A folder is walked recursively. You can also match a pattern, or name the files:

r3con run "Who approved the Q3 overspend?" "./reports/*.pdf"      # quote the glob
r3con run "Who approved the Q3 overspend?" "./reports/**/*.pdf"   # ** recurses
r3con run "Who approved the Q3 overspend?" q1.md q2.md q3.md      # or name them

Python, reading documents off disk:

from r3con import r3con

docs = r3con.read_documents("./reports")     # a folder, a glob, or a list of files
                                             # .txt .md .csv .json .html .xml … and .pdf
result = r3con.run("Which supplier missed the most delivery windows?", docs)
print(result)

Python, documents you already have:

result = r3con.run("Which supplier missed the most delivery windows?", [doc_a, doc_b, doc_c])

documents is a list of strings — the documents themselves.

Notebooks, over five short memos arranged so no single one holds the answer:

What you get back

result.answer             # str       — the answer; str(result) gives you the same
result.relevant_context   # list[str] — the final collection of relevance snippets
result.structured_context # dict      — the structured context, in dict form
result.run_dir            # Path      — where this run's artifacts went (below)

Logs

Every run writes a folder under ./logs with everything it did — each document's relevance snippet in every round, the schema it proposed, the parsed records, and the reasoning transcript.

logs/<timestamp>_<hex>/          <- result.run_dir
├── relevance/            result.json · calls.json
├── structuring/
│   ├── schema/           result.json · calls.json · transcript.yaml
│   └── parsing/          result.json · calls.json
└── reasoning/            result.json · calls.json · transcript.yaml

Evaluation

How r3con was evaluated, with the baselines it was compared against: r3con-evaluation.

Licence

MIT — see LICENSE. src/r3con/runtime/python_executor.py is a modified copy of the sandboxed interpreter from smolagents, Apache-2.0, © HuggingFace Inc. See NOTICE and LICENSE-APACHE-2.0.

Metadata

Release files for r3context 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for r3context 1.0.0
File Size Uploaded Provenance Actions
r3context-1.0.0.tar.gz 86.4 kB With provenance Details for r3context-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for r3context 1.0.0
File Interpreter ABI Platform Actions
r3context-1.0.0-py3-none-any.whl Python 3 none any Details for r3context-1.0.0-py3-none-any.whl

Total release size: 184.8 kB

Release files / r3context-1.0.0.tar.gz

Download URL r3context-1.0.0.tar.gz
Size 86.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a307ffe6c12074fb3b658ca2e199af1de8590a9e53a59b14422d9b6d28e33f40
BLAKE2b-256 checksum
How to use checksums
831b6bbc17e7b0dc6d6844eb4a0364d7157c0b8b84dfc1ead22fd36b32d238bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / r3context-1.0.0-py3-none-any.whl

Download URL r3context-1.0.0-py3-none-any.whl
Size 98.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b69a93dff25c458479807b45ca7f845b0519827c30844e87a315e4482bf19ac7
BLAKE2b-256 checksum
How to use checksums
005a9672e2a1cc453ac3d2424b781b6f104200eb4164ed6f7f1e419bc0fdb998
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for r3context 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for r3context-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page