okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
61c43ca
main
1"""Forced LCM preparation preserves its newest tool unit and stored summaries.""" 2 3import json 4import unittest 5 6from harness import Albedo ,Provider ,python ,text 7 8 9class LcmPreparationTests (unittest .TestCase ): 10def test_forced_fold_retains_tool_tail_on_next_preparation (self ): 11def reply (request ): 12inputs = request ["input" ] 13if "<newly-evicted-history>" in json .dumps (inputs ): 14return text ("archived earlier conversation" ) 15if inputs [- 1 ].get ("type" )== "function_call_output" : 16return text ("tool finished" ) 17if inputs [- 1 ].get ("content" )== "newest tool unit" : 18return python ("print('TAIL_TOOL_OUTPUT')" ) 19return text ("ordinary answer" ) 20 21provider = Provider (reply ) 22self .addCleanup (provider .close ) 23with Albedo (provider ,protocol = "responses" )as app : 24session = app .session () 25for prompt in ("older unit one" ,"older unit two" ,"newest tool unit" ): 26app .prompt (session ,prompt ).close () 27app .idle (session ) 28with app .api ( 29f"/sessions/ { session } /compaction" , 30 {"strategy" :"lcm" }, 31 )as response : 32result = json .load (response ) 33self .assertEqual (result ["state" ],"compacted" ) 34app .idle (session ) 35app .prompt (session ,"after fold" ).close () 36app .idle (session ) 37sent = provider .requests [- 1 ]["request" ]["input" ] 38self .assertIn ("LCM summary node #" ,json .dumps (sent )) 39self .assertIn ("newest tool unit" ,json .dumps (sent )) 40self .assertIn ("TAIL_TOOL_OUTPUT" ,json .dumps (sent )) 41calls = [ 42item ["call_id" ]for item in sent if item .get ("type" )== "function_call" 43 ] 44outputs = [ 45item ["call_id" ] 46for item in sent 47if item .get ("type" )== "function_call_output" 48 ] 49self .assertEqual (calls ,outputs ) 50with app .api (f"/sessions/ { session } /context" )as response : 51observation = json .load (response )["compaction" ] 52self .assertEqual (observation ["strategy" ],"lcm" )