# 🦜 LangChain Integration Guide: AgentOps Cockpit

This guide explains how to use the **AgentOps Cockpit** as a First-Class integrated provider within the LangChain ecosystem. By using the `CockpitCallbackHandler`, you can automatically enforce the **Sovereign Standard (v2.0.4)** on any LangChain or LangGraph workflow.

## 🚀 Quick Start

### 1. Installation
Install the cockpit with LangChain support:
```bash
pip install agentops-cockpit[langchain]
```

### 2. Integration
Add the `CockpitCallbackHandler` to your LLM or Chain:

```python
from langchain_openai import ChatOpenAI
from agent_ops_cockpit.integrations.langchain import CockpitCallbackHandler

# 1. Initialize the Cockpit Handler
cockpit_handler = CockpitCallbackHandler(app_name="my-cool-agent")

# 2. Attach to LLM or Chain
llm = ChatOpenAI(callbacks=[cockpit_handler])

# 3. Run your chain - Auditing happens in the background!
llm.invoke("What is the ROI of an AI agent?")
```

## 🛡️ Sovereign Protections (v2.0.4)

The integration automatically activates three SME personas:
1. **SecOps Hub**: Detects PII and sensitive data leakage in prompts.
2. **FinOps Hub**: Monitors token density and suggests context caching for large prompts.
3. **Architect Hub**: Flags high-risk or destructive tool calls (e.g., `delete_table`) that lack a HITL gate.

## 📊 Viewing Results
Audit findings from the LangChain traces are automatically added to the **Evidence Lake**. Use the Cockpit CLI to view the health of your fleet:

```bash
ops report --view-lake
```

---

## 🌎 How to Publish as an Official LangChain Provider

To get **AgentOps Cockpit** listed on the official [LangChain Integration Page](https://docs.langchain.com/oss/python/integrations/providers), follow these steps:

### Phase 1: Create a Partner Package (Optional but Preferred)
LangChain prefers partner-specific packages (e.g., `langchain-cockpit`).
1. Move the `src/agent_ops_cockpit/integrations/langchain.py` logic to a new repo following the [LangChain Integration Template](https://github.com/langchain-ai/langchain-integration-template).
2. Publish to PyPI as `langchain-cockpit`.

### Phase 2: PR to LangChain Documentation
1. Clone the `langchain` repository.
2. Add a new file `docs/docs/integrations/providers/agentops_cockpit.md`.
3. Link to your package and describe the governance capabilities.
4. Submit a Pull Request with the title `docs: add AgentOps Cockpit as a governance provider`.

### Phase 3: Community Listing
Submit a request to the [LangChain Ecosystem](https://github.com/langchain-ai/langchain/issues) to be listed in the "Governance & Ops" category.

---
*Generated by the AgentOps Cockpit. Sovereign Integration Division (v2.0.4).*
