Metadata-Version: 2.4
Name: credexai-langchain
Version: 0.1.0
Summary: CredexAI LangChain SDK — Consensus verification layer for AI agents with XRPL provenance certificates.
Project-URL: Homepage, https://credexai.live
Project-URL: Documentation, https://docs.credexai.live/sdk
Project-URL: Repository, https://github.com/credexai/credexai-langchain
Project-URL: Issues, https://github.com/credexai/credexai-langchain/issues
Project-URL: Changelog, https://github.com/credexai/credexai-langchain/blob/main/CHANGELOG.md
Author-email: CredexAI <sdk@credexai.live>
License-Expression: MIT
Keywords: ai-agents,consensus,credexai,crewai,fact-checking,langchain,provenance,verification,xrpl
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx>=0.24.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: all
Requires-Dist: crewai>=0.1.0; extra == 'all'
Requires-Dist: langchain-core>=0.1.0; extra == 'all'
Requires-Dist: xrpl-py>=2.0.0; extra == 'all'
Provides-Extra: crewai
Requires-Dist: crewai>=0.1.0; extra == 'crewai'
Provides-Extra: dev
Requires-Dist: build>=0.10.0; extra == 'dev'
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Requires-Dist: twine>=4.0.0; extra == 'dev'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.1.0; extra == 'langchain'
Provides-Extra: xrpl
Requires-Dist: xrpl-py>=2.0.0; extra == 'xrpl'
Description-Content-Type: text/markdown

# credexai-langchain

**Consensus verification layer for AI agents with XRPL provenance certificates.**

[![PyPI version](https://img.shields.io/pypi/v/credexai-langchain.svg)](https://pypi.org/project/credexai-langchain/)
[![Python](https://img.shields.io/pypi/pyversions/credexai-langchain.svg)](https://pypi.org/project/credexai-langchain/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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

```bash
# 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

```python
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

```python
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:

```bash
export CREDEXAI_API_KEY="your-api-key"
```

```python
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)

```python
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)

```python
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

```python
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

```python
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

```python
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:

```python
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

```python
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

```python
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

```python
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

```python
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

```bash
# Build
python -m build

# Upload to PyPI
twine upload dist/*

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

---

## Development

```bash
# 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](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
