unique_toolkit 1.35.1__py3-none-any.whl → 1.35.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,6 +31,7 @@ from unique_toolkit.language_model.schemas import (
31
31
  MAX_INPUT_TOKENS_SAFETY_PERCENTAGE = (
32
32
  0.1 # 10% safety margin for input tokens we need 10% less does not work.
33
33
  )
34
+ SAFETY_MARGIN_FOR_AGGRESSIVE_REDUCTION = 0.9
34
35
 
35
36
 
36
37
  class SourceReductionResult(BaseModel):
@@ -323,10 +324,10 @@ class LoopTokenReducer:
323
324
  Reduce the message length by removing sources from each tool call based on overshoot.
324
325
 
325
326
  The number of chunks to keep per tool call is calculated as:
326
- chunks_to_keep = num_sources / (overshoot_factor * 0.75)
327
+ chunks_to_keep = num_sources / (overshoot_factor * SAFETY_MARGIN_FOR_AGGRESSIVE_REDUCTION)
327
328
 
328
329
  This ensures more aggressive reduction when we're significantly over the limit.
329
- Using 0.75 factor provides a safety margin to avoid over-reduction.
330
+ Using SAFETY_MARGIN_FOR_AGGRESSIVE_REDUCTION factor provides a safety margin to avoid over-reduction.
330
331
  E.g., if overshoot_factor = 2 (2x over limit), keep 1/1.5 = 2/3 of chunks.
331
332
  Always keeps at least 1 chunk.
332
333
  """
@@ -369,7 +370,7 @@ class LoopTokenReducer:
369
370
  """
370
371
  Reduce the sources in the tool message based on overshoot factor.
371
372
 
372
- Chunks to keep = num_sources / (overshoot_factor * 0.75)
373
+ Chunks to keep = num_sources / (overshoot_factor * SAFETY_MARGIN_FOR_AGGRESSIVE_REDUCTION)
373
374
  This ensures fewer chunks are kept when overshoot is larger.
374
375
  E.g., if overshoot_factor = 2 (2x over limit), keep 1/1.5 = 2/3 of chunks
375
376
  Always keeps at least 1 chunk.
@@ -386,14 +387,15 @@ class LoopTokenReducer:
386
387
  )
387
388
 
388
389
  # Calculate how many chunks to keep based on overshoot
389
- # Use 0.75 safety margin for aggressive reduction, but only when overshoot is
390
+ # Use SAFETY_MARGIN_FOR_AGGRESSIVE_REDUCTION safety margin for aggressive reduction, but only when overshoot is
390
391
  # significant enough (>= ~1.33). Otherwise, the margin would prevent reduction.
391
392
  divisor = (
392
- overshoot_factor * 0.75
393
- if overshoot_factor * 0.75 >= 1.0
393
+ overshoot_factor * SAFETY_MARGIN_FOR_AGGRESSIVE_REDUCTION
394
+ if overshoot_factor * SAFETY_MARGIN_FOR_AGGRESSIVE_REDUCTION
395
+ >= 1.2 # Skip safety margin for small overshoots (e.g., 1.03) to avoid tiny reduction steps
394
396
  else overshoot_factor
395
397
  )
396
- chunks_to_keep = max(1, int(num_sources / divisor))
398
+ chunks_to_keep = max(1, int(num_sources // divisor))
397
399
 
398
400
  # Reduce chunks
399
401
  if chunks_to_keep >= num_sources:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 1.35.1
3
+ Version: 1.35.2
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Cedric Klinkert
@@ -121,6 +121,9 @@ All notable changes to this project will be documented in this file.
121
121
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
122
122
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
123
123
 
124
+ ## [1.35.2] - 2025-12-05
125
+ - Increase speed of token reducer
126
+
124
127
  ## [1.35.1] - 2025-12-05
125
128
  - Improve efficiency of token reducer if tool calls overshoot max token limit
126
129
 
@@ -60,7 +60,7 @@ unique_toolkit/agentic/evaluation/tests/test_context_relevancy_service.py,sha256
60
60
  unique_toolkit/agentic/evaluation/tests/test_output_parser.py,sha256=RN_HcBbU6qy_e_PoYyUFcjWnp3ymJ6-gLj6TgEOupAI,3107
61
61
  unique_toolkit/agentic/history_manager/history_construction_with_contents.py,sha256=kzxpVzTtQqL8TjdIvOy7gkRVxD4BsOMyimECryg7vdc,9060
62
62
  unique_toolkit/agentic/history_manager/history_manager.py,sha256=7V7_173XkAjc8otBACF0G3dbqRs34FSlURbBPrE95Wk,9537
63
- unique_toolkit/agentic/history_manager/loop_token_reducer.py,sha256=PUNR2aTFBUQjD1y3gJC9YlseBUYjbQ68qfig9a65e7w,19824
63
+ unique_toolkit/agentic/history_manager/loop_token_reducer.py,sha256=3c-uonDovtanEJUpAO4zlA4-n9MS_Ws_V0Yb6G7hPM0,20172
64
64
  unique_toolkit/agentic/history_manager/utils.py,sha256=VIn_UmcR3jHtpux0qp5lQQzczgAm8XYSeQiPo87jC3A,3143
65
65
  unique_toolkit/agentic/loop_runner/__init__.py,sha256=QLCYmIyfcKQEbuv1Xm0VuR_xC8JyD2_aMIvt1TRFzvw,517
66
66
  unique_toolkit/agentic/loop_runner/_stream_handler_utils.py,sha256=FTGc5y8wkDnwnRVSYEdandgKz-FiySOsrTFFMadwP6E,1706
@@ -208,7 +208,7 @@ unique_toolkit/short_term_memory/service.py,sha256=5PeVBu1ZCAfyDb2HLVvlmqSbyzBBu
208
208
  unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
209
209
  unique_toolkit/smart_rules/compile.py,sha256=Ozhh70qCn2yOzRWr9d8WmJeTo7AQurwd3tStgBMPFLA,1246
210
210
  unique_toolkit/test_utilities/events.py,sha256=_mwV2bs5iLjxS1ynDCjaIq-gjjKhXYCK-iy3dRfvO3g,6410
211
- unique_toolkit-1.35.1.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
212
- unique_toolkit-1.35.1.dist-info/METADATA,sha256=yqoVsVNxeGXbw7h5u9I7bLt_jcB1FF-yonYPGGgUS0o,45818
213
- unique_toolkit-1.35.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
214
- unique_toolkit-1.35.1.dist-info/RECORD,,
211
+ unique_toolkit-1.35.2.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
212
+ unique_toolkit-1.35.2.dist-info/METADATA,sha256=Q6IeZ9PHeit_qWXIbzwhpgq99Es-jGP_lQbxcAFca10,45878
213
+ unique_toolkit-1.35.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
214
+ unique_toolkit-1.35.2.dist-info/RECORD,,