mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-10 03:37:51 +02:00
Dedupe input (right-side) messages in add_messages
This commit is contained in:
@@ -176,9 +176,12 @@ def add_messages(
|
||||
for m in left:
|
||||
if m.id is None:
|
||||
m.id = str(uuid.uuid4())
|
||||
dedupe_map = {}
|
||||
for m in right:
|
||||
if m.id is None:
|
||||
m.id = str(uuid.uuid4())
|
||||
dedupe_map[m.id] = m
|
||||
right = list(dedupe_map.values())
|
||||
# merge
|
||||
left_idx_by_id = {m.id: i for i, m in enumerate(left)}
|
||||
merged = left.copy()
|
||||
|
||||
@@ -66,6 +66,15 @@ def test_missing_ids():
|
||||
assert all(isinstance(m.id, str) and UUID(m.id, version=4) for m in result)
|
||||
|
||||
|
||||
def test_duplicates_in_input():
|
||||
left = []
|
||||
right = [AIMessage(id="1", content="Hi there!"), AIMessage(id="1", content="Hi there again!")]
|
||||
result = add_messages(left, right)
|
||||
assert len(result) == 1
|
||||
assert result[0].id == "1"
|
||||
assert result[0].content == "Hi there again!"
|
||||
|
||||
|
||||
def test_remove_message():
|
||||
left = [
|
||||
HumanMessage(content="Hello", id="1"),
|
||||
|
||||
Reference in New Issue
Block a user