Skip to main content

CredexAI LangChain SDK — Consensus verification layer for AI agents with XRPL provenance certificates.

Project description

credexai-langchain

Consensus verification layer for AI agents with XRPL provenance certificates.

PyPI version Python License: MIT


What is CredexAI?

CredexAI provides a consensus verification layer for AI agent outputs. Every verification:

  1. Routes to 5 independent AI verifiers — no single point of failure
  2. Cross-references against live data — real-time fact-checking
  3. Anchors on the XRP Ledger — immutable provenance certificate via TXID
  4. Returns structured results — verdict, confidence, sub-claims, and explanations

The XRPL transaction ID (TXID) serves as a cryptographic provenance certificate — anyone can verify that a specific output was verified at a specific time by checking the transaction on the public ledger.


Installation

# Core package
pip install credexai-langchain

# With LangChain support
pip install credexai-langchain[langchain]

# With CrewAI support
pip install credexai-langchain[crewai]

# With XRPL anchoring
pip install credexai-langchain[xrpl]

# Everything
pip install credexai-langchain[all]

Quick Start

Simple Verification

from credexai_langchain import verify

# Verify any text — routes through 5 verifiers + XRPL anchoring
result = verify("Water boils at 100°C at standard atmospheric pressure.")

print(result.verified_output)   # Original text (or annotated if issues found)
print(result.verdict)           # TRUE / FALSE / MIXED
print(result.confidence)        # 0.95
print(result.txid)              # "A1B2C3D4..." (XRPL provenance certificate)
print(result.verifier_count)    # 5
print(result.timestamp)         # "2024-01-15T10:30:00Z"
print(result.provenance_url)    # "https://testnet.xrpl.org/transactions/A1B2C3..."

Wrap a LangChain Agent

from credexai_langchain import CredexAILangChainWrapper
from langchain.agents import AgentExecutor

# Create your agent as usual
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# Wrap it — all outputs are now verified with XRPL provenance
verified_agent = CredexAILangChainWrapper(agent_executor)

# Run — returns VerificationResult instead of raw string
result = verified_agent.run("Analyze the latest XRPL governance proposal.")
print(result.verified_output)   # The verified agent output
print(result.verdict)           # Consensus verdict
print(result.txid)              # XRPL provenance certificate

Authentication

Set your API key via environment variable or constructor parameter:

export CREDEXAI_API_KEY="your-api-key"
from credexai_langchain import verify

# Uses CREDEXAI_API_KEY env var automatically
result = verify("claim to check")

# Or pass explicitly
result = verify("claim to check", api_key="your-api-key")

Free tier: First 1,000 verification calls are free per API key.


LangChain Integration

Callback Handler (Automatic Verification)

from credexai_langchain.langchain import CredexVerifyCallback
from langchain.agents import initialize_agent

# Automatically verifies all agent outputs
callback = CredexVerifyCallback(api_key="your-key")
agent = initialize_agent(tools, llm, callbacks=[callback])

result = agent.run("What is the current price of XRP?")

# Access verification results
print(callback.last_result.verdict)
print(callback.last_result.txid)

Tool (Agent-Initiated Verification)

from credexai_langchain.langchain import CredexVerifyTool

# Give agents the ability to verify claims proactively
tools = [CredexVerifyTool(api_key="your-key")]
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)

# Agent can now decide to verify claims during reasoning
result = agent.run("Is it true that XRPL processes 1500 TPS? Verify this claim.")

LangSmith Tracer

from credexai_langchain.langchain import CredexVerifyTracer

# Logs verification results alongside LangSmith traces
tracer = CredexVerifyTracer(api_key="your-key", project_name="my-project")
agent = initialize_agent(tools, llm, callbacks=[tracer])

result = agent.run("Summarize the latest DeFi trends.")

# Access trace data
print(tracer.traces)
print(tracer.get_langsmith_metadata())

CrewAI Integration

from credexai_langchain.crewai import CredexVerifyTool
from crewai import Agent, Task, Crew

verify_tool = CredexVerifyTool(api_key="your-key")

researcher = Agent(
    role="Research Analyst",
    goal="Produce verified research reports",
    tools=[verify_tool],
)

task = Task(
    description="Research and verify claims about XRPL governance.",
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()

Async Support

import asyncio
from credexai_langchain import averify, CredexAILangChainWrapper

# Async verification
async def main():
    result = await averify("The speed of light is 299,792,458 m/s.")
    print(result.verdict)
    print(result.txid)

asyncio.run(main())

# Async wrapper
verified_agent = CredexAILangChainWrapper(agent_executor)
result = await verified_agent.arun("Analyze market conditions.")

XRPL Provenance Certificates

Every verification anchors a SHA-256 hash on the XRP Ledger:

from credexai_langchain import verify

result = verify("Important claim that needs provenance.")

# The TXID is your provenance certificate
print(f"TXID: {result.txid}")
print(f"Hash: {result.content_hash}")
print(f"Explorer: {result.provenance_url}")

# Anyone can verify:
# 1. Hash the verified_output with SHA-256
# 2. Look up the TXID on XRPL
# 3. Confirm the memo contains the matching hash

Direct XRPL Anchoring

from credexai_langchain.xrpl_anchor import XRPLAnchor, compute_content_hash

# Compute hash
content_hash = compute_content_hash("My verified content")

# Anchor on XRPL
anchor = XRPLAnchor(use_testnet=True)
txid = anchor.submit_hash(content_hash, metadata={"source": "my-agent"})
print(f"Provenance: https://testnet.xrpl.org/transactions/{txid}")

Verification Result Structure

VerificationResult(
    verified_output="The original output text",       # str
    verdict=Verdict.TRUE,                             # TRUE/FALSE/MIXED/UNVERIFIABLE
    confidence=0.95,                                  # float (0.0-1.0)
    txid="A1B2C3D4E5F6...",                          # XRPL transaction hash
    verifier_count=5,                                 # int
    timestamp="2024-01-15T10:30:00+00:00",           # ISO 8601
    content_hash="abc123...",                         # SHA-256 hex
    sub_claims=[SubClaim(...)],                       # Decomposed claims
    verifier_results=[VerifierResult(...)],           # Individual verifier outputs
    explanation="Consensus reached with 80% agreement...",
    request_id="uuid-here",
    usage=UsageInfo(calls_used=42, calls_remaining=958),
)

Configuration

from credexai_langchain import verify

result = verify(
    "Claim to verify",
    api_key="your-key",                    # Or set CREDEXAI_API_KEY env var
    base_url="https://credexai.live/marketplace-api",  # Default
    timeout=30.0,                          # Request timeout (seconds)
    verifier_count=5,                      # Number of verifiers (1-10)
    anchor_on_xrpl=True,                   # Enable XRPL anchoring
)

Environment Variables

Variable Description Default
CREDEXAI_API_KEY API key for authentication Required
CREDEXAI_BASE_URL API base URL override https://credexai.live/marketplace-api
CREDEXAI_XRPL_WALLET_SEED XRPL wallet seed for anchoring Auto-generated (testnet)

Error Handling

from credexai_langchain import verify
from credexai_langchain.exceptions import (
    CredexAIError,
    AuthenticationError,
    RateLimitError,
    TimeoutError,
    XRPLAnchorError,
)

try:
    result = verify("claim")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after: {e.retry_after}s")
except TimeoutError:
    print("Request timed out")
except XRPLAnchorError as e:
    print(f"XRPL anchoring failed: {e.message}")
except CredexAIError as e:
    print(f"SDK error: {e.message}")

API Endpoints

Endpoint Method Description
/verify/claim POST General claim verification
/verify/polymarket/claim POST Polymarket wallet claim verification

Publishing to PyPI

# Build
python -m build

# Upload to PyPI
twine upload dist/*

# Upload to Test PyPI first
twine upload --repository testpypi dist/*

Development

# Clone
git clone https://github.com/credexai/credexai-langchain.git
cd credexai-langchain

# Install with dev dependencies
pip install -e ".[dev,all]"

# Run tests
pytest tests/ -v

# Type checking
mypy credexai_langchain/

# Linting
ruff check credexai_langchain/

License

MIT License — see LICENSE for details.


Links

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

credexai_langchain-0.1.1.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

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

credexai_langchain-0.1.1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: credexai_langchain-0.1.1.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for credexai_langchain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bee9b5f688dd0ae7c4d39352ea6e3df506b65a27cdaa8fa442b19c3bdbbfc54e
MD5 065fec9a22320b997729a0480451fca7
BLAKE2b-256 f1c1e0d993a61934d93d99fd31deb76fdbfed1583c668b47e61155fc275ca536

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for credexai_langchain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c8f27236c876dc5ca7085fa2877d4f5589aec22a9d9e8450975c8dd6f2d9d34f
MD5 5d2fc5c032f96d899dc26f22d2f51828
BLAKE2b-256 717b4203552207ad8449dd9ffb07dca5a19e860345eb7b2802adef19f9d018e4

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