feat: support conversation history directly in AI Provider model runners#1371
Open
jsonbailey wants to merge 1 commit into
Open
feat: support conversation history directly in AI Provider model runners#1371jsonbailey wants to merge 1 commit into
jsonbailey wants to merge 1 commit into
Conversation
Contributor
|
@launchdarkly/js-sdk-common size report |
Contributor
|
@launchdarkly/js-client-sdk-common size report |
Contributor
|
@launchdarkly/js-client-sdk size report |
Contributor
|
@launchdarkly/browser size report |
Each provider model runner now keeps an internal conversation history that is seeded from the AI config's messages and grows with each successful call. The user prompt and the assistant's reply are appended to history only when the call succeeds and produces non-empty content, so failed calls leave history unchanged for retries. Mirrors python-server-sdk-ai #166. - OpenAI: private LDMessage[] history, mirrored on the Python OpenAI runner. - LangChain: uses InMemoryChatMessageHistory from @langchain/core/chat_history to mirror the Python LangChain runner. - Vercel: private ModelMessage[] history (Vercel-native types).
017efa0 to
b74c851
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port the multi-turn conversation history pattern from the Python AI SDK provider runners to the js-core AI SDK provider runners. Mirrors the behaviour shipped in python-server-sdk-ai #166.
Each provider model runner now keeps an internal conversation history that is seeded from the AI config's messages on construction and grows with each successful call. On every
run()invocation:The public
run(input)interface is unchanged and still returns the sameRunnerResult. The history is purely internal state on the runner instance.Per-provider approach
OpenAIModelRunner.ts) — privateLDMessage[]history, mirroring the Python OpenAI runner. The OpenAI Chat Completions API has no native conversation state.LangChainModelRunner.ts) — usesInMemoryChatMessageHistoryfrom@langchain/core/chat_history, the JS equivalent oflangchain_core.chat_history. This mirrors the Python LangChain runner.VercelModelRunner.ts) — privateModelMessage[]history (Vercel AI SDK native v5 type). No analogue exists in the Python SDK; choseModelMessage[]to avoid re-converting on every call.Behaviour change for multi-turn callers (medium risk)
Callers that invoke
run()multiple times on the same runner instance will now accumulate conversation history across calls. Token usage will grow with each turn since the full history is sent on every call. Callers that want stateless behaviour should construct a new runner per call.Test plan
run()calls (per provider)run()throws (per provider)run()returns empty content (per provider)yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/server-sdk-ai' run buildsucceedsNote
Medium Risk
Changes
run()semantics for repeated calls by accumulating prior prompts/responses, which can increase token usage and alter model outputs; failures/empty content are explicitly excluded from history to reduce runaway state.Overview
Adds stateful multi-turn support to the
LangChainModelRunner,OpenAIModelRunner, andVercelModelRunnerby keeping an internal conversation history seeded fromconfig.messagesand appending it to everyrun()call.History is only persisted after successful calls with non-empty content; exceptions or empty/multimodal responses leave history unchanged to allow clean retries. New unit tests in each provider verify accumulation behavior and that config/system messages stay prepended ahead of the growing history.
Reviewed by Cursor Bugbot for commit b74c851. Bugbot is set up for automated code reviews on this repo. Configure here.