@prefactor/packages/langchain
Prefactor TypeScript SDK / @prefactor/packages/langchain
@prefactor/packages/langchain
Section titled “@prefactor/packages/langchain”LangChain adapter package exposing Prefactor initialization helpers and middleware.
@prefactor/langchain overview
Section titled “@prefactor/langchain overview”@prefactor/langchain adds Prefactor tracing to LangChain middleware so agent, model,
chain, and tool activity is captured automatically.
The package initializes once with init, then captures model and tool traces through
LangChain middleware hooks. It also exposes withSpan for custom orchestration spans and
getTracer for advanced instrumentation patterns.
Quick start: initialize and attach middleware
Section titled “Quick start: initialize and attach middleware”import { init } from '@prefactor/langchain';import { createAgent } from 'langchain';
const prefactor = init({ transportType: 'http', httpConfig: { apiUrl: 'https://api.prefactor.ai', apiToken: process.env.PREFACTOR_API_TOKEN!, agentIdentifier: 'support-bot-v1', },});
const agent = createAgent({ model: 'claude-sonnet-4-5-20250929', tools: [], middleware: [prefactor],});Example: trace custom logic
Section titled “Example: trace custom logic”import { withSpan } from '@prefactor/langchain';
await withSpan( { name: 'rank-documents', spanType: 'langchain:chain', inputs: { count: 12 }, }, async () => { // your custom chain logic });