Skip to content

feat: replace LangChainProvider with Runner protocol implementation (AIC-2388)#1338

Merged
jsonbailey merged 13 commits intonext-ai-releasefrom
jb/aic-2388/js-langchain-runner
May 6, 2026
Merged

feat: replace LangChainProvider with Runner protocol implementation (AIC-2388)#1338
jsonbailey merged 13 commits intonext-ai-releasefrom
jb/aic-2388/js-langchain-runner

Conversation

@jsonbailey
Copy link
Copy Markdown
Contributor

@jsonbailey jsonbailey commented Apr 28, 2026

Summary

Replaces the legacy LangChainProvider extension model with the Runner protocol for the LangChain provider package. This is a breaking changeLangChainProvider is removed.

Removed:

  • LangChainProvider class and its tests — callers must migrate to the new factory/runner pattern

Added:

  • LangChainModelRunnerRunner for chat completions; run(input: string | LDMessage[], outputType?) returns RunnerResult { content, metrics, raw, parsed? }. Structured output is parsed via withStructuredOutput.
  • LangChainAgentRunnerRunner for a single agent. Runs a tool-calling loop using LangChain's native bindTools and ToolMessage. Tool definitions come from config.model.parameters.tools; tool callables come from a caller-supplied ToolRegistry. Populates LDAIMetrics.toolCalls with the names of tools invoked.
  • LangChainRunnerFactory — extends AIProvider; exposes createModel(config) and createAgent(config, tools?). Applies OpenTelemetry instrumentation (via @traceloop/instrumentation-langchain) fire-and-forget in the constructor if available.

Renamed / moved:

  • langchainHelper.tsLangChainHelper.ts (casing fix)
  • createLangChainModel moved from LangChainRunnerFactory into LangChainHelper and exported from the package

Renamed:

  • mapProvidermapProviderName in helper exports

Test plan

  • yarn workspace @launchdarkly/server-sdk-ai-langchain test — all tests pass
  • yarn workspace @launchdarkly/server-sdk-ai-langchain lint — clean
  • yarn workspace @launchdarkly/server-sdk-ai-langchain run build — clean

🤖 Generated with Claude Code


Note

High Risk
High risk because this is a breaking API change that removes LangChainProvider in favor of new runner/factory entrypoints, requiring downstream code migration. It also changes how tools, metrics (usage/toolCalls), and structured output are produced/returned.

Overview
Breaking change: removes the LangChainProvider class (and its tests) and replaces it with a Runner-protocol integration.

Adds LangChainRunnerFactory to create either a LangChainModelRunner (chat completions) or LangChainAgentRunner (agent execution via createAgent), including optional OpenTelemetry ESM instrumentation. Introduces LangChainHelper utilities for provider mapping, message conversion, tool wrapping (buildStructuredTools), tool-call extraction, and token-usage aggregation, and updates package exports to expose the new factory/runners/helpers.

Reviewed by Cursor Bugbot for commit 3b1aa33. Bugbot is set up for automated code reviews on this repo. Configure here.


Open in Devin Review

@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-openai-runner branch from 07f1af2 to 66bb862 Compare May 1, 2026 14:10
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-langchain-runner branch from 7a6a7b8 to 58f8249 Compare May 1, 2026 14:13
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-openai-runner branch from 66bb862 to c9d433a Compare May 4, 2026 21:59
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-langchain-runner branch from 58f8249 to fa4a5cf Compare May 4, 2026 21:59
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-openai-runner branch from c9d433a to 42f17c6 Compare May 5, 2026 14:13
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-langchain-runner branch from fa4a5cf to 1b5dcc1 Compare May 5, 2026 14:13
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-openai-runner branch from 42f17c6 to 6902ffa Compare May 5, 2026 17:10
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-langchain-runner branch from 1b5dcc1 to 175c210 Compare May 5, 2026 17:30
@jsonbailey jsonbailey changed the base branch from jb/aic-2388/js-openai-runner to next-ai-release May 5, 2026 18:50
@jsonbailey jsonbailey changed the title feat: add LangChain Runner protocol implementation (AIC-2388) feat: replace LangChainProvider with Runner protocol implementation (AIC-2388) May 5, 2026
@jsonbailey jsonbailey marked this pull request as ready for review May 5, 2026 20:16
@jsonbailey jsonbailey requested a review from a team as a code owner May 5, 2026 20:16
joker23
joker23 previously approved these changes May 5, 2026
cursor[bot]

This comment was marked as resolved.

@joker23 joker23 self-requested a review May 5, 2026 20:29
@joker23 joker23 dismissed their stale review May 5, 2026 20:30

accidental

devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread packages/ai-providers/server-ai-langchain/src/LangChainAgentRunner.ts Outdated
@jsonbailey jsonbailey requested a review from joker23 May 5, 2026 20:44
cursor[bot]

This comment was marked as resolved.

joker23
joker23 previously approved these changes May 5, 2026
jsonbailey and others added 7 commits May 6, 2026 14:29
Adds LangChainModelRunner, LangChainAgentRunner, and LangChainRunnerFactory
that implement the Runner protocol introduced in JS PR 6. The runners take
an LDAICompletionConfig / LDAIAgentConfig at construction and expose
run(prompt: string) returning RunnerResult.

LangChainModelRunner.run(prompt) prepends the config's messages before the
user prompt. LangChainAgentRunner uses LangChain's native bindTools to run
a tool-calling loop, populating LDAIMetrics.toolCalls with the names of
tools the model invoked. Tool implementations are supplied via a
ToolRegistry passed to LangChainRunnerFactory.createAgent.

mapProvider is renamed to mapProviderName on both the helper module and
the LangChainProvider class; the old mapProvider name is kept as a
deprecated alias. The deprecated LangChainProvider class is preserved so
AIProviderFactory continues to work during the migration.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ent on construction

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously the tool-calling loop fell off the end silently and returned
success=true. Now only the clean-exit path (no more tool calls) sets
success=true; hitting the iteration cap returns success=false with a
logger warning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
JSON.stringify(undefined) returns undefined (not a string), producing a
malformed ToolMessage content. Nullish-coalesce to empty string so the
message content is always a valid string.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jsonbailey jsonbailey force-pushed the jb/aic-2388/js-langchain-runner branch from 2479fb2 to d297039 Compare May 6, 2026 19:35
cursor[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@joker23 joker23 dismissed their stale review May 6, 2026 21:01

lots of changes

cursor[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

@jsonbailey jsonbailey merged commit f065743 into next-ai-release May 6, 2026
8 checks passed
@jsonbailey jsonbailey deleted the jb/aic-2388/js-langchain-runner branch May 6, 2026 21:57
jsonbailey added a commit that referenced this pull request May 7, 2026
… (AIC-2388)

Now that all provider packages (#1337 OpenAI, #1338 LangChain, #1339 Vercel)
have migrated to the Runner protocol, the deprecated compatibility surface on
the umbrella `feat/next-ai-release` branch can be removed.

BREAKING CHANGE: Removes the following deprecated APIs:

AIProvider abstract base class:
- `invokeModel()` and `invokeStructuredModel()` instance methods
- `static create()` factory method
- `protected logger` field on the constructor (provider subclasses now
  declare their own private `_logger` field)

LDAIClient deprecated method aliases:
- `config()` (use `completionConfig`)
- `agent()` (use `agentConfig`)
- `agents()` (use `agentConfigs`)
- `createChat()` and `initChat()` (use `createModel`)

Public types:
- `StructuredResponse` (only consumed by the removed
  `invokeStructuredModel` method)

Type narrowing on `AIProvider` and `RunnerFactory`:
- `createModel(config: LDAICompletionConfig | LDAIJudgeConfig)`
- `createAgent(config: LDAIAgentConfig)`
- `createAgentGraph(graphDef: AgentGraphDefinition)`

Previously these accepted the wider `LDAIConfigKind` union; the new signatures
mirror what the provider subclasses already declared and surface mode
mismatches at the type level.

Also updates README examples to use `createModel`/`run()` and removes the
stale `_LegacyProviderAdapter` references in `RunnerFactory` doc comments.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot mentioned this pull request May 7, 2026
jsonbailey pushed a commit that referenced this pull request May 7, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>server-sdk-ai: 0.20.0</summary>

##
[0.20.0](server-sdk-ai-v0.19.1...server-sdk-ai-v0.20.0)
(2026-05-07)


### ⚠ BREAKING CHANGES

* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
* Build judge input as string and strip legacy judge config messages
([#1364](#1364))
* Use LDAIGraphMetricSummary for graph metric summary
([#1362](#1362))

### Features

* add Evaluator class for judge orchestration
([#1331](#1331))
([54faa69](54faa69))
* add ManagedAgent with evaluations support
([#1334](#1334))
([7f09c46](7f09c46))
* add ManagedGraphResult, GraphMetricSummary, and ManagedAgentGraph
([#1335](#1335))
([09fa1db](09fa1db))
* introduce ManagedResult, RunnerResult, and LDAIMetricSummary
([#1332](#1332))
([5040122](5040122))
* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
([ad66314](ad66314))
* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
([ff932b7](ff932b7))
* Replace OpenAIProvider with Runner protocol implementation (AIC-2388)
([#1337](#1337))
([e32a955](e32a955))


### Bug Fixes

* Build judge input as string and strip legacy judge config messages
([#1364](#1364))
([c90034b](c90034b))
* Use LDAIGraphMetricSummary for graph metric summary
([#1362](#1362))
([76a4bf2](76a4bf2))
</details>

<details><summary>server-sdk-ai-langchain: 0.7.0</summary>

##
[0.7.0](server-sdk-ai-langchain-v0.6.3...server-sdk-ai-langchain-v0.7.0)
(2026-05-07)


### ⚠ BREAKING CHANGES

* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
* Build judge input as string and strip legacy judge config messages
([#1364](#1364))

### Features

* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
([ad66314](ad66314))
* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
([ff932b7](ff932b7))
* Replace LangChainProvider with Runner protocol implementation
(AIC-2388)
([#1338](#1338))
([113a0d2](113a0d2))


### Bug Fixes

* Build judge input as string and strip legacy judge config messages
([#1364](#1364))
([c90034b](c90034b))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.19.1 to ^0.20.0
  * peerDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.19.1 to ^0.20.0
</details>

<details><summary>server-sdk-ai-openai: 0.6.0</summary>

##
[0.6.0](server-sdk-ai-openai-v0.5.10...server-sdk-ai-openai-v0.6.0)
(2026-05-07)


### ⚠ BREAKING CHANGES

* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
* Build judge input as string and strip legacy judge config messages
([#1364](#1364))

### Features

* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
([ad66314](ad66314))
* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
([ff932b7](ff932b7))
* Replace OpenAIProvider with Runner protocol implementation (AIC-2388)
([#1337](#1337))
([e32a955](e32a955))


### Bug Fixes

* Build judge input as string and strip legacy judge config messages
([#1364](#1364))
([c90034b](c90034b))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.19.1 to ^0.20.0
  * peerDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.19.1 to ^0.20.0
</details>

<details><summary>server-sdk-ai-vercel: 0.6.0</summary>

##
[0.6.0](server-sdk-ai-vercel-v0.5.10...server-sdk-ai-vercel-v0.6.0)
(2026-05-07)


### ⚠ BREAKING CHANGES

* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
* Build judge input as string and strip legacy judge config messages
([#1364](#1364))

### Features

* Remove AIProvider deprecated methods and create*/init* aliases
(AIC-2388)
([#1363](#1363))
([ad66314](ad66314))
* Rename LDAIMetrics.usage and LDAIGraphMetrics.usage to .tokens
([#1366](#1366))
([ff932b7](ff932b7))
* replace VercelProvider with Runner protocol implementation (AIC-2388)
([#1339](#1339))
([d5a62de](d5a62de))


### Bug Fixes

* add zod devDependency to Vercel provider (peer dep of ai v5)
([aab6226](aab6226))
* Build judge input as string and strip legacy judge config messages
([#1364](#1364))
([c90034b](c90034b))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.19.1 to ^0.20.0
  * peerDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.19.1 to ^0.20.0
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> This is primarily a versioning/release metadata update, but it ships
breaking API changes in `@launchdarkly/server-sdk-ai` and provider
packages that may require consumer code updates (e.g., metrics field
rename and deprecated method removals).
> 
> **Overview**
> Publishes a new release for `@launchdarkly/server-sdk-ai` (`0.19.1` →
`0.20.0`) and the provider packages (`server-sdk-ai-langchain` `0.6.3` →
`0.7.0`, `server-sdk-ai-openai`/`server-sdk-ai-vercel` `0.5.10` →
`0.6.0`), updating `.release-please-manifest.json`, package versions,
and `sdkInfo.ts`.
> 
> Updates provider `peerDependencies`/`devDependencies` to require
`@launchdarkly/server-sdk-ai@^0.20.0`, and bumps all `server-ai`
examples to depend on the new SDK/provider versions. Changelogs
highlight *breaking changes* including renaming metrics `usage` →
`tokens`, removing deprecated `AIProvider` methods/aliases, and
judge-input/config cleanup (plus additional `server-sdk-ai`
graph/managed result summary changes).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
cb3aebc. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants