Optional logger: LDLoggerOptional Private _llmProtected Optional Readonly loggerStatic Private _ensureAutomatically patches the ESM LangChain module for OpenTelemetry tracing when a TracerProvider is active and @traceloop/instrumentation-langchain is installed.
OpenTelemetry instrumentations auto-patch CJS require() calls, but this provider loads LangChain via ESM import, which bypasses those hooks. This method bridges that gap by calling manuallyInstrument() on the ESM module.
Optional logger: LDLoggerOptional Static convertConvert LaunchDarkly messages to LangChain messages. This helper method enables developers to work directly with LangChain message types while maintaining compatibility with LaunchDarkly's standardized message format.
Static createStatic factory method to create a LangChain AIProvider from an AI configuration.
Optional logger: LDLoggerOptional Static createAIMetricsCreate AI metrics information from a LangChain provider response. This method extracts token usage information and success status from LangChain responses and returns a LaunchDarkly AIMetrics object.
The response from the LangChain model
LDAIMetrics with success status and token usage
Use getAIMetricsFromResponse() instead.
Static createCreate a LangChain model from an AI configuration. This public helper method enables developers to initialize their own LangChain models using LaunchDarkly AI configurations.
The LaunchDarkly AI configuration
A Promise that resolves to a configured LangChain BaseChatModel
Static getAIMetricsGet AI metrics from a LangChain provider response. This method extracts token usage information and success status from LangChain responses and returns a LaunchDarkly AIMetrics object.
The response from the LangChain model
LDAIMetrics with success status and token usage
// Use with tracker.trackMetricsOf for automatic tracking
const response = await tracker.trackMetricsOf(
LangChainProvider.getAIMetricsFromResponse,
() => llm.invoke(messages)
);
Static mapGenerated using TypeDoc
LangChain implementation of AIProvider. This provider integrates LangChain models with LaunchDarkly's tracking capabilities.