dify icon indicating copy to clipboard operation
dify copied to clipboard

Agent Memory Window

Open juniorsereno opened this issue 10 months ago • 4 comments

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Create an agent, set a personal assistant prompt, for example All interactions with it will go to infinite memory Have more than 100 interactions and see your token cost increase exponentially, making it impossible to continue the conversation, forcing you to open a new conversation window and losing all the desired last context.

Without a memory window, it becomes impossible to maintain a long conversation.

OBS: This same problem is coming up for the new Agent in the chatflow of version 1.0.0

✔️ Expected Behavior

Possibility to limit the memory window just like there is in LLM the chatflow.

❌ Actual Behavior

Infinite memory window causing uncontrollable and unnecessary consumption of the LLM forcing to always open new decks.

juniorsereno avatar Feb 24 '25 12:02 juniorsereno

I found some relevant discussions and issues related to your concern about the memory window for agents in Dify:

  1. There is an open discussion titled Limit the number of messages that addresses similar concerns about managing token costs due to large context windows [1].

  2. An open issue suggests implementing a context limitation feature for agents, similar to the existing limitation in ChatFlow, to manage costs associated with larger context windows in production [2].

  3. Another open issue discusses limiting the maximum token size of a session to prevent excessive token usage in prolonged conversations [3].

These threads indicate that the problem of managing memory windows and token costs is recognized, and there are ongoing discussions and suggestions for solutions.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 24 '25 12:02 dosubot[bot]

@juniorsereno You could try this (fix code) by change in file core/agent/base_agent_runner.py. I fix to only fetch 20 latest message

Image

k1eNdn avatar Feb 26 '25 09:02 k1eNdn

@juniorsereno You could try this (fix code) by change in file core/agent/base_agent_runner.py. I fix to only fetch 20 latest message

Image

Seriously, does this solve the problem?

Why doesn't the dify team implement this, something so simple?

@crazywoola

juniorsereno avatar Feb 26 '25 12:02 juniorsereno

Hi, @juniorsereno. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • You reported an issue with the absence of a memory window for agents when self-hosted using Docker, leading to increased token costs.
  • I provided references to related discussions on managing token costs and context windows.
  • User k1endn suggested a code modification to limit the memory window to the 20 latest messages.
  • You questioned why this simple fix hasn't been implemented by the Dify team.

Next Steps

  • Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting on this issue.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Mar 29 '25 16:03 dosubot[bot]