Metadata-Version: 2.4
Name: fail-kit
Version: 1.5.0
Summary: F.A.I.L. Kit adapter for LangChain agents - Receipts, auditing, and policy enforcement
Author: F.A.I.L. Kit Contributors
License: MIT
Project-URL: Homepage, https://github.com/resetroot99/The-FAIL-Kit
Project-URL: Documentation, https://github.com/resetroot99/The-FAIL-Kit/tree/main/middleware/langchain
Project-URL: Repository, https://github.com/resetroot99/The-FAIL-Kit
Project-URL: Issues, https://github.com/resetroot99/The-FAIL-Kit/issues
Project-URL: Changelog, https://github.com/resetroot99/The-FAIL-Kit/blob/main/CHANGELOG.md
Keywords: ai,agents,langchain,auditing,testing,receipts,llm,openai,anthropic,fail-kit
Classifier: Development Status :: 5 - Production/Stable
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 :: Testing
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: langchain>=0.1.0
Requires-Dist: langchain-core>=0.1.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.100.0; extra == "fastapi"
Requires-Dist: uvicorn>=0.23.0; extra == "fastapi"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: httpx>=0.24.0; extra == "dev"
Requires-Dist: langchain-openai>=0.0.5; extra == "dev"
Provides-Extra: langgraph
Requires-Dist: langgraph>=0.0.20; extra == "langgraph"
Provides-Extra: all
Requires-Dist: fail-kit-langchain[fastapi,langgraph]; extra == "all"

# fail-kit-langchain

> **v1.5.0** - LangChain adapter for F.A.I.L. Kit (Python)

Drop-in adapter for integrating LangChain agents with the F.A.I.L. Kit audit framework.

## Installation

```bash
pip install fail-kit-langchain
```

With FastAPI support:
```bash
pip install fail-kit-langchain[fastapi]
```

With LangGraph support:
```bash
pip install fail-kit-langchain[langgraph]
```

All extras:
```bash
pip install fail-kit-langchain[all]
```

## Quick Start

```python
from fastapi import FastAPI
from langchain.agents import AgentExecutor
from fail_kit_langchain import (
    create_fail_kit_endpoint,
    ReceiptGeneratingTool
)

app = FastAPI()

# Define tools with automatic receipt generation
class EmailTool(ReceiptGeneratingTool):
    name = "email_sender"
    description = "Send an email"
    
    def _execute(self, to: str, subject: str, body: str):
        send_email(to, subject, body)
        return {"status": "sent", "message_id": "msg_123"}

# Create agent
tools = [EmailTool()]
agent_executor = AgentExecutor(agent=agent, tools=tools)

# Add F.A.I.L. Kit endpoint
app.include_router(
    create_fail_kit_endpoint(agent_executor),
    prefix="/eval"
)
```

## Features

- ✅ Automatic receipt generation from tool executions
- ✅ Full RECEIPT_SCHEMA.json compliance
- ✅ Native LangGraph support
- ✅ Async/await support
- ✅ Custom metadata in receipts
- ✅ Error handling with failure receipts
- ✅ SHA256 hashing for verification

## API Reference

### `create_fail_kit_endpoint(agent_executor, config=None)`

Creates a FastAPI router with the `/run` endpoint.

**Parameters:**
- `agent_executor`: LangChain AgentExecutor instance
- `config`: Optional FailKitConfig

**Returns:** APIRouter

### `ReceiptGeneratingTool`

Base class for tools with automatic receipt generation.

**Methods:**
- `_execute(*args, **kwargs)`: Override with your tool logic
- `get_receipts()`: Get all receipts
- `clear_receipts()`: Clear receipt history

### `extract_receipts_from_agent_executor(executor, result, config=None)`

Extract receipts from AgentExecutor intermediate steps.

### `wrap_tool_with_receipts(tool)`

Wrap a legacy LangChain tool to generate receipts.

## Examples

See [examples/langchain-python/](../../../examples/langchain-python/) for a complete working example.

## Testing

```bash
pytest
```

## Related

- [@fail-kit/core](https://www.npmjs.com/package/@fail-kit/core) - Core receipt generation library (npm)
- [F.A.I.L. Kit CLI](https://github.com/resetroot99/The-FAIL-Kit) - Command-line audit tool
- [F.A.I.L. Kit VS Code Extension](https://marketplace.visualstudio.com/items?itemName=AliJakvani.fail-kit-vscode) - IDE integration

## License

MIT License - See [LICENSE](../../../LICENSE.txt)
