Skip to content

docs: fix delete_old_messages example to properly demonstrate deletion effect#4009

Merged
Naomi Pentrel (npentrel) merged 2 commits into
langchain-ai:mainfrom
uditstocks:fix/delete-old-messages-demo
May 29, 2026
Merged

docs: fix delete_old_messages example to properly demonstrate deletion effect#4009
Naomi Pentrel (npentrel) merged 2 commits into
langchain-ai:mainfrom
uditstocks:fix/delete-old-messages-demo

Conversation

@uditstocks
Copy link
Copy Markdown
Contributor

Overview

The existing delete_old_messages example in the short-term memory documentation failed to properly demonstrate
the deletion effect. After deleting the earliest two messages, the agent could still recall the user's name "Bob" because
the AI's own first response had echoed the name - and that response survived the deletion window.

This PR fixes the example by inserting an unrelated conversation turn (a cat poem)
between the name introduction and the name recall query. This naturally pushes the
name-containing messages out of the window, so when the agent is asked "what's my name?"
it correctly responds that it doesn't know.

Type of change

[Update existing documentation]

Checklist

  • I have read the contributing guidelines
  • I have tested my changes locally using docs dev
  • All code examples have been tested and work correctly

Related issues/PRs

closes #3894

Additional notes

The fix is minimal and surgical - only the example code and output block are changed.
No API behavior, no logic, no navigation changes. The updated output block is taken
from an actual local run to ensure accuracy.

@github-actions github-actions Bot added the external User is not a member of langchain-ai label May 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for opening a docs PR, Udit Sharma (@uditstocks)! When it's ready for review, please add the relevant reviewers:

  • @npentrel or @lnhsingh (LangChain)

@github-actions github-actions Bot added langchain For docs changes to LangChain oss labels May 14, 2026
@uditstocks Udit Sharma (uditstocks) force-pushed the fix/delete-old-messages-demo branch from b739c77 to 18bf2d3 Compare May 14, 2026 18:06
@AA-G-AA
Copy link
Copy Markdown

AA-G-AA commented May 26, 2026

Thanks for implementing this based on my issue #3894.

I verified the original behavior locally as well, and the reproduction flow correctly demonstrates the deletion effect.

I’m new to contributing to this repository, so I really appreciate your help turning my initial issue and reproduction idea into a proper PR.

Comment thread src/oss/langchain/short-term-memory.mdx
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Please mirror the change in JS as well

- Added unrelated conversation turn (cat poem) in JS section
- Updated JS output block to show correct deletion behavior
- Agent now correctly responds it does not know the name
@uditstocks Udit Sharma (uditstocks) force-pushed the fix/delete-old-messages-demo branch from 18bf2d3 to 56a106c Compare May 28, 2026 19:50
@uditstocks
Copy link
Copy Markdown
Contributor Author

Hi Lauren Hirata Singh (@lnhsingh) I've mirrored the change in the JS section as well.
Please review when you get a chance. Thank you! 🙏

Copy link
Copy Markdown
Contributor

@npentrel Naomi Pentrel (npentrel) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@npentrel Naomi Pentrel (npentrel) merged commit 393b6b0 into langchain-ai:main May 29, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external User is not a member of langchain-ai langchain For docs changes to LangChain oss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[langchain]: 'delete_old_messages' The deletion effect was not effectively demonstrated.

4 participants