i-am-bee / bee-agent-framework

The framework for building scalable agentic applications.
https://i-am-bee.github.io/bee-agent-framework/
Apache License 2.0
1.09k stars 106 forks source link

Agent repeating steps - improve token memory removal #177

Closed jezekra1 closed 2 days ago

jezekra1 commented 4 days ago

The removalSelector in Bee agent runner will remove important information from agent memory causing the agent to loop endlessly:

We should at least let the agent know that a message was removed or provide a summary so that it won't repeat itself

Bugs in removal selector

Removal selector does not remove user messages from history

https://github.com/i-am-bee/bee-agent-framework/blob/ad55531ac81a643536a6da739f92be77e0624f21/src/agents/bee/runner.ts#L103

This find compares transformed messages:

curMessages[1]
{
  "role": "user",
  "text": "Message: Hi\n\nThis message was created at 2024-11-18T16:09:49.706Z",
  "meta": {
    "createdAt": "2024-11-18T16:09:49.706Z"
  }
}

vs. input.memory.messages[0]

{
  "role": "user",
  "text": "Hi",
  "meta": {
    "createdAt": "2024-11-18T16:09:49.706Z"
  }
}

Possible removal of the latest prompt

If the above is fixed, the removal selector could select the last user prompt if not passed through prompt to agent but through memory content (this is the way how it's done in the API)

Tomas2D commented 2 days ago

Good catch. Fix has been released in v0.0.41