Metadata-Version: 2.4
Name: langchain-kredo
Version: 0.1.0
Summary: LangChain integration for the Kredo agent attestation protocol
Project-URL: Homepage, https://aikredo.com
Project-URL: Repository, https://github.com/jimmotes2024/kredo
Project-URL: Documentation, https://aikredo.com
Author: Jim Motes, Vanguard
License-Expression: MIT
License-File: LICENSE
Keywords: agents,attestation,ed25519,kredo,langchain,trust
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Requires-Dist: kredo>=0.4.0
Requires-Dist: langchain-core<1.0.0,>=0.3.0
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Description-Content-Type: text/markdown

# langchain-kredo

LangChain integration for the [Kredo](https://aikredo.com) agent attestation protocol.

Check agent trust, search attestations, enforce policy, and create signed attestations — all from your LangChain pipeline.

## Install

```bash
pip install langchain-kredo
```

## Quick Start

```python
from langchain_kredo import KredoSigningClient, KredoTrustGate

# Initialize with Ed25519 signing key (hex seed)
client = KredoSigningClient(
    signing_key="your-hex-seed",
    name="my-pipeline",
    agent_type="agent",
)

# Check trust before delegating to an agent
gate = KredoTrustGate(client, min_score=0.3, block_warned=True)
result = gate.check("ed25519:agent-pubkey-here")
if result.passed:
    print(f"Agent trusted (score: {result.score})")
```

## Components

### KredoSigningClient

Wraps the Kredo Discovery API with Ed25519 signing. Read operations query `api.aikredo.com`. Write operations build Pydantic models, sign with your key, and submit.

```python
client = KredoSigningClient(
    signing_key=sk,           # SigningKey, bytes, hex string, or env var
    name="my-agent",
    agent_type="agent",       # "agent" or "human"
)

# Read
profile = client.get_profile("ed25519:...")
results = client.search(domain="security", min_proficiency=3)
taxonomy = client.get_taxonomy()

# Write (requires signing key)
client.register()
client.attest_skill(
    subject_pubkey="ed25519:...",
    domain="security",
    skill="vulnerability_assessment",
    proficiency=4,
    context="Demonstrated expert-level vuln assessment in CTF",
)
```

Key resolution order: `signing_key` param > `KREDO_PRIVATE_KEY` env var > read-only mode.

### LangChain Tools

Four tools for agent pipelines:

```python
from langchain_kredo import (
    KredoCheckTrustTool,
    KredoSearchAttestationsTool,
    KredoSubmitAttestationTool,
    KredoGetTaxonomyTool,
)

tools = [
    KredoCheckTrustTool(client=client),
    KredoSearchAttestationsTool(client=client),
    KredoSubmitAttestationTool(client=client),
    KredoGetTaxonomyTool(client=client),
]
```

| Tool | Name | Purpose |
|------|------|---------|
| `KredoCheckTrustTool` | `kredo_check_trust` | Check agent reputation + skills + warnings |
| `KredoSearchAttestationsTool` | `kredo_search_attestations` | Find agents by skill/domain/proficiency |
| `KredoSubmitAttestationTool` | `kredo_submit_attestation` | Sign and submit skill attestation |
| `KredoGetTaxonomyTool` | `kredo_get_taxonomy` | Browse valid domains/skills |

### KredoCallbackHandler

Tracks chain execution and builds attestation evidence:

```python
from langchain_kredo import KredoCallbackHandler

handler = KredoCallbackHandler()
chain.invoke(input, config={"callbacks": [handler]})

for record in handler.get_records():
    print(record.build_evidence_context())
    # Chain abc-123
    # Duration: 1500ms
    # Tools used: 3
    # Success rate: 100%
    # ...

    # Use evidence in an attestation
    client.attest_skill(
        subject_pubkey="ed25519:...",
        domain="security",
        skill="incident_response",
        proficiency=3,
        context=record.build_evidence_context(),
        artifacts=record.build_artifacts(),
    )
```

The handler never submits automatically. You decide when and what to attest.

### KredoTrustGate

Policy enforcement for agent selection:

```python
from langchain_kredo import KredoTrustGate

gate = KredoTrustGate(client, min_score=0.3, block_warned=True)

# Non-throwing check
result = gate.check("ed25519:...")
if result.passed:
    ...

# Throwing enforcement
result = gate.enforce("ed25519:...")  # raises InsufficientTrustError

# Decorator
@gate.require(min_score=0.7)
def sensitive_operation(pubkey: str):
    ...

# Select best candidate
best = gate.select_best(
    ["ed25519:agent-a", "ed25519:agent-b"],
    domain="security",
)
```

## Design Decisions

- **No auto-attestation** — The callback handler collects evidence but never submits. Attestations are cryptographic claims with reputation consequences.
- **`attest_warning` not a tool** — Behavioral warnings are too serious for LLM autonomy. Available on the client but not exposed as a LangChain tool.
- **No local store** — SDK uses the Discovery API only. LangChain developers query `api.aikredo.com`, not a local database.
- **Sync with async passthrough** — Kredo uses stdlib urllib (sync). Async tool methods delegate to sync. Acceptable for v0.1.

## Development

```bash
cd langchain-kredo
pip install -e ".[dev]"
pytest tests/ -v
```

## License

MIT
