# @aerograph/adapter-langchain

> LangChain adapter for emitting AeroGraph traces from agent workflows.

Latest version **0.3.1** (published 2026-07-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @aerograph/adapter-langchain
pnpm add @aerograph/adapter-langchain
yarn add @aerograph/adapter-langchain
bun add @aerograph/adapter-langchain
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2026-07-23 |
| First published | 2026-05-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 37.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | sgcpu |
| Keywords | ai, adapter, langchain, trace, observability |

## Links

- npm: https://www.npmjs.com/package/@aerograph/adapter-langchain
- Repository: https://github.com/SGcpu/AeroGraph
- Homepage: https://github.com/SGcpu/AeroGraph#readme
- Issues: https://github.com/SGcpu/AeroGraph/issues
- npm.io page: https://npm.io/package/@aerograph/adapter-langchain

## Dependencies (4)

- [langchain](https://npm.io/package/langchain.md) ^0.3.0
- [@aerograph/sdk](https://npm.io/package/@aerograph/sdk.md) 0.3.0
- [@langchain/core](https://npm.io/package/@langchain/core.md) ^1.2.2
- [@aerograph/contracts](https://npm.io/package/@aerograph/contracts.md) 0.3.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2026-07-23
- 0.3.0 — 2026-06-30
- 0.2.1 — 2026-06-10
- 0.2.0 — 2026-06-03
- 0.1.0 — 2026-05-24

## README

# @aerograph/adapter-langchain

This adapter bridges LangChain.js workflows into the AeroGraph.

## Deterministic Mapping

LangChain's complex callback hierarchy is deterministically mapped to the minimal Flight Recorder contracts as follows:

| LangChain Callback | AFR Event Kind | Metadata Mapped |
|---|---|---|
| `handleLLMStart` | `prompt` | messages/prompts, `model.name`, parentSpanId, runId -> spanId |
| `handleLLMEnd` | `response` | generations, streaming metrics, `usage` tokens, `durationMs`, runId -> spanId |
| `handleLLMError` | `error` | error message, `durationMs`, runId -> spanId |
| `handleToolStart` | `tool_call` | input string/JSON, runId -> spanId |
| `handleToolEnd` | `tool_result` | output, `durationMs`, runId -> spanId |
| `handleToolError` | `error` | error message, `durationMs`, runId -> spanId |
| `handleChainStart` / `handleChainEnd` | `note` | Detects LangGraph node boundaries (`kind: "langgraph_node"`), capturing `state_before` (Inputs) and `state_update` (Outputs) |

## Installation

```bash
npm install @aerograph/adapter-langchain @aerograph/sdk
```

*(Requires Node.js >= 18.18.0)*

## Quick Start

The adapter provides a callback handler that you inject into your LangChain invocations.

```typescript
import { FlightRecorder } from "@aerograph/sdk";
import { AeroGraphCallbackHandler } from "@aerograph/adapter-langchain";
import { ChatOpenAI } from "@langchain/openai";

const recorder = new FlightRecorder({
  endpoint: "http://localhost:4317",
  actor: { id: "my-langchain-agent" }
});

const handler = new AeroGraphCallbackHandler(recorder);
const model = new ChatOpenAI({ modelName: "gpt-4" });

// The handler automatically maps LangChain callbacks to AeroGraph events
await model.invoke("Hello, how are you?", {
  callbacks: [handler]
});
```

## Supported Features
- LLM Call Tracking (Prompts & Responses)
- Streaming Telemetry (TTFT, tokens/sec)
- RAG Retriever Document Payloads
- Tool Calls & Results
- LangGraph State Snapshots

## License
Apache-2.0
| `handleAgentAction`| *(ignored)* | Caught by tool/llm events |

For Phase 1 MVP, we focus strictly on LLMs and Tools plus lightweight chain boundary notes to keep the graph comprehensible.

---
_Source: https://npm.io/package/@aerograph/adapter-langchain · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
