Commit cd2f2a0
authored
feat(strands-memory): add event metadata support to AgentCoreMemorySessionManager (#339)
* feat(strands-memory): add user-supplied event metadata support to AgentCoreMemorySessionManager
Allow users to attach custom key-value metadata to conversation events
via a new `default_metadata` config field and per-call `metadata` kwarg.
Metadata is merged (per-call > config defaults > internal) and validated
against reserved keys and the 15-key API limit.
Also refactors the internal message buffer from a raw tuple to a
`BufferedMessage` NamedTuple for clarity and extensibility.
Closes #149 (Phase 1: Metadata)
* feat(strands-memory): add metadata_provider for dynamic per-invocation metadata
Add `metadata_provider` config field — a callable invoked at each event
creation, enabling dynamic metadata like traceId that changes per
agent invocation. This solves the Langfuse/user-feedback use case where
a static `default_metadata` is insufficient because Strands controls
the append_message → create_message call path.
Merge precedence: default_metadata < metadata_provider() < per-call kwargs < internal keys.
* fix: address PR review feedback
- Auto-normalize plain string metadata values to {"stringValue": ...}
so users can write {"project": "atlas"} instead of the verbose form.
Applied via pydantic validator on default_metadata and at runtime for
metadata_provider return values.
- Move inline datetime imports to top of test file (nit from Hweinstock)
- Fix lint/format issues that caused CI Lint and Format check to fail
- Add tests for normalization in both config and session manager
* fix: remove unnecessary model_config from AgentCoreMemoryConfig
Pydantic v2 handles Callable natively, so arbitrary_types_allowed
is not needed. Removing it avoids any risk of breaking subclasses
or downstream validators.1 parent 2f4f297 commit cd2f2a0
6 files changed
Lines changed: 722 additions & 63 deletions
File tree
- src/bedrock_agentcore/memory/integrations/strands
- tests_integ/memory/integrations
- tests/bedrock_agentcore/memory/integrations/strands
Lines changed: 67 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
222 | 224 | | |
223 | 225 | | |
224 | 226 | | |
| |||
239 | 241 | | |
240 | 242 | | |
241 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
242 | 309 | | |
243 | 310 | | |
244 | 311 | | |
| |||
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
| |||
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
41 | 54 | | |
42 | 55 | | |
43 | 56 | | |
| |||
48 | 61 | | |
49 | 62 | | |
50 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
Lines changed: 119 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
49 | 66 | | |
50 | 67 | | |
51 | 68 | | |
| |||
129 | 146 | | |
130 | 147 | | |
131 | 148 | | |
132 | | - | |
133 | | - | |
| 149 | + | |
| 150 | + | |
134 | 151 | | |
135 | 152 | | |
136 | 153 | | |
| |||
169 | 186 | | |
170 | 187 | | |
171 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
172 | 238 | | |
173 | 239 | | |
174 | 240 | | |
| |||
482 | 548 | | |
483 | 549 | | |
484 | 550 | | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
485 | 554 | | |
486 | 555 | | |
487 | 556 | | |
| |||
490 | 559 | | |
491 | 560 | | |
492 | 561 | | |
493 | | - | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
494 | 571 | | |
495 | 572 | | |
496 | 573 | | |
| |||
508 | 585 | | |
509 | 586 | | |
510 | 587 | | |
| 588 | + | |
511 | 589 | | |
512 | 590 | | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
522 | 601 | | |
523 | 602 | | |
524 | 603 | | |
| |||
790 | 869 | | |
791 | 870 | | |
792 | 871 | | |
793 | | - | |
| 872 | + | |
794 | 873 | | |
795 | 874 | | |
796 | | - | |
797 | | - | |
798 | | - | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
799 | 879 | | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
804 | 883 | | |
805 | | - | |
806 | | - | |
807 | | - | |
| 884 | + | |
| 885 | + | |
808 | 886 | | |
809 | 887 | | |
810 | 888 | | |
811 | 889 | | |
812 | | - | |
813 | | - | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
814 | 896 | | |
815 | 897 | | |
816 | 898 | | |
817 | 899 | | |
818 | 900 | | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
826 | 911 | | |
827 | 912 | | |
828 | 913 | | |
| |||
0 commit comments