@@ -101,13 +101,15 @@ def test_standard_add_and_get(standard_history):
101
101
"role" : "tool" ,
102
102
"content" : "tool result 1" ,
103
103
"tool_call_id" : "tool call one" ,
104
+ "metadata" : {"tool call params" : "abc 123" },
104
105
}
105
106
)
106
107
standard_history .add_message (
107
108
{
108
109
"role" : "tool" ,
109
110
"content" : "tool result 2" ,
110
111
"tool_call_id" : "tool call two" ,
112
+ "metadata" : {"tool call params" : "abc 456" },
111
113
}
112
114
)
113
115
standard_history .add_message ({"role" : "user" , "content" : "third prompt" })
@@ -121,7 +123,12 @@ def test_standard_add_and_get(standard_history):
121
123
partial_context = standard_history .get_recent (top_k = 3 )
122
124
assert len (partial_context ) == 3
123
125
assert partial_context == [
124
- {"role" : "tool" , "content" : "tool result 2" , "tool_call_id" : "tool call two" },
126
+ {
127
+ "role" : "tool" ,
128
+ "content" : "tool result 2" ,
129
+ "tool_call_id" : "tool call two" ,
130
+ "metadata" : {"tool call params" : "abc 456" },
131
+ },
125
132
{"role" : "user" , "content" : "third prompt" },
126
133
{"role" : "llm" , "content" : "third response" },
127
134
]
@@ -133,8 +140,18 @@ def test_standard_add_and_get(standard_history):
133
140
{"role" : "llm" , "content" : "first response" },
134
141
{"role" : "user" , "content" : "second prompt" },
135
142
{"role" : "llm" , "content" : "second response" },
136
- {"role" : "tool" , "content" : "tool result 1" , "tool_call_id" : "tool call one" },
137
- {"role" : "tool" , "content" : "tool result 2" , "tool_call_id" : "tool call two" },
143
+ {
144
+ "role" : "tool" ,
145
+ "content" : "tool result 1" ,
146
+ "tool_call_id" : "tool call one" ,
147
+ "metadata" : {"tool call params" : "abc 123" },
148
+ },
149
+ {
150
+ "role" : "tool" ,
151
+ "content" : "tool result 2" ,
152
+ "tool_call_id" : "tool call two" ,
153
+ "metadata" : {"tool call params" : "abc 456" },
154
+ },
138
155
{"role" : "user" , "content" : "third prompt" },
139
156
{"role" : "llm" , "content" : "third response" },
140
157
]
@@ -160,7 +177,11 @@ def test_standard_add_messages(standard_history):
160
177
standard_history .add_messages (
161
178
[
162
179
{"role" : "user" , "content" : "first prompt" },
163
- {"role" : "llm" , "content" : "first response" },
180
+ {
181
+ "role" : "llm" ,
182
+ "content" : "first response" ,
183
+ "metadata" : {"llm provider" : "openai" },
184
+ },
164
185
{"role" : "user" , "content" : "second prompt" },
165
186
{"role" : "llm" , "content" : "second response" },
166
187
{
@@ -182,7 +203,11 @@ def test_standard_add_messages(standard_history):
182
203
assert len (full_context ) == 8
183
204
assert full_context == [
184
205
{"role" : "user" , "content" : "first prompt" },
185
- {"role" : "llm" , "content" : "first response" },
206
+ {
207
+ "role" : "llm" ,
208
+ "content" : "first response" ,
209
+ "metadata" : {"llm provider" : "openai" },
210
+ },
186
211
{"role" : "user" , "content" : "second prompt" },
187
212
{"role" : "llm" , "content" : "second response" },
188
213
{"role" : "tool" , "content" : "tool result 1" , "tool_call_id" : "tool call one" },
@@ -198,17 +223,21 @@ def test_standard_messages_property(standard_history):
198
223
{"role" : "user" , "content" : "first prompt" },
199
224
{"role" : "llm" , "content" : "first response" },
200
225
{"role" : "user" , "content" : "second prompt" },
201
- {"role" : "llm" , "content" : "second response" },
202
- {"role" : "user" , "content" : "third prompt" },
226
+ {
227
+ "role" : "llm" ,
228
+ "content" : "second response" ,
229
+ "metadata" : {"params" : "abc" },
230
+ },
231
+ {"role" : "user" , "content" : "third prompt" , "metadata" : 42 },
203
232
]
204
233
)
205
234
206
235
assert standard_history .messages == [
207
236
{"role" : "user" , "content" : "first prompt" },
208
237
{"role" : "llm" , "content" : "first response" },
209
238
{"role" : "user" , "content" : "second prompt" },
210
- {"role" : "llm" , "content" : "second response" },
211
- {"role" : "user" , "content" : "third prompt" },
239
+ {"role" : "llm" , "content" : "second response" , "metadata" : { "params" : "abc" } },
240
+ {"role" : "user" , "content" : "third prompt" , "metadata" : 42 },
212
241
]
213
242
214
243
@@ -357,7 +386,14 @@ def test_semantic_store_and_get_recent(semantic_history):
357
386
semantic_history .add_message (
358
387
{"role" : "tool" , "content" : "tool result" , "tool_call_id" : "tool id" }
359
388
)
360
- # test default context history size
389
+ semantic_history .add_message (
390
+ {
391
+ "role" : "tool" ,
392
+ "content" : "tool result" ,
393
+ "tool_call_id" : "tool id" ,
394
+ "metadata" : "return value from tool" ,
395
+ }
396
+ ) # test default context history size
361
397
default_context = semantic_history .get_recent ()
362
398
assert len (default_context ) == 5 # 5 is default
363
399
@@ -367,10 +403,10 @@ def test_semantic_store_and_get_recent(semantic_history):
367
403
368
404
# test larger context history returns full history
369
405
too_large_context = semantic_history .get_recent (top_k = 100 )
370
- assert len (too_large_context ) == 9
406
+ assert len (too_large_context ) == 10
371
407
372
408
# test that order is maintained
373
- full_context = semantic_history .get_recent (top_k = 9 )
409
+ full_context = semantic_history .get_recent (top_k = 10 )
374
410
assert full_context == [
375
411
{"role" : "user" , "content" : "first prompt" },
376
412
{"role" : "llm" , "content" : "first response" },
@@ -381,15 +417,26 @@ def test_semantic_store_and_get_recent(semantic_history):
381
417
{"role" : "user" , "content" : "fourth prompt" },
382
418
{"role" : "llm" , "content" : "fourth response" },
383
419
{"role" : "tool" , "content" : "tool result" , "tool_call_id" : "tool id" },
420
+ {
421
+ "role" : "tool" ,
422
+ "content" : "tool result" ,
423
+ "tool_call_id" : "tool id" ,
424
+ "metadata" : "return value from tool" ,
425
+ },
384
426
]
385
427
386
428
# test that more recent entries are returned
387
429
context = semantic_history .get_recent (top_k = 4 )
388
430
assert context == [
389
- {"role" : "llm" , "content" : "third response" },
390
431
{"role" : "user" , "content" : "fourth prompt" },
391
432
{"role" : "llm" , "content" : "fourth response" },
392
433
{"role" : "tool" , "content" : "tool result" , "tool_call_id" : "tool id" },
434
+ {
435
+ "role" : "tool" ,
436
+ "content" : "tool result" ,
437
+ "tool_call_id" : "tool id" ,
438
+ "metadata" : "return value from tool" ,
439
+ },
393
440
]
394
441
395
442
# test no entries are returned and no error is raised if top_k == 0
@@ -422,11 +469,13 @@ def test_semantic_messages_property(semantic_history):
422
469
"role" : "tool" ,
423
470
"content" : "tool result 1" ,
424
471
"tool_call_id" : "tool call one" ,
472
+ "metadata" : 42 ,
425
473
},
426
474
{
427
475
"role" : "tool" ,
428
476
"content" : "tool result 2" ,
429
477
"tool_call_id" : "tool call two" ,
478
+ "metadata" : [1 , 2 , 3 ],
430
479
},
431
480
{"role" : "user" , "content" : "second prompt" },
432
481
{"role" : "llm" , "content" : "second response" },
@@ -437,8 +486,18 @@ def test_semantic_messages_property(semantic_history):
437
486
assert semantic_history .messages == [
438
487
{"role" : "user" , "content" : "first prompt" },
439
488
{"role" : "llm" , "content" : "first response" },
440
- {"role" : "tool" , "content" : "tool result 1" , "tool_call_id" : "tool call one" },
441
- {"role" : "tool" , "content" : "tool result 2" , "tool_call_id" : "tool call two" },
489
+ {
490
+ "role" : "tool" ,
491
+ "content" : "tool result 1" ,
492
+ "tool_call_id" : "tool call one" ,
493
+ "metadata" : 42 ,
494
+ },
495
+ {
496
+ "role" : "tool" ,
497
+ "content" : "tool result 2" ,
498
+ "tool_call_id" : "tool call two" ,
499
+ "metadata" : [1 , 2 , 3 ],
500
+ },
442
501
{"role" : "user" , "content" : "second prompt" },
443
502
{"role" : "llm" , "content" : "second response" },
444
503
{"role" : "user" , "content" : "third prompt" },
0 commit comments