Metadata-Version: 2.5
Name: attestify-langchain
Version: 0.2.0
Summary: LangChain toolkit for Attestify — governed AI loop execution, receipts, audit trails, and Attestify Trust (no-wallet agent identity + signed evidence)
Project-URL: Homepage, https://attestifyos.com/trust
Project-URL: Repository, https://github.com/attestifyagent/attestify-langchain
Project-URL: Documentation, https://attestifyos.com/docs#trust
Project-URL: Bug Tracker, https://github.com/attestifyagent/attestify-langchain/issues
License: MIT
Keywords: agent-identity,ai-agents,attestify,governance,langchain,receipts,trust,x402
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
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: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Requires-Dist: langchain-core>=0.1.0
Provides-Extra: dev
Requires-Dist: langchain-openai; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-asyncio; extra == 'dev'
Provides-Extra: trust
Requires-Dist: cryptography>=41.0.0; extra == 'trust'
Description-Content-Type: text/markdown

# attestify-langchain

Official LangChain toolkit for [Attestify](https://attestifyos.com) — governed AI loop execution with signed receipts, audit trails, governance-docs semantic search, x402-native payments on Base, and [Attestify Trust](https://attestifyos.com/trust) (no-wallet agent identity + signed evidence).

## Install

```bash
pip install attestify-langchain
```

Requires Python ≥ 3.9 and `langchain-core ≥ 0.1`. Trust tools additionally need `cryptography` — install with `pip install attestify-langchain[trust]`; everything else works without it.

## Quick Start

```python
import os
from attestify_langchain import AttestifyToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate

# 1. Create the toolkit with your API key
toolkit = AttestifyToolkit(api_key=os.environ["ATTESTIFY_API_KEY"])
tools   = toolkit.get_tools()

# 2. Build the agent
llm    = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ["system", "You are an assistant with access to Attestify tools for governed execution and receipts."],
    ["placeholder", "{chat_history}"],
    ["human", "{input}"],
    ["placeholder", "{agent_scratchpad}"],
])
agent    = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# 3. Run it
result = executor.invoke({"input": "How many runs have I used this month?"})
print(result["output"])
```

## Available Tools

| Tool | Description | Plan |
|---|---|---|
| `attestify_run_loop` | Submit a governed task to the loop router | All |
| `attestify_get_dashboard` | Run count, quota, plan tier, recent receipts | Builder+ |
| `attestify_get_recent_loops` | List recent loop receipts | All |
| `attestify_get_receipt` | Fetch a single receipt by `loop_id` | All |
| `attestify_query_governance_docs` | Semantic search over Attestify's governance docs | All |
| `attestify_get_control_tower` | Live governance data (Enterprise only) | Enterprise |
| `attestify_trust_submit_evidence` | Sign and submit evidence of real work — free, no wallet | All (Trust configured) |
| `attestify_trust_verify` | Independently verify any Trust receipt by ID | Public, no key |

## Getting Your API Key

1. Subscribe at [attestifyos.com/pricing](https://attestifyos.com/pricing) — or register free for Trust-only use at [attestifyos.com/trust](https://attestifyos.com/trust)
2. Your `att_live_...` key arrives by email immediately after payment (or instantly for Trust's free tier)
3. Set it as an environment variable: `export ATTESTIFY_API_KEY=att_live_...`

## Toolkit Options

```python
toolkit = AttestifyToolkit(
    api_key="att_live_...",
    base_url="https://attestifyos.com",           # default
    timeout_s=60,                                 # default
    max_retries=2,                                # default
    include_control_tower=False,                  # set False for Builder-plan agents
    include_rag=False,                            # set False to omit the governance-docs search tool
    trust_agent_id="agt_...",                      # or set TRUST_AGENT_ID
    trust_private_key="...",                       # or set TRUST_PRIVATE_KEY
    include_trust=False,                           # set False to omit the Trust tools entirely
)
```

## Attestify Trust — no-wallet agent identity + signed evidence

A separate concern from Router execution above: no x402, no lanes, no spend. Register once, then every agent run can sign proof of what it actually did.

```python
from attestify_langchain import provision_trust_agent, AttestifyToolkit
import os

# ONE TIME, outside any agent run — never call this per-invocation, and
# never let the agent call it itself. A fresh identity per run breaks the
# agent's own verified-active streak and adds noise to Attestify's public
# census instead of a real, citable number.
creds = provision_trust_agent(
    api_key=os.environ["ATTESTIFY_API_KEY"],
    display_name="Research Agent",
    framework="langchain",
)
print(f"Store these — TRUST_AGENT_ID={creds['agent_id']}  TRUST_PRIVATE_KEY={creds['private_key']}")

# From then on, with those two env vars set:
toolkit = AttestifyToolkit(api_key=os.environ["ATTESTIFY_API_KEY"])
tools   = toolkit.get_tools()  # includes attestify_trust_submit_evidence and
                                # attestify_trust_verify automatically
```

The private key is bound once at `AttestifyToolkit` construction — it's never a tool parameter, so it never enters the LLM's own context or a transcript.

## Callback Handler

Log loop completions (loop_id, cost, verified) automatically:

```python
from attestify_langchain import AttestifyCallbackHandler

handler  = AttestifyCallbackHandler(
    on_run_complete=lambda loop_id, cost, verified:
        print(f"Loop {loop_id} cost {cost} USDC verified={verified}")
)
executor = AgentExecutor(agent=agent, tools=tools, callbacks=[handler])
```

## LangGraph Example

```python
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from attestify_langchain import AttestifyToolkit
import os

toolkit = AttestifyToolkit(api_key=os.environ["ATTESTIFY_API_KEY"])
agent   = create_react_agent(
    ChatOpenAI(model="gpt-4o"),
    toolkit.get_tools(),
)

for chunk in agent.stream({"messages": [("human", "Submit a task: summarise Q2 revenue")]}):
    print(chunk)
```

(For a dedicated LangGraph package with its own state-graph node, see [attestify-langgraph](https://github.com/attestifyagent/attestify-langgraph) instead.)

## Plan Gating

All plan enforcement is server-side. If an agent calls `attestify_get_control_tower` on a Builder plan, it receives:

```json
{"error": "Enterprise plan required to access Control Tower.", "status": 403}
```

The agent can relay this directly to the user without any client-side logic.

## Links

- [Attestify OS](https://attestifyos.com)
- [Attestify Trust](https://attestifyos.com/trust)
- [Pricing](https://attestifyos.com/pricing)
- [Dashboard](https://attestifyos.com/dashboard)
- [Python SDK (attestify-sdk)](https://github.com/attestifyagent/attestify-sdk-python)
- [GitHub](https://github.com/attestifyagent/attestify-langchain)
