Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Auto_Use/macOS_use/agent/main_driver/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def process_request(self, task: str) -> str:
# Note: messages_for_api has previous responses with Step 1 replaced if applicable
# normalized_json is current response (with thinking)
self._save_conversation(messages_for_api, user_message, normalized_json, image_sent, step_number)

# Remove thinking from response before adding to memory (saves tokens)
normalized_json_without_thinking = self._remove_thinking_from_response(normalized_json)

Expand Down
277 changes: 255 additions & 22 deletions Auto_Use/macOS_use/remote_connection/telegram/banner.py

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Auto_Use/macOS_use/remote_connection/telegram/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pathlib import Path

from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.error import BadRequest
from telegram.ext import (
Application,
CommandHandler,
Expand Down Expand Up @@ -692,12 +693,26 @@ def _run_agent(task, provider, model, chat_id, bot, loop):
provider_keys.get(provider_key_name) if provider_key_name else None
)

# Pipe each step's formatted response (thinking + current_goal +
# memory + verdict, with action stripped) into the compact banner.
# The agent already calls text_callback at
# main_driver/service.py:704-705 with exactly this content — same
# path the frontend's streamAgentText uses in app.py. update()
# serialises onto the banner's UI thread, so the agent loop never
# blocks on it.
def _banner_update(text: str) -> None:
try:
task_banner.update(text)
except Exception:
logger.warning("banner.update failed", exc_info=True)

agent = AgentService(
provider=provider,
model=model,
save_conversation=False,
thinking=True,
api_key=provider_api_key,
text_callback=_banner_update,
)
agent.process_request(task)
# Stop the monitor BEFORE the done message so the final scratchpad
Expand Down Expand Up @@ -731,6 +746,15 @@ def _run_agent(task, provider, model, chat_id, bot, loop):

# ── entry points ─────────────────────────────────────────────────────────────

async def _on_error(update, context):
err = context.error
# Benign: user tapped the same inline button twice, so the edit produces
# identical content. Telegram rejects it; swallow quietly.
if isinstance(err, BadRequest) and "Message is not modified" in str(err):
return
logger.error("Unhandled exception in telegram handler", exc_info=err)


def _build_telegram_app(token: str):
"""Build a python-telegram-bot Application with all our handlers wired.

Expand All @@ -744,6 +768,7 @@ def _build_telegram_app(token: str):
.post_init(_post_init)
.build()
)
app.add_error_handler(_on_error)
app.add_handler(CommandHandler("start", start_cmd))
app.add_handler(CommandHandler("reset", reset_cmd))
app.add_handler(CallbackQueryHandler(callback_handler))
Expand Down
2 changes: 1 addition & 1 deletion Auto_Use/windows_use/agent/main_driver/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def process_request(self, task: str) -> str:
# Note: messages_for_api has previous responses with Step 1 replaced if applicable
# normalized_json is current response (with thinking)
self._save_conversation(messages_for_api, user_message, normalized_json, image_sent, step_number)

# Remove thinking from response before adding to memory (saves tokens)
normalized_json_without_thinking = self._remove_thinking_from_response(normalized_json)

Expand Down
Loading
Loading