Metadata-Version: 2.5
Name: attestify-langchain
Version: 0.1.4
Summary: LangChain toolkit for Attestify — governed AI loop execution, receipts, and audit trails
Project-URL: Homepage, https://attestifyos.com
Project-URL: Repository, https://github.com/attestifyagent/attestify-os
Project-URL: Documentation, https://attestifyos.com/docs
Project-URL: Bug Tracker, https://github.com/attestifyagent/attestify-os/issues
License: MIT
Keywords: ai-agents,attestify,governance,langchain,receipts,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'
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, and x402-native payments on Base.

## Install

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

Requires Python ≥ 3.9 and `langchain-core ≥ 0.1`.

## 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.create_tools()

# 2. Build the agent
llm    = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ["system", toolkit.system_prompt()],
    ["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 |

## Getting Your API Key

1. Subscribe at [attestifyos.com/pricing](https://attestifyos.com/pricing)
2. Your `att_live_...` key arrives by email immediately after payment
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
)
```

## 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.create_tools(),
    state_modifier=toolkit.system_prompt(),
)

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

## 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 included `system_prompt()` instructs the agent to relay this gracefully to the user.

## Links

- [Attestify OS](https://attestifyos.com)
- [Pricing](https://attestifyos.com/pricing)
- [Dashboard](https://attestifyos.com/dashboard)
- [Python SDK (attestify-sdk)](../python/)
- [MCP Package](../../mcp-package/)
- [GitHub](https://github.com/attestifyagent/attestify-os)
