-
Notifications
You must be signed in to change notification settings - Fork 45.6k
Fix memory by adding it only when context window full #3469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory by adding it only when context window full #3469
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
bb8c356
to
442b2d6
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
442b2d6
to
46e040a
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
1 similar comment
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
954ff6c
to
afe1b69
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
afe1b69
to
fb2de7b
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
fb2de7b
to
a60160c
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
a60160c
to
e286c23
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #3469 +/- ##
==========================================
+ Coverage 56.46% 56.88% +0.42%
==========================================
Files 66 67 +1
Lines 3018 3043 +25
Branches 507 509 +2
==========================================
+ Hits 1704 1731 +27
+ Misses 1175 1174 -1
+ Partials 139 138 -1
☔ View full report in Codecov by Sentry. |
e286c23
to
f561fb4
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
f561fb4
to
34ce877
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
34ce877
to
db5e2bf
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
1 similar comment
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
eaa3239
to
6983af5
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
6983af5
to
a70bfd1
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
ca9e911
to
19f3318
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
2 similar comments
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
d42fdae
to
6587d5c
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
6587d5c
to
139cb39
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
Ok I applied the fixes @p-i- |
139cb39
to
10f5857
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
10f5857
to
5a0e13c
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
5a0e13c
to
ab04020
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
ab04020
to
e893785
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
e893785
to
2610675
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
autogpt/chat.py
Outdated
@@ -126,6 +126,7 @@ def chat_with_ai( | |||
[message_to_add], model | |||
) | |||
if current_tokens_used + tokens_to_add > send_token_limit: | |||
save_memory_trimmed_from_context_window(full_message_history, next_message_to_add_index, permanent_memory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will see above there is a while loop while next_message_to_add_index >= 0:
so basicallly if current_tokens_used + tokens_to_add > send_token_limit:
this means the context window is full.
autogpt/chat.py
Outdated
memory_to_add = format_memory(thoughts_memory["content"], next_message["content"]) | ||
permanent_memory.add(memory_to_add) | ||
|
||
next_message_to_add_index -= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we just say "add to memory as long as you see a json reply". And we add the json reply but also the command or user input, like we did before
def expected_permanent_memory(): | ||
return """Assistant Reply: { | ||
"thoughts": { | ||
"text": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flake8 W291 was complaining about a space here but this is necessary
Background
Currently the memory is added at the cycle number 2. it doesn't make sense because we don't need memory if the context window is small.
Changes
add the memory only when the context window is full. We happen to have a while loop that does exactly that, so I just inserted the memory in there.
Also, we only want to add memory when we hit a json reply, not a command system or user input.
When we hit an assistant reply, we look at the message after it and we see if it's a user input or Command result.
We then append the assistant reply and user input or command result
Documentation
Test Plan
PR Quality Checklist