Skip to main content

AHS-Core — Conflict Resolution & Forensic Traceability for Agentic RAG

CI Python License: MIT

When documents disagree, AHS catches it — and proves it.

AHS-Core is a Python library that sits on top of your RAG / agent stack (LangGraph, CrewAI, raw OpenAI — anything) and adds three things generic agent frameworks don't give you out of the box:

  1. Conflict detection between retrieved premises — direct contradictions, numeric disagreements, and version drift (old SOP vs. new regulation).
  2. Cascading-hallucination awareness — every conflict is tracked across reasoning stages so an error from hop 1 doesn't silently become the answer at hop 5. (CHARM, arXiv:2606.04435).
  3. A forensic audit log — append-only, hash-chained JSONL recording every query, retrieved document, conflict, prompt, and answer. Tamper-evident and auditor-ready.

AHS is not a replacement for LangGraph or CrewAI. It's the layer you add when your RAG has to be correct and provable — compliance, legal, clinical, insurance, finance, policy.


Install

pip install ahs-agentic                # core (offline, deterministic LLM)
pip install ahs-agentic[openai]        # + OpenAI embeddings / LLM
pip install ahs-agentic[dev]           # + pytest, build, twine

From source:

git clone https://github.com/sachinagenticai/AHS_Agentic.git
cd AHS_Agentic
pip install -e ".[dev]"
pytest

60-second demo (no API key)

ahs demo

…or, in Python:

import asyncio
from ahs_agentic import (
    Evidence, HashEmbedder, InMemoryRetriever, SpeculativeRetriever,
    SkepticSubroutine, Reconciler, DeterministicLLM,
)

async def main():
    embedder = HashEmbedder(dim=512)
    backend  = InMemoryRetriever(embedder=embedder)
    retr     = SpeculativeRetriever(backend=backend, embedder=embedder)
    skeptic  = SkepticSubroutine(embedder=embedder, sensitivity_threshold=0.4)

    result = await Reconciler(retr, skeptic, DeterministicLLM()).reconcile(
        question="How long must customer tickets be retained?",
        corpus=[
            Evidence(id="v2022", source="policy.pdf", version="2022",
                     text="Tickets must be retained for 24 months. Encryption is optional."),
            Evidence(id="v2024", source="policy.pdf", version="2024",
                     text="Tickets must be retained for 60 months. Encryption at rest is mandatory."),
        ],
        audit_path="audit.jsonl",
    )

    print(result.answer)
    print("conflicts:", [c.conflict_type for c in result.conflicts])
    print("audit_id :", result.audit_id)

asyncio.run(main())

Sample output:

Question: How long must customer tickets be retained?

Answer based on the evidence:
- Tickets must be retained for 24 months. Encryption is optional. [v2022]
- Tickets must be retained for 60 months. Encryption at rest is mandatory. [v2024]

Source(s): v2022, v2024

Conflicts detected (human review recommended):
- [NUMERIC_DISAGREEMENT] between 'v2022' and 'v2024': Numbers disagree: ['24'] vs ['60'] ...

Architecture

User question
     │
     ▼
┌──────────────────┐
│   Reconciler     │   one-call façade
└──────────────────┘
     │
     ├──► SpeculativeRetriever ──► RetrieverBackend (in-mem / Chroma / pgvector)
     │       (parallel fan-out, bounded concurrency, metrics)
     │
     ├──► SkepticSubroutine  ──► Embedder (HashEmbedder / OpenAI / local)
     │       cosine delta + negation/version/numeric heuristics
     │
     ├──► ForensicLogger  ──► audit.jsonl  (append-only, hash-chained)
     │
     └──► LLM (DeterministicLLM / OpenAI / any provider)
             grounded, citation-only answer
     │
     ▼
ReconciliationResult { answer, evidence[], conflicts[], audit_id, cited_ids[] }

Why "conflict-aware" matters

Naive RAG retrieves chunks and asks the LLM to answer. When two chunks disagree, the model either silently picks one or hallucinates a compromise. Production pipelines in 2026 show the damage:

  • Cascading hallucinations propagate across multi-step pipelines with 82% reduction when stage-level conflict detection is added (CHARM, 2026).
  • GraphRAG with factuality gates cuts hallucinations by ~62% vs. naive chunk-and-retrieve (MLOps Community benchmark, May 2026).
  • Self-RAG / CRAG achieve 5.8–10.5% hallucination rates vs. 14%+ for static RAG.

AHS packages the detection and audit parts of those architectures into a library you can add to an existing pipeline in an afternoon.

Command-line usage

# Reconcile a question against a folder of .txt/.md files
ahs reconcile \
  --question "How long are customer tickets retained?" \
  --corpus  ./docs/policies/ \
  --out     report.json \
  --audit   audit.jsonl

# Or feed a JSONL corpus
ahs reconcile --question "..." --corpus corpus.jsonl --out report.json

Use it with LangGraph / CrewAI

AHS is just a Python object — call it from any node / agent:

# LangGraph node
def ahs_node(state):
    result = asyncio.run(reconciler.reconcile(
        question=state["question"], corpus=state["corpus"]))
    return {"answer": result.answer,
            "conflicts": [c.to_dict() for c in result.conflicts],
            "audit_id": result.audit_id}
# CrewAI custom agent
class ComplianceReviewer(Agent):
    def run(self, question, corpus):
        return asyncio.run(reconciler.reconcile(question, corpus)).to_dict()

Project status — v0.1 MVP

What's implemented

  • ✅ Installable PyPI package (ahs-agentic) with a stable public API
  • ✅ Pluggable Embedder, RetrieverBackend, LLMClient interfaces
  • HashEmbedder (offline) + OpenAIEmbedder
  • InMemoryRetriever + SpeculativeRetriever (parallel fan-out, batching, concurrency limits, metrics)
  • SkepticSubroutine — cosine delta plus direct-contradiction, numeric-disagreement, and version-drift detection
  • Reconciler façade — plan → retrieve → conflict-check → grounded LLM answer → audit log
  • OrchestratorManager + TaskStateMachine + BaseAgent — audited routing with keyword/specialty scoring and escalation
  • ForensicLogger — hash-chained JSONL, tamper-evident
  • DeterministicLLM for offline tests/CI + OpenAILLM adapter
  • ✅ Resilience layer (tenacity retries, tiktoken prompt trimming)
  • ✅ CLI: ahs demo, ahs reconcile
  • ✅ Full pytest suite + GitHub Actions CI

What's v0.2+ (not in MVP)

  • 🔜 Chroma / FAISS / pgvector retriever backends
  • 🔜 LangGraph / CrewAI integration packages
  • 🔜 Cross-stage cascade detector (the full CHARM pipeline)
  • 🔜 Anthropic / local-LLM clients
  • 🔜 Orchestrator with TaskStateMachine (see docs/ORCHESTRATOR.md for the design)
  • 🔜 Streamlit explorer UI
  • 🔜 Public conflict-reconciliation benchmark

See ROADMAP.md.

Smoke evaluation

examples/eval.py is a tiny, reproducible, offline eval on 20 hand-curated premise pairs (10 conflicts, 10 aligned paraphrases). It is not a research benchmark — it's a guard rail so changes to the Skeptic don't silently break obvious cases.

$ python examples/eval.py
Accuracy : 1.00
Precision: 1.00
Recall   : 1.00
F1       : 1.00

For real numbers against your corpus, pair SkepticSubroutine with OpenAIEmbedder (or any semantic embedder) and run it over a labelled conflict set.

Development

pip install -e ".[dev]"
pytest                       # all tests, offline
python examples/reconcile_demo.py
python examples/orchestrator_demo.py
python examples/resilience_demo.py
python examples/eval.py
ahs demo

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ahs_agentic-0.1.0.tar.gz (51.0 kB view details)

Uploaded Source

Built Distribution

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

ahs_agentic-0.1.0-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

Details for the file ahs_agentic-0.1.0.tar.gz.

File metadata

  • Download URL: ahs_agentic-0.1.0.tar.gz
  • Upload date:
  • Size: 51.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ahs_agentic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c9ac7a54ede851b0e77f9d418162139e0dd1cfb9666a77fca8e486865a93d7bd
MD5 d6b8fe71ecb0bcd5173375f8d61170a0
BLAKE2b-256 c6e8b100e9fcbe98f16968d4790bff25bc4883adbe66c2f9b8a04fed8f936f3d

See more details on using hashes here.

File details

Details for the file ahs_agentic-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ahs_agentic-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ahs_agentic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfa65fb67bdc6e9031bf9c0097cd1f75c872b8196491308902648545c42a56a8
MD5 5377af02c6d8147ea5b43e43d28e6f21
BLAKE2b-256 ea66b7bb659e9c0530da8fae5df6a313b27df88fdbf6541b6d9417aca53f9907

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

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