Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/askui/agent_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
LocateSettings,
)
from askui.models.shared.tools import Tool, ToolCollection
from askui.models.shared.truncation_strategies import TruncationStrategy
from askui.prompts.act_prompts import CACHE_USE_PROMPT, create_default_prompt
from askui.telemetry.otel import OtelSettings, setup_opentelemetry_tracing
from askui.tools.agent_os import AgentOs
Expand Down Expand Up @@ -59,6 +60,7 @@ def __init__(
agent_os: AgentOs | AndroidAgentOs | None = None,
settings: AgentSettings | None = None,
callbacks: list[ConversationCallback] | None = None,
truncation_strategy: TruncationStrategy | None = None,
) -> None:
load_dotenv()
self._reporter: Reporter = reporter or CompositeReporter(reporters=None)
Expand Down Expand Up @@ -87,6 +89,7 @@ def __init__(
image_qa_provider=self._image_qa_provider,
detection_provider=self._detection_provider,
reporter=self._reporter,
truncation_strategy=truncation_strategy,
callbacks=_callbacks,
)

Expand Down
3 changes: 3 additions & 0 deletions src/askui/android_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from askui.models.models import Point
from askui.models.shared.settings import ActSettings, MessageSettings
from askui.models.shared.tools import Tool
from askui.models.shared.truncation_strategies import TruncationStrategy
from askui.prompts.act_prompts import create_android_agent_prompt
from askui.tools.android.agent_os import ANDROID_KEY
from askui.tools.android.agent_os_facade import AndroidAgentOsFacade
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(
retry: Retry | None = None,
act_tools: list[Tool] | None = None,
callbacks: list[ConversationCallback] | None = None,
truncation_strategy: TruncationStrategy | None = None,
) -> None:
reporter = CompositeReporter(reporters=reporters)
self.os = PpadbAgentOs(device_identifier=device, reporter=reporter)
Expand All @@ -85,6 +87,7 @@ def __init__(
agent_os=self.os,
settings=settings,
callbacks=callbacks,
truncation_strategy=truncation_strategy,
)
self.act_tool_collection.add_agent_os(self.act_agent_os_facade)
# Override default act settings with Android-specific settings
Expand Down
3 changes: 3 additions & 0 deletions src/askui/computer_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from askui.models.models import Point
from askui.models.shared.settings import ActSettings, LocateSettings, MessageSettings
from askui.models.shared.tools import Tool
from askui.models.shared.truncation_strategies import TruncationStrategy
from askui.prompts.act_prompts import (
create_computer_agent_prompt,
)
Expand Down Expand Up @@ -81,6 +82,7 @@ def __init__(
retry: Retry | None = None,
act_tools: list[Tool] | None = None,
callbacks: list[ConversationCallback] | None = None,
truncation_strategy: TruncationStrategy | None = None,
) -> None:
reporter = CompositeReporter(reporters=reporters)
self.tools = tools or AgentToolbox(
Expand All @@ -96,6 +98,7 @@ def __init__(
agent_os=self.tools.os,
settings=settings,
callbacks=callbacks,
truncation_strategy=truncation_strategy,
)
self.act_agent_os_facade: ComputerAgentOsFacade = ComputerAgentOsFacade(
self.tools.os
Expand Down
34 changes: 15 additions & 19 deletions src/askui/models/shared/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
from askui.models.shared.settings import ActSettings
from askui.models.shared.tools import ToolCollection
from askui.models.shared.truncation_strategies import (
SimpleTruncationStrategyFactory,
SummarizingTruncationStrategy,
TruncationStrategy,
TruncationStrategyFactory,
)
from askui.reporting import NULL_REPORTER, Reporter
from askui.speaker.speaker import SpeakerResult, Speakers
Expand Down Expand Up @@ -55,7 +54,7 @@ class Conversation:
detection_provider: Detection provider (optional)
reporter: Reporter for logging messages and actions
cache_manager: Cache manager for recording/playback (optional)
truncation_strategy_factory: Factory for creating truncation strategies
truncation_strategy: truncation strategies (optional)
callbacks: List of callbacks for conversation lifecycle hooks (optional)
"""

Expand All @@ -67,7 +66,7 @@ def __init__(
detection_provider: DetectionProvider | None = None,
reporter: Reporter = NULL_REPORTER,
cache_manager: "CacheManager | None" = None,
truncation_strategy_factory: TruncationStrategyFactory | None = None,
truncation_strategy: TruncationStrategy | None = None,
callbacks: "list[ConversationCallback] | None" = None,
) -> None:
"""Initialize conversation with speakers and model providers."""
Expand All @@ -90,10 +89,6 @@ def __init__(
# Infrastructure
self._reporter = reporter
self.cache_manager = cache_manager
self._truncation_strategy_factory = (
truncation_strategy_factory or SimpleTruncationStrategyFactory()
)
self._truncation_strategy: TruncationStrategy | None = None
self._callbacks: "list[ConversationCallback]" = callbacks or []

# State for current execution (set in start())
Expand All @@ -102,6 +97,14 @@ def __init__(
self._reporters: list[Reporter] = []
self._step_index: int = 0

# truncation strategy
self._truncation_strategy = (
truncation_strategy
or SummarizingTruncationStrategy(
vlm_provider=vlm_provider,
)
)

# Track if cache execution was used (to prevent recording during playback)
self._executed_from_cache: bool = False

Expand Down Expand Up @@ -180,6 +183,7 @@ def _setup_control_loop(
reporters: list[Reporter] | None = None,
) -> None:
# Reset state
self._truncation_strategy.reset(messages)
Comment thread
programminx-askui marked this conversation as resolved.
self._executed_from_cache = False
self.speakers.reset_state()

Expand All @@ -191,16 +195,6 @@ def _setup_control_loop(
# Auto-populate speaker descriptions and switch_speaker tool
self._setup_speaker_handoff()

# Initialize truncation strategy
self._truncation_strategy = (
self._truncation_strategy_factory.create_truncation_strategy(
tools=self.tools.to_params(),
system=self.settings.messages.system,
messages=messages,
model=self.vlm_provider.model_id,
)
)

@tracer.start_as_current_span("_execute_control_loop")
def _execute_control_loop(self) -> None:
self._on_control_loop_start()
Expand Down Expand Up @@ -443,7 +437,9 @@ def get_messages(self) -> list[MessageParam]:
Returns:
List of messages in current conversation
"""
return self._truncation_strategy.messages if self._truncation_strategy else []
return (
Comment thread
programminx-askui marked this conversation as resolved.
self._truncation_strategy.full_messages if self._truncation_strategy else []
)

def get_truncation_strategy(self) -> TruncationStrategy | None:
"""Get current truncation strategy.
Expand Down
Loading
Loading