1313from askui .models .shared .settings import ActSettings
1414from askui .models .shared .tools import ToolCollection
1515from askui .models .shared .truncation_strategies import (
16- SimpleTruncationStrategyFactory ,
16+ SummarizingTruncationStrategy ,
1717 TruncationStrategy ,
18- TruncationStrategyFactory ,
1918)
2019from askui .reporting import NULL_REPORTER , Reporter
2120from askui .speaker .speaker import SpeakerResult , Speakers
@@ -55,7 +54,7 @@ class Conversation:
5554 detection_provider: Detection provider (optional)
5655 reporter: Reporter for logging messages and actions
5756 cache_manager: Cache manager for recording/playback (optional)
58- truncation_strategy_factory: Factory for creating truncation strategies
57+ truncation_strategy: truncation strategies (optional)
5958 callbacks: List of callbacks for conversation lifecycle hooks (optional)
6059 """
6160
@@ -67,7 +66,7 @@ def __init__(
6766 detection_provider : DetectionProvider | None = None ,
6867 reporter : Reporter = NULL_REPORTER ,
6968 cache_manager : "CacheManager | None" = None ,
70- truncation_strategy_factory : TruncationStrategyFactory | None = None ,
69+ truncation_strategy : TruncationStrategy | None = None ,
7170 callbacks : "list[ConversationCallback] | None" = None ,
7271 ) -> None :
7372 """Initialize conversation with speakers and model providers."""
@@ -90,10 +89,6 @@ def __init__(
9089 # Infrastructure
9190 self ._reporter = reporter
9291 self .cache_manager = cache_manager
93- self ._truncation_strategy_factory = (
94- truncation_strategy_factory or SimpleTruncationStrategyFactory ()
95- )
96- self ._truncation_strategy : TruncationStrategy | None = None
9792 self ._callbacks : "list[ConversationCallback]" = callbacks or []
9893
9994 # State for current execution (set in start())
@@ -102,6 +97,22 @@ def __init__(
10297 self ._reporters : list [Reporter ] = []
10398 self ._step_index : int = 0
10499
100+ # Truncation strategy. Conversation-owned dependencies are
101+ # auto-injected so users can pass a custom strategy with only
102+ # strategy-specific config (e.g. n_messages_to_keep) without
103+ # needing access to vlm_provider/reporter/callbacks/conversation
104+ # at construction time. ``vlm_provider`` is only injected when
105+ # not pre-set, allowing callers to override the summarization
106+ # VLM (e.g. with a cheaper model).
107+ self ._truncation_strategy : TruncationStrategy = (
108+ truncation_strategy or SummarizingTruncationStrategy ()
109+ )
110+ if self ._truncation_strategy .vlm_provider is None :
111+ self ._truncation_strategy .vlm_provider = vlm_provider
112+ self ._truncation_strategy .reporter = reporter
113+ self ._truncation_strategy .callbacks = self ._callbacks
114+ self ._truncation_strategy .conversation = self
115+
105116 # Track if cache execution was used (to prevent recording during playback)
106117 self ._executed_from_cache : bool = False
107118
@@ -180,6 +191,7 @@ def _setup_control_loop(
180191 reporters : list [Reporter ] | None = None ,
181192 ) -> None :
182193 # Reset state
194+ self ._truncation_strategy .reset (messages )
183195 self ._executed_from_cache = False
184196 self .speakers .reset_state ()
185197
@@ -191,16 +203,6 @@ def _setup_control_loop(
191203 # Auto-populate speaker descriptions and switch_speaker tool
192204 self ._setup_speaker_handoff ()
193205
194- # Initialize truncation strategy
195- self ._truncation_strategy = (
196- self ._truncation_strategy_factory .create_truncation_strategy (
197- tools = self .tools .to_params (),
198- system = self .settings .messages .system ,
199- messages = messages ,
200- model = self .vlm_provider .model_id ,
201- )
202- )
203-
204206 @tracer .start_as_current_span ("_execute_control_loop" )
205207 def _execute_control_loop (self ) -> None :
206208 self ._on_control_loop_start ()
@@ -448,7 +450,9 @@ def get_messages(self) -> list[MessageParam]:
448450 Returns:
449451 List of messages in current conversation
450452 """
451- return self ._truncation_strategy .messages if self ._truncation_strategy else []
453+ return (
454+ self ._truncation_strategy .full_messages if self ._truncation_strategy else []
455+ )
452456
453457 def get_truncation_strategy (self ) -> TruncationStrategy | None :
454458 """Get current truncation strategy.
0 commit comments