LLMAdapter with a LangGraph checkpointer duplicates assistant history on the next turn
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Start with the reproduction script's LLMAdapter setup and add_messages reducer path, then compare the IDs of the assistant message written by the graph with the one AgentSession records in session.history. Done means the first assistant reply appears once at each turn's node entry with a checkpointer enabled, matching the expected counts [0, 1, 1] in both stream modes. Confirm the fix against the messages and custom cases, which must both pass.
索引モデルが issue の本文から書いたものです。
説明
Problem
A graph using the add_messages reducer and InMemorySaver stores its generated AIMessage.
When the next AgentSession turn starts, LLMAdapter also supplies the transport's copy of that
assistant reply. The copies have different IDs, so add_messages retains both.
The duplicate is in the graph's input history, not duplicate audible playback. AgentSession
history contains one reply per turn, while the graph receives two copies of prior replies.
This may distort subsequent model context and increase input tokens; this reproduction does
not measure production cost or downstream tool effects.
Environment and reproduction
Reproduced on Windows with Python 3.14.7:
- langgraph 1.2.14, langgraph-checkpoint 4.2.0, langchain-core 1.6.9
- livekit-agents 1.8.5, livekit-plugins-langchain 1.8.5
Also reproduced with langgraph 1.2.7 and livekit-agents/livekit-plugins-langchain 1.6.4.
The script uses the official GenericFakeChatModel and a real, text-only AgentSession.
It needs no room, credentials, microphone, TTS provider, or model API calls.
Preemptive generation is not part of this reproduction.
Install the current-release packages listed above in a fresh environment and run this script:
"""Compare transport and checkpoint history using synthetic, local replies."""
import asyncio
import json
from importlib.metadata import version
from typing import Annotated, TypedDict
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, BaseMessage
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.config import get_stream_writer
from langgraph.graph import END, START, StateGraph
from langgraph.graph.message import add_messages
from livekit.agents import Agent, AgentSession
from livekit.plugins.langchain import LLMAdapter
class State(TypedDict):
messages: Annotated[list[BaseMessage], add_messages]
async def run_case(checkpointed: bool, stream_mode: str) -> dict:
observations = []
model = GenericFakeChatModel(
messages=iter(
AIMessage(content=f"synthetic reply {n}", id=f"graph-reply-{n}") for n in range(1, 4)
)
)
async def reply(state: State) -> dict:
observations.append(
[{"role": m.type, "id": m.id, "text": m.content} for m in state["messages"]]
)
response = await model.ainvoke(state["messages"])
if stream_mode == "custom":
get_stream_writer()(response.content)
return {"messages": [response]}
graph = (
StateGraph(State)
.add_node("reply", reply)
.add_edge(START, "reply")
.add_edge("reply", END)
.compile(checkpointer=InMemorySaver() if checkpointed else None)
)
config = {"configurable": {"thread_id": "synthetic-session"}}
session = AgentSession(llm=LLMAdapter(graph, config=config, stream_mode=stream_mode))
await session.start(Agent(instructions=""), record=False)
try:
for n in range(1, 4):
speech = session.generate_reply(user_input=f"synthetic turn {n}")
await asyncio.wait_for(speech.wait_for_playout(), timeout=15)
transport = [
{"role": item.role, "id": item.id, "text": item.text_content}
for item in session.history.items
if item.type == "message" and item.role in {"user", "assistant"}
]
return {
"checkpointed": checkpointed,
"stream_mode": stream_mode,
"reply_1_copies_at_node_entry": [
sum(m["text"] == "synthetic reply 1" for m in messages) for messages in observations
],
"node_inputs": observations,
"transport_history": transport,
}
finally:
await session.aclose()
async def main() -> None:
packages = (
"langgraph",
"langgraph-checkpoint",
"langchain-core",
"livekit-agents",
"livekit-plugins-langchain",
)
print(json.dumps({"versions": {name: version(name) for name in packages}}))
for mode in ("messages", "custom"):
for checkpointed in (False, True):
print(json.dumps(await run_case(checkpointed, mode)))
if __name__ == "__main__":
asyncio.run(main())
Expected and observed
At entry to turns 1, 2, and 3, the first assistant reply should occur 0, 1, and 1 times.
| Mode | InMemorySaver | Observed first-reply counts |
|---|---|---|
| messages | disabled | [0, 1, 1] |
| messages | enabled | [0, 2, 2] |
| custom | disabled | [0, 1, 1] |
| custom | enabled | [0, 2, 2] |
On the third turn, the second reply is also present twice. The user-message IDs remain aligned.
The script prints both graph inputs and session history, including IDs, so the distinction is
visible without relying on an assertion or a real provider.
Relation to previous work
PR #2767 preserved the IDs of assistant, user, and
system messages when converting transport history. This reproduction is a different remaining
identity problem: the assistant message already written by the graph has a different ID from the
assistant message recorded by AgentSession.
Targeted GitHub issue/PR searches for langchain duplication and checkpointer usage did not find
a report of this exact mechanism. That search is not proof that no related discussion exists.
Could the integration preserve a common assistant-message identity across these two histories,
or document the supported history-ownership pattern when using a checkpointer?
- 主要言語
- Python
- スター
- 14.6k
- フォーク
- 3.9k
- 平均マージ
- 2日 23時間
- マージ済み PR(30日)
- 258
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
livekit/agents のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
livekit/agents#8284 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
ci: unit tests pin Python 3.12 while the package advertises 3.14 support対応中かも @huong8373tt-beep が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
livekit/agents#8231 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Assistant markup is stripped from chat history when expressive mode is off対応中かも @ShivamSharma43 が 28 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
livekit/agents#7647 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hosts再び着手できるかも @AbarnaaSree が 67 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
livekit/agents#7022 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
area:docs documentation effort:M ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
mczielinski/ob-analytics#423 ·
メンテナーはふだん 1 日以内に返信
-
infra
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
vllm-project/vllm-ascend#21033 ·
メンテナーはふだん 1 日以内に返信