feat: replace LangChainProvider with Runner protocol implementation (AIC-2388)#1338
feat: replace LangChainProvider with Runner protocol implementation (AIC-2388)#1338jsonbailey wants to merge 7 commits intonext-ai-releasefrom
Conversation
07f1af2 to
66bb862
Compare
7a6a7b8 to
58f8249
Compare
66bb862 to
c9d433a
Compare
58f8249 to
fa4a5cf
Compare
c9d433a to
42f17c6
Compare
fa4a5cf to
1b5dcc1
Compare
42f17c6 to
6902ffa
Compare
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>
1b5dcc1 to
175c210
Compare
…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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2479fb2. Configure here.
| }), | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Agent executes tools on final iteration without consuming results
Medium Severity
When MAX_ITERATIONS is exhausted, the loop still executes all tool calls on the final iteration (i=24) even though their results are never sent back to the model. Tools with side effects (database writes, external API calls, mutations) will be triggered unnecessarily, and the latency of those calls is wasted. The loop structure doesn't check whether it's on the last iteration before calling _executeTool. This was flagged in PR discussion by @joker23.
Reviewed by Cursor Bugbot for commit 2479fb2. Configure here.


Summary
Replaces the legacy
LangChainProviderextension model with the Runner protocol for the LangChain provider package. This is a breaking change —LangChainProvideris removed.Removed:
LangChainProviderclass and its tests — callers must migrate to the new factory/runner patternAdded:
LangChainModelRunner—Runnerfor chat completions;run(input: string | LDMessage[], outputType?)returnsRunnerResult { content, metrics, raw, parsed? }. Structured output is parsed viawithStructuredOutput.LangChainAgentRunner—Runnerfor a single agent. Runs a tool-calling loop using LangChain's nativebindToolsandToolMessage. Tool definitions come fromconfig.model.parameters.tools; tool callables come from a caller-suppliedToolRegistry. PopulatesLDAIMetrics.toolCallswith the names of tools invoked.LangChainRunnerFactory— extendsAIProvider; exposescreateModel(config)andcreateAgent(config, tools?). Applies OpenTelemetry instrumentation (via@traceloop/instrumentation-langchain) fire-and-forget in the constructor if available.Renamed / moved:
langchainHelper.ts→LangChainHelper.ts(casing fix)createLangChainModelmoved fromLangChainRunnerFactoryintoLangChainHelperand exported from the packageRenamed:
mapProvider→mapProviderNamein helper exportsTest plan
yarn workspace @launchdarkly/server-sdk-ai-langchain test— all tests passyarn workspace @launchdarkly/server-sdk-ai-langchain lint— cleanyarn workspace @launchdarkly/server-sdk-ai-langchain run build— clean🤖 Generated with Claude Code
Note
High Risk
High risk because it removes the exported
LangChainProviderAPI and replaces it with newRunner/factory entrypoints, requiring downstream migration and potentially affecting tool-calling and metrics behavior.Overview
Breaking change: removes
LangChainProvider(and its tests) and switches the package API to the LaunchDarklyRunnerprotocol.Adds
LangChainModelRunnerfor chat completions (string + optional structured output) andLangChainAgentRunnerfor tool-calling agents (binds tools from config, executes a caller-suppliedToolRegistry, aggregates token usage, and records invoked tool names). IntroducesLangChainRunnerFactoryto build these runners and keep the existing optional OpenTelemetry instrumentation, and exports new helpers (createLangChainModel, message conversion, provider-name mapping, and usage/metrics extraction) fromindex.ts.Reviewed by Cursor Bugbot for commit 2479fb2. Bugbot is set up for automated code reviews on this repo. Configure here.