Metadata-Version: 2.4
Name: context-coherence
Version: 0.1.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Dist: wasmtime==51.0.0 ; extra == 'wasmtime-reference'
Requires-Dist: langgraph==1.2.24 ; extra == 'langgraph'
Requires-Dist: claude-agent-sdk==0.2.189 ; extra == 'claude-agents'
Requires-Dist: python-dotenv>=1,<2 ; extra == 'claude-agents'
Requires-Dist: google-adk==2.15.1 ; extra == 'google-adk'
Requires-Dist: openai-agents==0.20.0 ; extra == 'openai-agents'
Requires-Dist: python-dotenv>=1,<2 ; extra == 'openai-agents'
Requires-Dist: langgraph==1.2.24 ; extra == 'llm-example'
Requires-Dist: openai>=1.100,<3 ; extra == 'llm-example'
Requires-Dist: python-dotenv>=1,<2 ; extra == 'llm-example'
Provides-Extra: wasmtime-reference
Provides-Extra: langgraph
Provides-Extra: claude-agents
Provides-Extra: google-adk
Provides-Extra: openai-agents
Provides-Extra: llm-example
License-File: LICENSE
License-File: NOTICE
License-File: THIRD_PARTY_NOTICES.md
License-File: LICENSES/Rust-1.95.0-Apache-2.0.txt
License-File: LICENSES/Rust-1.95.0-BSD-2-Clause.txt
License-File: LICENSES/Rust-1.95.0-CC-BY-SA-4.0.txt
License-File: LICENSES/Rust-1.95.0-COPYRIGHT-library.html
License-File: LICENSES/Rust-1.95.0-GCC-exception-3.1.txt
License-File: LICENSES/Rust-1.95.0-GPL-2.0-only.txt
License-File: LICENSES/Rust-1.95.0-GPL-3.0-or-later.txt
License-File: LICENSES/Rust-1.95.0-ISC.txt
License-File: LICENSES/Rust-1.95.0-LLVM-exception.txt
License-File: LICENSES/Rust-1.95.0-MIT.txt
License-File: LICENSES/Rust-1.95.0-NCSA.txt
License-File: LICENSES/Rust-1.95.0-OFL-1.1.txt
License-File: LICENSES/Rust-1.95.0-Unicode-3.0.txt
License-File: LICENSES/allocator-api2-0.2.22-LICENSE-APACHE.txt
License-File: LICENSES/allocator-api2-0.2.22-LICENSE-MIT.txt
License-File: LICENSES/bitflags-2.13.2-LICENSE-APACHE.txt
License-File: LICENSES/bitflags-2.13.2-LICENSE-MIT.txt
License-File: LICENSES/block-buffer-0.10.4-LICENSE-APACHE.txt
License-File: LICENSES/block-buffer-0.10.4-LICENSE-MIT.txt
License-File: LICENSES/boxcar-0.2.14-LICENSE.txt
License-File: LICENSES/cc-1.12.0-LICENSE-APACHE.txt
License-File: LICENSES/cc-1.12.0-LICENSE-MIT.txt
License-File: LICENSES/cfg-if-1.0.5-LICENSE-APACHE.txt
License-File: LICENSES/cfg-if-1.0.5-LICENSE-MIT.txt
License-File: LICENSES/cpufeatures-0.2.17-LICENSE-APACHE.txt
License-File: LICENSES/cpufeatures-0.2.17-LICENSE-MIT.txt
License-File: LICENSES/crossbeam-deque-0.8.8-LICENSE-APACHE.txt
License-File: LICENSES/crossbeam-deque-0.8.8-LICENSE-MIT.txt
License-File: LICENSES/crossbeam-epoch-0.9.21-LICENSE-APACHE.txt
License-File: LICENSES/crossbeam-epoch-0.9.21-LICENSE-MIT.txt
License-File: LICENSES/crossbeam-queue-0.3.14-LICENSE-APACHE.txt
License-File: LICENSES/crossbeam-queue-0.3.14-LICENSE-MIT.txt
License-File: LICENSES/crossbeam-utils-0.8.23-LICENSE-APACHE.txt
License-File: LICENSES/crossbeam-utils-0.8.23-LICENSE-MIT.txt
License-File: LICENSES/crypto-common-0.1.7-LICENSE-APACHE.txt
License-File: LICENSES/crypto-common-0.1.7-LICENSE-MIT.txt
License-File: LICENSES/digest-0.10.7-LICENSE-APACHE.txt
License-File: LICENSES/digest-0.10.7-LICENSE-MIT.txt
License-File: LICENSES/either-1.19.0-LICENSE-APACHE.txt
License-File: LICENSES/either-1.19.0-LICENSE-MIT.txt
License-File: LICENSES/equivalent-1.0.3-LICENSE-APACHE.txt
License-File: LICENSES/equivalent-1.0.3-LICENSE-MIT.txt
License-File: LICENSES/fallible-iterator-0.3.0-LICENSE-APACHE.txt
License-File: LICENSES/fallible-iterator-0.3.0-LICENSE-MIT.txt
License-File: LICENSES/fallible-streaming-iterator-0.1.9-LICENSE-APACHE.txt
License-File: LICENSES/fallible-streaming-iterator-0.1.9-LICENSE-MIT.txt
License-File: LICENSES/find-msvc-tools-0.1.16-LICENSE-APACHE.txt
License-File: LICENSES/find-msvc-tools-0.1.16-LICENSE-MIT.txt
License-File: LICENSES/foldhash-0.2.0-LICENSE.txt
License-File: LICENSES/generic-array-0.14.7-LICENSE.txt
License-File: LICENSES/hashbrown-0.17.2-LICENSE-APACHE.txt
License-File: LICENSES/hashbrown-0.17.2-LICENSE-MIT.txt
License-File: LICENSES/hashlink-0.12.2-LICENSE-APACHE.txt
License-File: LICENSES/hashlink-0.12.2-LICENSE-MIT.txt
License-File: LICENSES/heck-0.5.0-LICENSE-APACHE.txt
License-File: LICENSES/heck-0.5.0-LICENSE-MIT.txt
License-File: LICENSES/indexmap-2.14.2-LICENSE-APACHE.txt
License-File: LICENSES/indexmap-2.14.2-LICENSE-MIT.txt
License-File: LICENSES/intrusive-collections-0.10.3-LICENSE-APACHE.txt
License-File: LICENSES/intrusive-collections-0.10.3-LICENSE-MIT.txt
License-File: LICENSES/inventory-0.3.25-LICENSE-APACHE.txt
License-File: LICENSES/inventory-0.3.25-LICENSE-MIT.txt
License-File: LICENSES/libc-0.2.191-LICENSE-APACHE.txt
License-File: LICENSES/libc-0.2.191-LICENSE-MIT.txt
License-File: LICENSES/libsqlite3-sys-0.40.0-LICENSE.txt
License-File: LICENSES/lock_api-0.4.14-LICENSE-APACHE.txt
License-File: LICENSES/lock_api-0.4.14-LICENSE-MIT.txt
License-File: LICENSES/once_cell-1.21.4-LICENSE-APACHE.txt
License-File: LICENSES/once_cell-1.21.4-LICENSE-MIT.txt
License-File: LICENSES/parking_lot-0.12.5-LICENSE-APACHE.txt
License-File: LICENSES/parking_lot-0.12.5-LICENSE-MIT.txt
License-File: LICENSES/parking_lot_core-0.9.12-LICENSE-APACHE.txt
License-File: LICENSES/parking_lot_core-0.9.12-LICENSE-MIT.txt
License-File: LICENSES/pin-project-lite-0.2.19-LICENSE-APACHE.txt
License-File: LICENSES/pin-project-lite-0.2.19-LICENSE-MIT.txt
License-File: LICENSES/pkg-config-0.3.34-LICENSE-APACHE.txt
License-File: LICENSES/pkg-config-0.3.34-LICENSE-MIT.txt
License-File: LICENSES/portable-atomic-1.15.0-LICENSE-APACHE.txt
License-File: LICENSES/portable-atomic-1.15.0-LICENSE-MIT.txt
License-File: LICENSES/proc-macro2-1.0.107-LICENSE-APACHE.txt
License-File: LICENSES/proc-macro2-1.0.107-LICENSE-MIT.txt
License-File: LICENSES/pyo3-0.29.0-LICENSE-APACHE.txt
License-File: LICENSES/pyo3-0.29.0-LICENSE-MIT.txt
License-File: LICENSES/pyo3-build-config-0.29.0-LICENSE-APACHE.txt
License-File: LICENSES/pyo3-build-config-0.29.0-LICENSE-MIT.txt
License-File: LICENSES/pyo3-ffi-0.29.0-LICENSE-APACHE.txt
License-File: LICENSES/pyo3-ffi-0.29.0-LICENSE-MIT.txt
License-File: LICENSES/pyo3-macros-0.29.0-LICENSE-APACHE.txt
License-File: LICENSES/pyo3-macros-0.29.0-LICENSE-MIT.txt
License-File: LICENSES/pyo3-macros-backend-0.29.0-LICENSE-APACHE.txt
License-File: LICENSES/pyo3-macros-backend-0.29.0-LICENSE-MIT.txt
License-File: LICENSES/quote-1.0.47-LICENSE-APACHE.txt
License-File: LICENSES/quote-1.0.47-LICENSE-MIT.txt
License-File: LICENSES/rayon-1.12.0-LICENSE-APACHE.txt
License-File: LICENSES/rayon-1.12.0-LICENSE-MIT.txt
License-File: LICENSES/rayon-core-1.13.0-LICENSE-APACHE.txt
License-File: LICENSES/rayon-core-1.13.0-LICENSE-MIT.txt
License-File: LICENSES/redox_syscall-0.5.18-LICENSE.txt
License-File: LICENSES/rusqlite-0.43.0-LICENSE.txt
License-File: LICENSES/rustc-hash-2.1.3-LICENSE-APACHE.txt
License-File: LICENSES/rustc-hash-2.1.3-LICENSE-MIT.txt
License-File: LICENSES/rustversion-1.0.23-LICENSE-APACHE.txt
License-File: LICENSES/rustversion-1.0.23-LICENSE-MIT.txt
License-File: LICENSES/salsa-0.28.5-LICENSE-APACHE.txt
License-File: LICENSES/salsa-0.28.5-LICENSE-MIT.txt
License-File: LICENSES/salsa-macro-rules-0.28.5-LICENSE-APACHE.txt
License-File: LICENSES/salsa-macro-rules-0.28.5-LICENSE-MIT.txt
License-File: LICENSES/salsa-macros-0.28.5-LICENSE-APACHE.txt
License-File: LICENSES/salsa-macros-0.28.5-LICENSE-MIT.txt
License-File: LICENSES/scopeguard-1.2.0-LICENSE-APACHE.txt
License-File: LICENSES/scopeguard-1.2.0-LICENSE-MIT.txt
License-File: LICENSES/sha2-0.10.9-LICENSE-APACHE.txt
License-File: LICENSES/sha2-0.10.9-LICENSE-MIT.txt
License-File: LICENSES/shlex-2.0.1-LICENSE-APACHE.txt
License-File: LICENSES/shlex-2.0.1-LICENSE-MIT.txt
License-File: LICENSES/smallvec-1.16.6-LICENSE-APACHE.txt
License-File: LICENSES/smallvec-1.16.6-LICENSE-MIT.txt
License-File: LICENSES/syn-2.0.119-LICENSE-APACHE.txt
License-File: LICENSES/syn-2.0.119-LICENSE-MIT.txt
License-File: LICENSES/syn-3.0.10-LICENSE-APACHE.txt
License-File: LICENSES/syn-3.0.10-LICENSE-MIT.txt
License-File: LICENSES/target-lexicon-0.13.6-LICENSE.txt
License-File: LICENSES/thin-vec-0.2.21-LICENSE-APACHE.txt
License-File: LICENSES/thin-vec-0.2.21-LICENSE-MIT.txt
License-File: LICENSES/tracing-0.1.44-LICENSE.txt
License-File: LICENSES/tracing-core-0.1.36-LICENSE.txt
License-File: LICENSES/typeid-1.0.3-LICENSE-APACHE.txt
License-File: LICENSES/typeid-1.0.3-LICENSE-MIT.txt
License-File: LICENSES/typenum-1.20.1-LICENSE-APACHE.txt
License-File: LICENSES/typenum-1.20.1-LICENSE-MIT.txt
License-File: LICENSES/typenum-1.20.1-LICENSE.txt
License-File: LICENSES/unicode-ident-1.0.27-LICENSE-APACHE.txt
License-File: LICENSES/unicode-ident-1.0.27-LICENSE-MIT.txt
License-File: LICENSES/unicode-ident-1.0.27-LICENSE-UNICODE.txt
License-File: LICENSES/vcpkg-0.2.15-LICENSE-APACHE.txt
License-File: LICENSES/vcpkg-0.2.15-LICENSE-MIT.txt
License-File: LICENSES/version_check-0.9.5-LICENSE-APACHE.txt
License-File: LICENSES/version_check-0.9.5-LICENSE-MIT.txt
License-File: LICENSES/windows-link-0.2.1-license-apache-2.0.txt
License-File: LICENSES/windows-link-0.2.1-license-mit.txt
Summary: Dependency-aware context validity and selective recomputation for AI agents and long-running computational workflows.
Keywords: artificial-intelligence,ai-agents,context-coherence,dependency-tracking,selective-recomputation,agent-reliability
Author-email: "Bhanuj.AI" <contact@bhanuj.ai>
Maintainer-email: Bhanuj <contact@bhanuj.ai>
License-Expression: Apache-2.0
Requires-Python: >=3.11, <3.15
Description-Content-Type: text/markdown
Project-URL: Homepage, https://github.com/Bhanuj-AI/context-coherence
Project-URL: Documentation, https://github.com/Bhanuj-AI/context-coherence/blob/main/docs/README.md
Project-URL: Changelog, https://github.com/Bhanuj-AI/context-coherence/blob/main/CHANGELOG.md
Project-URL: Repository, https://github.com/Bhanuj-AI/context-coherence
Project-URL: Issues, https://github.com/Bhanuj-AI/context-coherence/issues
Project-URL: Maintainer, https://bhanuj.ai

# Co2 — Context Coherence

**Dependency-aware context validity and selective recomputation for AI agents and long-running workflows.**

Install **`context-coherence`**, import **`co2`**.

Co2 tracks which computational results depend on changing inputs. When those inputs change, it identifies stale results and produces an explainable plan for what can be reused, refreshed, recomputed or reviewed. Your application keeps control of execution, agent orchestration and external actions.

The typed Python SDK delegates to an authoritative Rust core. The base package runs in memory and requires no database service, agent framework or model provider.

## Install

```sh
python -m pip install context-coherence
```

To pin this release:

```sh
python -m pip install 'context-coherence==0.1.0'
```

Use standard GIL-enabled CPython **3.11–3.14**. Version `0.1.0` provides native wheels for:

| Platform | Architecture | Wheel compatibility |
| --- | --- | --- |
| Linux | x86_64 | glibc 2.34 or later |
| Linux | ARM64 / aarch64 | glibc 2.34 or later |
| macOS | Apple Silicon / ARM64 | `macosx_11_0_arm64` deployment target |

The macOS deployment target is a binary compatibility tag, not a claim of testing every macOS release. Windows, Intel macOS, Alpine/musl, PyPy and free-threaded Python are outside this wheel matrix. Source builds require Rust/Cargo 1.95 or later, a native C toolchain and the pinned Maturin build backend.

## Track changing context

This standalone example uses synthetic values and no network services:

```python
from co2 import Coherence, ExecutionKind, IdentityKind, PlanAction

with Coherence() as coherence:
    coherence.register_resource("customer-status", "active-v1")
    attempt, artifact = coherence.new_identities(
        [IdentityKind.ATTEMPT, IdentityKind.ARTIFACT]
    )
    coherence.begin(
        attempt.value,
        "eligibility",
        resources=["customer-status"],
        execution=ExecutionKind.DETERMINISTIC,
    )
    coherence.complete(attempt.value, artifact.value, b"eligible")

    assert coherence.plan_actions().steps[0].action is PlanAction.REUSE

    coherence.register_resource("customer-status", "inactive-v2")
    step = coherence.plan_actions().steps[0]
    assert step.action is PlanAction.RECOMPUTE
    print(step.action.value)  # recompute
```

Co2 does not run that computation again. The host consumes the plan, obtains current source data, executes permitted work and registers a new result with new attempt and artifact identities. A result arriving after its captured inputs change is rejected atomically.

## Recompute only affected work

In a synthetic lending workflow:

- Eligibility depends on customer status.
- Credit assessment depends on credit history.
- A recommendation depends on both assessment artifacts.

Changing customer status invalidates eligibility and the derived recommendation. The credit assessment can remain reusable under an accurate dependency contract. The host can execute the affected work and retain the unaffected artifact.

Dependency provenance remains explicit even when two computations return equal bytes. The host supplies accurate resource versions and complete accessible context; Co2 cannot discover unreported external changes.

## Plan according to execution semantics

| Disposition | Host response |
| --- | --- |
| `REUSE` | Reuse an existing valid artifact. |
| `REFRESH` | Refresh eligible read-only observations. |
| `RECOMPUTE` | Execute eligible stale reasoning or deterministic work. |
| `REVALIDATE` | Obtain renewed human validation. |
| `BLOCK` | Stop automatic continuation. |
| `ESCALATE` | Obtain explicit review for irreversible work. |

Probabilistic reasoning requires an explicit recomputation policy. Stale side-effecting operations are blocked, irreversible operations require escalation, and human decisions require revalidation. Unknown execution classifications fail conservatively.

A plan is a point-in-time classification, not an execution authorization or a transaction over external systems.

## Choose dependency confidence

- **Invocation level:** the conservative default retains the complete context supplied by the host.
- **Explicit structured:** independently identifiable outputs can use distinct trusted developer-declared dependency sets. Missing, untrusted or incomplete declarations fall back conservatively.
- **Runtime observed:** controlled reads record access, but ordinary host observation does not prove isolation. `RuntimeObservedFallback` retains conservative dependencies.
- **Scoped runtime enforced:** reviewed native providers can submit broker-bound evidence for their approved execution profiles. These optional native builds are separate from the public base wheel.

Publication validates the complete captured invocation snapshot before accepting results, regardless of the effective dependency set used for later invalidation.

## Integrate with an existing framework

Install only the optional dependencies your application uses:

```sh
python -m pip install 'context-coherence[langgraph]'
python -m pip install 'context-coherence[openai-agents]'
python -m pip install 'context-coherence[google-adk]'
python -m pip install 'context-coherence[claude-agents]'
```

The adapters use the public SDK. Frameworks retain scheduling and execution; Co2 owns dependency validity and atomic artifact publication. Model credentials and live provider usage are application responsibilities. The Claude integration also has CLI/runtime prerequisites described in its integration guide.

The `llm-example` extra supports the optional synthetic comparison harness. Installing an extra does not change compiled native features.

## Understand the base package

The public `0.1.0` base wheel includes in-memory coherence, resource/version tracking, immutable artifact provenance, selective invalidation, execution-aware planning, lifecycle controls and the typed SDK.

SQLite durability and native runtime-enforcement providers require explicit feature builds with distinct private `+native.*` versions. They are not enabled by Python extras and are not included in the base wheel. Co2 owns neither sandbox infrastructure nor provider execution environments.

Coherence instances serialize authority mutations and atomically validate result registration. Computation executes outside that authority lock. The SDK supports concurrent callers sharing an instance within the documented single-process boundary; persistence, fork and recovery constraints depend on the chosen native build.

## Learn more

- [Documentation](https://github.com/Bhanuj-AI/context-coherence/blob/main/docs/README.md)
- [Installation and native variants](https://github.com/Bhanuj-AI/context-coherence/blob/main/docs/installation.md)
- [Synthetic lending quickstart](https://github.com/Bhanuj-AI/context-coherence/blob/main/docs/quickstart.md)
- [Architecture and trust boundaries](https://github.com/Bhanuj-AI/context-coherence/blob/main/ARCHITECTURE.md)
- [Supported configurations and limitations](https://github.com/Bhanuj-AI/context-coherence/blob/main/docs/capabilities.md)
- [Source and issue tracker](https://github.com/Bhanuj-AI/context-coherence)

Licensed under **Apache-2.0**. The package includes the project licence, notice and third-party attribution files.

