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.
What is CredexAI?
CredexAI provides a consensus verification layer for AI agent outputs. Every verification:
- Routes to 5 independent AI verifiers — no single point of failure
- Cross-references against live data — real-time fact-checking
- Anchors on the XRP Ledger — immutable provenance certificate via TXID
- 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
- Website: https://credexai.live
- Documentation: https://docs.credexai.live/sdk
- API Reference: https://credexai.live/marketplace-api/docs
- GitHub: https://github.com/credexai/credexai-langchain
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file credexai_langchain-0.1.0.tar.gz.
File metadata
- Download URL: credexai_langchain-0.1.0.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0f9da596b4605e632d6d0a23f1b2890ce930267bfb77d2e8619dd111a445b1c
|
|
| MD5 |
f198810a4a1625f73e0ff7be0bdec2f6
|
|
| BLAKE2b-256 |
39106a8d5b012a76f44d93809dfd1b93610ed614a7cd1c123fc9d25cc4fa0357
|
File details
Details for the file credexai_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: credexai_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cadc37c40a410281b1b7782f37c7280a0f64b2d69d02f07c9978866e2df4fd07
|
|
| MD5 |
ecda727909a689408459ed0e592211ee
|
|
| BLAKE2b-256 |
43f8bd7734fad67b67ae79ff033aadb973dcbb3e5a2b8407ab47b9e33e692756
|