> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmuster.io/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain / LangGraph

> Automatic monitoring of LangChain and LangGraph agents via the muster connector.

## How it works

The LangChain connector monitors your agents in two modes:

**LangSmith mode (zero code changes):** If your team is already tracing to LangSmith, the connector polls the LangSmith API for completed runs. No changes to your agent code.

**Callback mode (real-time):** Your team adds `MusterCallbackHandler` to your chain config. Executions are sent to muster in real time as they complete.

Elitery deploys and manages the connector. Your developers choose which mode suits them.

***

## Option A — LangSmith mode (recommended, zero code changes)

If you're already sending traces to LangSmith:

1. Provide Elitery with your LangSmith API key during onboarding
2. Elitery deploys the connector — it immediately starts discovering agents and streaming executions
3. No changes to your agent code

The connector polls LangSmith every 30 seconds for new completed runs.

**Required credentials for Elitery:**

```
LANGSMITH_API_KEY=ls__...
LANGSMITH_PROJECT=your-project-name   # optional, defaults to all projects
```

***

## Option B — Callback mode (real-time, one line of code)

If you're not using LangSmith, or want real-time data without the 30-second polling delay:

```python theme={null}
from muster.callback import MusterCallbackHandler

# Add the callback to your chain or agent
result = chain.invoke(
    {"input": user_input},
    config={"callbacks": [MusterCallbackHandler()]}
)
```

Set these env vars in your agent's environment:

```bash theme={null}
MUSTER_BACKEND_URL=https://api.yourcompany.getmuster.io
MUSTER_CONNECTOR_ID=<your-connector-id>   # provided by Elitery
```

The callback captures:

* Input and output data
* Token usage (prompt + completion tokens)
* Model name
* Execution status (success/error)
* Start and end timestamps

It fires and forgets — never blocks your chain execution.

***

## What muster does automatically

Once executions arrive (via either mode), muster's check inference engine:

1. Matches your agent name to a check category (financial, legal, risk, etc.)
2. Inspects output field names for additional check suggestions
3. Emits a quality signal with inferred pass/fail checks
4. Surfaces results in your Health Heatmap and Executive dashboard

***

## Adding precise checks with the SDK

For agents where business rules matter (arithmetic validation, required fields, decision enums), add the SDK alongside the connector:

```python theme={null}
import httpx, threading

def muster_emit(job_id: str, checks: list):
    def _send():
        try:
            httpx.post(
                f"{MUSTER_BACKEND_URL}/api/v1/jobs/{job_id}/quality",
                json={"agent_id": "contract-review-agent", "checks": checks},
                timeout=2.0,
            )
        except Exception:
            pass
    threading.Thread(target=_send, daemon=True).start()

# After your chain runs:
muster_emit(job_id, checks=[
    {"check_id": "output_not_empty",  "severity": "HIGH", "passed": bool(result)},
    {"check_id": "risk_flag_present", "severity": "HIGH", "passed": "risk_flags" in result},
    {"check_id": "source_cited",      "severity": "HIGH", "passed": "source" in result},
])
```

See the [Signal integration guide →](/sdk/overview) for full details.
