You can use the inventory#count() method to determine how many items are currently in the inventory:
/* assuming the inventory is stored in the variable `$inv` */
<<if $inv.count() < 10>>
<<pickup '$inv' 'something'>>
<<else>>
''You cannot carry any more items.''
<</if>>
/* To drop a random item. */
<<if $inv.count() >= 10>>
<<drop '$inv' `$inv.toArray().random()`>>
<</if>>
<<pickup '$inv' 'something'>>