-
Notifications
You must be signed in to change notification settings - Fork 52.7k
[codex] Add message transport for gateway tool progress #18050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juanfradb
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
juanfradb:codex/telegram-progress-messages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10679,6 +10679,22 @@ def _run_still_current() -> bool: | |
| if _env_tp and not _tool_progress_configured | ||
| else (_resolved_tp or _env_tp or "all") | ||
| ) | ||
| progress_transport = resolve_display_setting( | ||
| user_config, | ||
| platform_key, | ||
| "tool_progress_transport", | ||
| "edit", | ||
| ) | ||
| progress_transport = str(progress_transport or "edit").lower() | ||
| progress_as_messages = progress_transport in {"messages", "message", "send", "separate"} | ||
| progress_show_results = bool( | ||
| resolve_display_setting( | ||
| user_config, | ||
| platform_key, | ||
| "tool_progress_results", | ||
| False, | ||
| ) | ||
| ) | ||
| # Disable tool progress for webhooks - they don't support message editing, | ||
| # so each progress line would be sent as a separate message. | ||
| from gateway.config import Platform | ||
|
|
@@ -10709,16 +10725,27 @@ def progress_callback(event_type: str, tool_name: str = None, preview: str = Non | |
| if not progress_queue or not _run_still_current(): | ||
| return | ||
|
|
||
| # Reasoning events are only useful when progress is rendered as | ||
| # discrete messages; edited progress bubbles would bury them. | ||
| if event_type == "reasoning.available": | ||
| if progress_as_messages and progress_mode == "verbose" and preview: | ||
| progress_queue.put(f"💭 Thinking\n```\n{str(preview).strip()}\n```") | ||
| return | ||
|
|
||
| # First-touch onboarding: the first time a tool takes longer than | ||
| # _LONG_TOOL_THRESHOLD_S during a run that's streaming every tool | ||
| # (progress_mode == "all"), append a one-time hint suggesting | ||
| # /verbose. We only fire when (a) the user hasn't seen the hint | ||
| # before and (b) /verbose is actually usable on this platform | ||
| # (gateway gate must be open). The CLI has its own trigger. | ||
| if event_type == "tool.completed" and not long_tool_hint_fired[0]: | ||
| if event_type == "tool.completed": | ||
| try: | ||
| duration = kwargs.get("duration") or 0 | ||
| if duration >= _LONG_TOOL_THRESHOLD_S and progress_mode == "all": | ||
| duration = float(kwargs.get("duration") or 0) | ||
| if ( | ||
| not long_tool_hint_fired[0] | ||
| and duration >= _LONG_TOOL_THRESHOLD_S | ||
| and progress_mode == "all" | ||
| ): | ||
| from agent.onboarding import ( | ||
| TOOL_PROGRESS_FLAG, | ||
| is_seen, | ||
|
|
@@ -10733,6 +10760,26 @@ def progress_callback(event_type: str, tool_name: str = None, preview: str = Non | |
| mark_seen(_hermes_home / "config.yaml", TOOL_PROGRESS_FLAG) | ||
| except Exception as _hint_err: | ||
| logger.debug("tool-progress onboarding hint failed: %s", _hint_err) | ||
|
|
||
| if progress_as_messages and progress_mode == "verbose" and progress_show_results: | ||
| from agent.display import get_tool_emoji, get_tool_preview_max_len | ||
| emoji = get_tool_emoji(tool_name, default="⚙️") | ||
| duration = float(kwargs.get("duration") or 0) | ||
| is_error = bool(kwargs.get("is_error", False)) | ||
| result = kwargs.get("function_result", kwargs.get("result")) | ||
| status = "errored" if is_error else "completed" | ||
| if result is None: | ||
| progress_queue.put(f"{emoji} {tool_name} {status} in {duration:.1f}s") | ||
| else: | ||
| result = str(result) | ||
| _pl = get_tool_preview_max_len() | ||
| if _pl > 0 and len(result) > _pl: | ||
| result = result[:_pl - 3] + "..." | ||
| result = result.replace("```", "` ` `").rstrip() | ||
| progress_queue.put( | ||
| f"{emoji} {tool_name} {status} in {duration:.1f}s\n" | ||
| f"```text\n{result}\n```" | ||
| ) | ||
| return | ||
|
|
||
|
|
||
|
|
@@ -10800,7 +10847,7 @@ def progress_callback(event_type: str, tool_name: str = None, preview: str = Non | |
| # Dedup: collapse consecutive identical progress messages. | ||
| # Common with execute_code where models iterate with the same | ||
| # code (same boilerplate imports → identical previews). | ||
| if msg == last_progress_msg[0]: | ||
| if not progress_as_messages and msg == last_progress_msg[0]: | ||
| repeat_count[0] += 1 | ||
| # Update the last line in progress_lines with a counter | ||
| # via a special "dedup" queue message. | ||
|
|
@@ -10833,6 +10880,46 @@ async def send_progress_messages(): | |
| if not adapter: | ||
| return | ||
|
|
||
| async def _send_progress_item(raw): | ||
| if isinstance(raw, tuple) and len(raw) == 3 and raw[0] == "__dedup__": | ||
| _, base_msg, count = raw | ||
| msg = f"{base_msg} (×{count + 1})" | ||
| else: | ||
| msg = raw | ||
| await adapter.send(chat_id=source.chat_id, content=msg, metadata=_progress_metadata) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When salvaging onto current main, route this through the shared progress-send helper rather than calling |
||
|
|
||
| if progress_as_messages: | ||
| while True: | ||
| try: | ||
| if not _run_still_current(): | ||
| while not progress_queue.empty(): | ||
| try: | ||
| progress_queue.get_nowait() | ||
| except Exception: | ||
| break | ||
| return | ||
|
|
||
| raw = progress_queue.get_nowait() | ||
| await _send_progress_item(raw) | ||
|
|
||
| await asyncio.sleep(0.1) | ||
| if _run_still_current(): | ||
| await adapter.send_typing(source.chat_id, metadata=_progress_metadata) | ||
|
|
||
| except queue.Empty: | ||
| await asyncio.sleep(0.3) | ||
| except asyncio.CancelledError: | ||
| while not progress_queue.empty(): | ||
| try: | ||
| raw = progress_queue.get_nowait() | ||
| await _send_progress_item(raw) | ||
| except Exception: | ||
| break | ||
| return | ||
| except Exception as e: | ||
| logger.error("Progress message error: %s", e) | ||
| await asyncio.sleep(1) | ||
|
|
||
| # Skip tool progress for platforms that don't support message | ||
| # editing (e.g. iMessage/BlueBubbles) — each progress update | ||
| # would become a separate message bubble, which is noisy. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current main already exposes this edit-versus-separate-message choice as
display.tool_progress_grouping: accumulate|separate(gateway/display_config.py:35, commit6373aba8). Reuse that surface during salvage rather than introduce a second transport key.