Skip to content

Conversation

asvishnyakov
Copy link

@asvishnyakov asvishnyakov commented Jul 30, 2025

Because the messages field is cumulative, overwriting history in any of the swarm agents causes the history update (such as a message summary) to be appended to the end. For example:

Agent 1:

  • Message 1
  • Message 2
  • Hand off to Agent 2

Agent 2:

  • Message 1
  • Message 2
  • Hand off to Agent 2
  • Message 3

Then Agent 2 overwrites the history:

  • Summary
  • Message 4

And when handing off back to Agent 1, this happens:

  • Message 1
  • Message 2
  • Hand off to Agent 2
  • Summary
  • Message 4
  • Hand off to Agent 1

This not only disrupts the flow of the conversation but also causes issues if the summary is a system message (such as in langmem's SummarizationNode).

On the other hand, if history is not overwritten, everything continues to work correctly after changes made in this PR, since the "removed" messages will simply be replaced by themselves.

Fixes #84.

@asvishnyakov
Copy link
Author

@farisnanosoft @sydney-runkle @eyurtsev I’d appreciate any feedback if you think this isn’t the right fix for the issue, as I’m currently experiencing it in my project.

@asvishnyakov asvishnyakov changed the title fix: clean shared messages state in case of history overwrite fix: clean shared messages state in case of history rewrite Jul 30, 2025
@asvishnyakov
Copy link
Author

@sydney-runkle May you look into this please?

@asvishnyakov
Copy link
Author

@sydney-runkle @eyurtsev May someone take a look on this, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to manage memory of swarm for long conversation
1 participant