Skip to content
Closed
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
45 changes: 42 additions & 3 deletions agent/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dataclasses import dataclass, field
from difflib import unified_diff
from pathlib import Path
from typing import Any
from typing import Any, Optional

from utils import safe_json_loads
from agent.tool_result_classification import file_mutation_result_landed
Expand Down Expand Up @@ -160,6 +160,23 @@ def get_tool_emoji(tool_name: str, default: str = "⚡") -> str:
return default


# =========================================================================
# Delegation model label (shown alongside delegate_task progress)
# =========================================================================


def _get_delegation_model_label(provider: Optional[str] = None, model: Optional[str] = None) -> str:
"""Return a short model tag for display from actual runtime values.

Returns ``[xai-oauth/grok-build-0.1] `` (with trailing space) when
provider and model are provided, or empty string when not available.
"""
if provider or model:
parts = [p for p in [provider, model] if p]
return f"[{'/'.join(parts)}] "
return ""


# =========================================================================
# Tool preview (one-line summary of a tool call's primary argument)
# =========================================================================
Expand Down Expand Up @@ -1056,12 +1073,34 @@ def _wrap(line: str) -> str:
return _wrap(f"┊ 🐍 exec {_trunc(first_line, 35)} {dur}")
if tool_name == "delegate_task":
tasks = args.get("tasks")
# Pull actual runtime provider/model from the delegate result dict
# (populated by _run_single_child from child.provider / child.model).
provider = None
model = None
if result:
try:
if isinstance(result, str):
res = safe_json_loads(result) or {}
else:
res = result if isinstance(result, dict) else {}
results_list = res.get("results") or []
if results_list and isinstance(results_list, list):
first = results_list[0] if results_list else {}
if isinstance(first, dict):
provider = first.get("provider")
model = first.get("model")
elif isinstance(res, dict):
provider = res.get("provider")
model = res.get("model")
except Exception:
pass
tag = _get_delegation_model_label(provider=provider, model=model)
if tasks and isinstance(tasks, list):
task_count, goals = _delegate_task_goal_parts(tasks, per_goal_len=30)
detail = " | ".join(goals) if goals else "parallel"
count_label = task_count or len(tasks)
return _wrap(f"┊ 🔀 delegate {count_label}x: {_trunc(detail, 35)} {dur}")
return _wrap(f"┊ 🔀 delegate {_trunc(args.get('goal', ''), 35)} {dur}")
return _wrap(f"┊ 🔀 delegate {tag}{count_label}x: {_trunc(detail, 35)} {dur}")
return _wrap(f"┊ 🔀 delegate {tag}{_trunc(args.get('goal', ''), 35 - len(tag))} {dur}")

preview = build_tool_preview(tool_name, args) or ""
return _wrap(f"┊ ⚡ {tool_name[:9]:9} {_trunc(preview, 35)} {dur}")
Expand Down
32 changes: 27 additions & 5 deletions agent/tool_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
get_cute_tool_message as _get_cute_tool_message_impl,
get_tool_emoji as _get_tool_emoji,
_detect_tool_failure,
_get_delegation_model_label,
)
from agent.tool_guardrails import ToolGuardrailDecision
from agent.tool_dispatch_helpers import (
Expand Down Expand Up @@ -434,7 +435,11 @@ def execute_tool_calls_concurrent(agent, assistant_message, messages: list, effe
if agent.tool_progress_callback:
try:
preview = _build_tool_preview(name, args)
agent.tool_progress_callback("tool.started", name, preview, args)
agent.tool_progress_callback(
"tool.started", name, preview, args,
provider=getattr(agent, "provider", None),
model=getattr(agent, "model", None),
)
except Exception as cb_err:
logging.debug(f"Tool progress callback error: {cb_err}")

Expand Down Expand Up @@ -892,7 +897,11 @@ def execute_tool_calls_sequential(agent, assistant_message, messages: list, effe
if not _execution_blocked and agent.tool_progress_callback:
try:
preview = _build_tool_preview(function_name, function_args)
agent.tool_progress_callback("tool.started", function_name, preview, function_args)
agent.tool_progress_callback(
"tool.started", function_name, preview, function_args,
provider=getattr(agent, "provider", None),
model=getattr(agent, "model", None),
)
except Exception as cb_err:
logging.debug(f"Tool progress callback error: {cb_err}")

Expand Down Expand Up @@ -1086,14 +1095,27 @@ def _execute(next_args: dict) -> Any:
agent._vprint(f" {_get_cute_tool_message_impl('read_terminal', function_args, tool_duration, result=function_result)}")
elif function_name == "delegate_task":
tasks_arg = function_args.get("tasks")
# Read provider/model from delegation config (what the subagent
# will actually run on), NOT from the parent agent — the parent
# may be on a completely different model (e.g. deepseek-v4-flash).
_dt_provider = None
_dt_model = None
try:
from hermes_cli.config import load_config as _load_cfg
_dt_cfg = _load_cfg().get("delegation", {}) or {}
_dt_provider = _dt_cfg.get("provider")
_dt_model = _dt_cfg.get("model")
except Exception:
pass
_tag = _get_delegation_model_label(provider=_dt_provider, model=_dt_model)
if tasks_arg and isinstance(tasks_arg, list):
spinner_label = f"🔀 delegating {len(tasks_arg)} tasks · (/agents to monitor)"
spinner_label = f"🔀 {_tag}delegating {len(tasks_arg)} tasks · (/agents to monitor)"
else:
goal_preview = (function_args.get("goal") or "")[:30]
spinner_label = (
f"🔀 {goal_preview} · (/agents to monitor)"
f"🔀 {_tag}{goal_preview} · (/agents to monitor)"
if goal_preview
else "🔀 delegating · (/agents to monitor)"
else f"🔀 {_tag}delegating · (/agents to monitor)"
)
spinner = None
if agent._should_emit_quiet_tool_messages() and agent._should_start_quiet_spinner():
Expand Down
40 changes: 33 additions & 7 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13591,6 +13591,8 @@ def voice_ack_callback(call_id, tool_name, args):

def progress_callback(event_type: str, tool_name: str = None, preview: str = None, args: dict = None, **kwargs):
"""Callback invoked by agent on tool lifecycle events."""
logger.debug("PROGRESS_CB: event_type=%s tool_name=%s preview_len=%s kwargs_keys=%s",
event_type, tool_name, len(preview or ""), list(kwargs.keys()))
if not progress_queue or not _run_still_current():
return

Expand Down Expand Up @@ -13700,6 +13702,28 @@ def progress_callback(event_type: str, tool_name: str = None, preview: str = Non
_cmd_short = _cmd_short + " ..."
_code_block_short = f"{_block_header}```\n{_cmd_short}\n```"

# Inject delegation model tag for delegate_task so users see
# which LLM model the sub-agent is running on. Reads from
# delegation config explicitly — not from callback kwargs
# (which carry the *parent* agent's provider/model, not the
# subagent's).
if tool_name == "delegate_task":
from agent.display import _get_delegation_model_label
_dt_provider = None
_dt_model = None
try:
from hermes_cli.config import load_config as _load_cfg
_dt_cfg = _load_cfg().get("delegation", {}) or {}
_dt_provider = _dt_cfg.get("provider")
_dt_model = _dt_cfg.get("model")
except Exception:
pass
_dt_tag = _get_delegation_model_label(
provider=_dt_provider,
model=_dt_model,
)
else:
_dt_tag = ""
# Verbose mode: show detailed arguments, respects tool_preview_length
if progress_mode == "verbose":
if _code_block_full is not None:
Expand All @@ -13716,11 +13740,12 @@ def progress_callback(event_type: str, tool_name: str = None, preview: str = Non
# detail. Platform message-length limits handle the rest.
if _pl > 0 and len(args_str) > _pl:
args_str = args_str[:_pl - 3] + "..."
msg = f"{emoji} {tool_name}({list(args.keys())})\n{args_str}"
label = tool_name if not _dt_tag else f"{tool_name} {_dt_tag.strip()}"
msg = f"{emoji} {label}({list(args.keys())})\n{args_str}"
elif preview:
msg = f"{emoji} {tool_name}: \"{preview}\""
msg = f"{emoji} {tool_name}: \"{_dt_tag}{preview}\""
else:
msg = f"{emoji} {tool_name}..."
msg = f"{emoji} {tool_name}: {_dt_tag}..."
progress_queue.put(msg)
return

Expand All @@ -13736,12 +13761,13 @@ def progress_callback(event_type: str, tool_name: str = None, preview: str = Non
from agent.display import get_tool_preview_max_len
_pl = get_tool_preview_max_len()
_cap = _pl if _pl > 0 else 40
if len(preview) > _cap:
preview = preview[:_cap - 3] + "..."
msg = f"{emoji} {tool_name}: \"{preview}\""
_effective = f"{_dt_tag}{preview}"
if len(_effective) > _cap:
_effective = _effective[:_cap - 3] + "..."
msg = f"{emoji} {tool_name}: \"{_effective}\""
last_was_terminal_block[0] = False
else:
msg = f"{emoji} {tool_name}..."
msg = f"{emoji} {tool_name}: {_dt_tag}..."
last_was_terminal_block[0] = False

# Dedup: collapse consecutive identical progress messages.
Expand Down
9 changes: 8 additions & 1 deletion tools/delegate_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ def _build_child_progress_callback(
parent_id: Optional[str] = None,
depth: Optional[int] = None,
model: Optional[str] = None,
provider: Optional[str] = None,
toolsets: Optional[List[str]] = None,
session_ref: Optional[Dict[str, Any]] = None,
) -> Optional[callable]:
Expand All @@ -755,7 +756,7 @@ def _build_child_progress_callback(
Gateway: batches tool names and relays to parent's progress callback

The identity kwargs (``subagent_id``, ``parent_id``, ``depth``, ``model``,
``toolsets``) are threaded into every relayed event so the TUI can
``provider``, ``toolsets``) are threaded into every relayed event so the TUI can
reconstruct the live spawn tree and route per-branch controls (kill,
pause) back by ``subagent_id``. All are optional for backward compat —
older callers that ignore them still produce a flat list on the TUI.
Expand Down Expand Up @@ -792,6 +793,8 @@ def _identity_kwargs() -> Dict[str, Any]:
kw["depth"] = depth
if model is not None:
kw["model"] = model
if provider is not None:
kw["provider"] = provider
if toolsets is not None:
kw["toolsets"] = list(toolsets)
# The child's own session id — filled into the shared ref once the
Expand Down Expand Up @@ -1044,6 +1047,7 @@ def _build_child_agent(

# Resolve the child's effective model early so it can ride on every event.
effective_model_for_cb = model or getattr(parent_agent, "model", None)
effective_provider_for_cb = override_provider or getattr(parent_agent, "provider", None)

# Build progress callback to relay tool calls to parent display.
# Identity kwargs thread the subagent_id through every emitted event so the
Expand All @@ -1058,6 +1062,7 @@ def _build_child_agent(
parent_id=parent_subagent_id,
depth=tui_depth,
model=effective_model_for_cb,
provider=effective_provider_for_cb,
toolsets=child_toolsets,
session_ref=child_session_ref,
)
Expand Down Expand Up @@ -1774,6 +1779,7 @@ def _run_with_thread_capture():
_input_tokens = getattr(child, "session_prompt_tokens", 0)
_output_tokens = getattr(child, "session_completion_tokens", 0)
_model = getattr(child, "model", None)
_provider = getattr(child, "provider", None)

entry: Dict[str, Any] = {
"task_index": task_index,
Expand All @@ -1782,6 +1788,7 @@ def _run_with_thread_capture():
"api_calls": api_calls,
"duration_seconds": duration,
"model": _model if isinstance(_model, str) else None,
"provider": _provider if isinstance(_provider, str) else None,
"exit_reason": exit_reason,
"tokens": {
"input": (
Expand Down