Commit 2b047ff
fix(memory): Improve pagination behavior in get_last_k_turns() and list_messages() (#209)
* feat(memory): Improve pagination behavior in get_last_k_turns() and list_messages()
- get_last_k_turns(): Auto-calculate max_results based on k (max(100, k*3))
- list_messages(): Add fetch_all parameter to fetch all messages (up to 10000)
- Backward compatible: default behavior unchanged
* fix(memory): Address PR review comments for pagination behavior
- Extract shared pagination logic into pagination.py helper
- Fix test mocks to use _data_plane_client.list_events
- Add MAX_FETCH_ALL_RESULTS constant (10000) in strands session_manager
- Rename include_branches to include_parent_branches in client.py for consistency
- Add comprehensive tests for pagination helper
* fix(memory): Address PR review comments
- Remove fetch_all parameter from list_messages (misleading name)
- Use MAX_FETCH_ALL_RESULTS (10000) as default when no limit specified
- Remove pagination.py module, inline logic into client.py and session.py
- Revert include_branches rename to avoid breaking change
* fix: Apply ruff formatting to pagination changes
Apply automatic formatting fixes identified by ruff format pre-commit hook.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Aidan Daly <aidandal@amazon.com>
Co-authored-by: T.J Ariyawansa <tjariy@amazon.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 43c6c3c commit 2b047ff
6 files changed
Lines changed: 337 additions & 211 deletions
File tree
- src/bedrock_agentcore/memory
- integrations/strands
- tests/bedrock_agentcore/memory
- integrations/strands
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1096 | 1096 | | |
1097 | 1097 | | |
1098 | 1098 | | |
1099 | | - | |
| 1099 | + | |
1100 | 1100 | | |
1101 | 1101 | | |
1102 | 1102 | | |
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
1106 | 1110 | | |
1107 | 1111 | | |
1108 | 1112 | | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
1109 | 1122 | | |
1110 | | - | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | | - | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
1119 | 1136 | | |
1120 | | - | |
1121 | | - | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
1122 | 1140 | | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
| 1141 | + | |
| 1142 | + | |
1126 | 1143 | | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
1133 | 1148 | | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
1138 | 1159 | | |
1139 | | - | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
1140 | 1163 | | |
1141 | | - | |
1142 | | - | |
| 1164 | + | |
1143 | 1165 | | |
1144 | 1166 | | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
| 1167 | + | |
1148 | 1168 | | |
1149 | 1169 | | |
1150 | 1170 | | |
| |||
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
427 | 428 | | |
428 | 429 | | |
429 | 430 | | |
430 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
431 | 437 | | |
432 | 438 | | |
433 | 439 | | |
| |||
448 | 454 | | |
449 | 455 | | |
450 | 456 | | |
451 | | - | |
| 457 | + | |
| 458 | + | |
452 | 459 | | |
453 | 460 | | |
454 | 461 | | |
| |||
512 | 519 | | |
513 | 520 | | |
514 | 521 | | |
515 | | - | |
| 522 | + | |
| 523 | + | |
516 | 524 | | |
517 | 525 | | |
518 | 526 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
786 | 786 | | |
787 | 787 | | |
788 | 788 | | |
789 | | - | |
| 789 | + | |
790 | 790 | | |
791 | 791 | | |
792 | 792 | | |
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
796 | 800 | | |
797 | 801 | | |
798 | 802 | | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
799 | 812 | | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
807 | 826 | | |
808 | | - | |
809 | | - | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
810 | 833 | | |
811 | | - | |
812 | | - | |
813 | | - | |
| 834 | + | |
| 835 | + | |
814 | 836 | | |
815 | | - | |
816 | | - | |
817 | | - | |
818 | | - | |
819 | | - | |
820 | | - | |
| 837 | + | |
821 | 838 | | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
826 | 849 | | |
827 | | - | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
828 | 853 | | |
829 | | - | |
830 | | - | |
| 854 | + | |
831 | 855 | | |
832 | 856 | | |
833 | | - | |
834 | | - | |
835 | | - | |
| 857 | + | |
836 | 858 | | |
837 | 859 | | |
838 | 860 | | |
| |||
1153 | 1175 | | |
1154 | 1176 | | |
1155 | 1177 | | |
1156 | | - | |
| 1178 | + | |
1157 | 1179 | | |
1158 | 1180 | | |
1159 | 1181 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1096 | 1096 | | |
1097 | 1097 | | |
1098 | 1098 | | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3064 | 3064 | | |
3065 | 3065 | | |
3066 | 3066 | | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
| 3079 | + | |
| 3080 | + | |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
| 3093 | + | |
| 3094 | + | |
| 3095 | + | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
| 3101 | + | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
| 3110 | + | |
| 3111 | + | |
| 3112 | + | |
| 3113 | + | |
| 3114 | + | |
| 3115 | + | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
0 commit comments