Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(platform): render canonical agent and block names in AutoPilot (#14373)

Toran Bruce Richards940b24144611
diff --git a/autogpt_platform/backend/backend/copilot/baseline/service.py b/autogpt_platform/backend/backend/copilot/baseline/service.py
index a365e1460c..c96930f46d 100644
--- a/autogpt_platform/backend/backend/copilot/baseline/service.py
+++ b/autogpt_platform/backend/backend/copilot/baseline/service.py
@@ -38,6 +38,7 @@ from backend.copilot.baseline.reasoning import (
anthropic_thinking_extra_body,
reasoning_extra_body,
)
+from backend.copilot.baseline.tool_persistence import BaselineToolPersistence
from backend.copilot.builder_context import (
build_builder_context_turn_prefix,
build_builder_system_prompt_suffix,
@@ -95,10 +96,12 @@ from backend.copilot.response_model import (
StreamTextDelta,
StreamTextEnd,
StreamTextStart,
+ StreamToolDisplayAvailable,
StreamToolInputAvailable,
StreamToolInputStart,
StreamToolOutputAvailable,
StreamUsage,
+ ToolDisplayData,
)
from backend.copilot.service import (
_build_system_prompt,
@@ -114,6 +117,7 @@ from backend.copilot.token_tracking import (
_extract_cache_creation_tokens,
persist_and_record_usage,
)
+from backend.copilot.tool_display import tool_calls_for_provider, tool_display_context
from backend.copilot.tools import (
ToolGroup,
execute_tool,
@@ -487,6 +491,9 @@ class _BaselineStreamState:
# deltas stream in. Reassigning (``state.session_messages = [...]``)
# would silently detach the emitter from the new list.
session_messages: list[ChatMessage] = field(default_factory=list)
+ tool_persistence: BaselineToolPersistence = field(
+ default_factory=BaselineToolPersistence
+ )
# Tracks how much of ``assistant_text`` has already been flushed to
# ``session.messages`` via mid-loop pending drains, so the ``finally``
# block only appends the *new* assistant text (avoiding duplication of
@@ -1029,13 +1036,16 @@ async def _baseline_llm_caller(
for tc in tool_calls_by_index.values()
]
- return LLMLoopResponse(
+ response = LLMLoopResponse(
response_text=round_text or None,
tool_calls=llm_tool_calls,
raw_response=None, # Not needed for baseline conversation updater
prompt_tokens=0, # Tracked via state accumulators
completion_tokens=0,
)
+ if response.tool_calls:
+ _begin_baseline_tool_round(state, response)
+ return response
async def _baseline_tool_executor(
@@ -1073,11 +1083,13 @@ async def _baseline_tool_executor(
success=False,
),
)
- return ToolCallResult(
- tool_call_id=tool_call_id,
- tool_name=tool_name,
- content=parse_error,
- is_error=True,
+ return state.tool_persistence.record_result(
+ ToolCallResult(
+ tool_call_id=tool_call_id,
+ tool_name=tool_name,
+ content=parse_error,
+ is_error=True,
+ )
)
_emit(
@@ -1103,26 +1115,39 @@ async def _baseline_tool_executor(
# the guide having been called. The announce-set is cleared at turn
# end; we deliberately don't touch ``session.messages`` here to avoid
# duplicating the assistant row that ``_baseline_conversation_updater``
- # will append at round end.
+ # persists at turn end.
session.announce_inflight_tool_call(tool_name, tool_args)
- try:
- result: StreamToolOutputAvailable = await execute_tool(
- tool_name=tool_name,
- parameters=tool_args,
- user_id=user_id,
- session=session,
- tool_call_id=tool_call_id,
- disabled_groups=disabled_groups,
+ def on_display_name(name: str) -> None:
+ state.tool_persistence.set_display_name(tool_call_id, name)
+ _emit(
+ state,
+ StreamToolDisplayAvailable(
+ id=tool_call_id,
+ data=ToolDisplayData(toolCallId=tool_call_id, displayName=name),
+ ),
)
+
+ try:
+ with tool_display_context(on_display_name):
+ result: StreamToolOutputAvailable = await execute_tool(
+ tool_name=tool_name,
+ parameters=tool_args,
+ user_id=user_id,
+ session=session,
+ tool_call_id=tool_call_id,
+ disabled_groups=disabled_groups,
+ )
_emit(state, result)
tool_output = (
result.output if isinstance(result.output, str) else str(result.output)
)
- return ToolCallResult(
- tool_call_id=tool_call_id,
- tool_name=tool_name,
- content=tool_output,
+ return state.tool_persistence.record_result(
+ ToolCallResult(
+ tool_call_id=tool_call_id,
+ tool_name=tool_name,
+ content=tool_output,
+ )
)
except Exception as e:
error_output = f"Tool execution error: {e}"
@@ -1141,11 +1166,13 @@ async def _baseline_tool_executor(
success=False,
),
)
- return ToolCallResult(
- tool_call_id=tool_call_id,
- tool_name=tool_name,
- content=error_output,
- is_error=True,
+ return state.tool_persistence.record_result(
+ ToolCallResult(
+ tool_call_id=tool_call_id,
+ tool_name=tool_name,
+ content=error_output,
+ is_error=True,
+ )
)
@@ -1254,9 +1281,7 @@ def _baseline_conversation_updater(
) -> None:
"""Update OpenAI message list with assistant response + tool results.
- Also records structured ChatMessage entries in ``state.session_messages``
- so the full tool-call history is persisted to the session (not just the
- concatenated assistant text).
+ Also finishes the pending tool round for session persistence.
"""
_mutate_openai_messages(messages, response, tool_results)
_record_turn_to_transcript(
@@ -1265,10 +1290,15 @@ def _baseline_conversation_updater(
transcript_builder=transcript_builder,
model=model,
)
- # Record structured messages for session persistence so tool calls
- # and tool results survive across turns and mode switches.
if state is not None and tool_results:
- assistant_msg = ChatMessage(
+ state.tool_persistence.finish(state.session_messages)
+
+
+def _begin_baseline_tool_round(
+ state: _BaselineStreamState, response: LLMLoopResponse
+) -> None:
+ state.tool_persistence.begin(
+ ChatMessage(
role="assistant",
model=state.model,
routing_source=state.routing_source,
@@ -1283,16 +1313,9 @@ def _baseline_conversation_updater(
}
for tc in response.tool_calls
],
- )
- state.session_messages.append(assistant_msg)
- for tr in tool_results:
- state.session_messages.append(
- ChatMessage(
- role="tool",
- content=tr.content,
- tool_call_id=tr.tool_call_id,
- )
- )
+ ),
+ state.session_messages,
+ )
async def _compress_session_messages(
@@ -1311,7 +1334,7 @@ async def _compress_session_messages(
if msg.content:
msg_dict["content"] = msg.content
if msg.tool_calls:
- msg_dict["tool_calls"] = msg.tool_calls
+ msg_dict["tool_calls"] = tool_calls_for_provider(msg.tool_calls)
if msg.tool_call_id:
msg_dict["tool_call_id"] = msg.tool_call_id
messages_dict.append(msg_dict)
@@ -1901,7 +1924,7 @@ async def stream_chat_completion_baseline(
if msg.content:
entry["content"] = msg.content
if msg.tool_calls:
- entry["tool_calls"] = msg.tool_calls
+ entry["tool_calls"] = tool_calls_for_provider(msg.tool_calls)
if msg.content or msg.tool_calls:
openai_messages.append(entry)
elif msg.role == "tool" and msg.tool_call_id:
@@ -2514,6 +2537,7 @@ async def stream_chat_completion_baseline(
# observe a phantom in-flight call and skip its gate, so this must
# run unconditionally.
session.clear_inflight_tool_calls()
+ state.tool_persistence.finish(state.session_messages)
# Pending messages are drained atomically at turn start and
# between tool rounds, so there's nothing to clear in finally.
diff --git a/autogpt_platform/backend/backend/copilot/baseline/service_cancellation_test.py b/autogpt_platform/backend/backend/copilot/baseline/service_cancellation_test.py
new file mode 100644
index 0000000000..819d318f80
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/baseline/service_cancellation_test.py
@@ -0,0 +1,213 @@
+"""Saved display names survive cancellation and stay out of provider requests."""
+
+import asyncio
+from collections.abc import Iterator
+from contextlib import suppress
+from unittest.mock import AsyncMock, MagicMock
+
+import pytest
+from openai.types.chat import ChatCompletionChunk
+
+from backend.copilot.baseline import service
+from backend.copilot.context import set_execution_context
+from backend.copilot.model import ChatMessage, ChatSession
+from backend.copilot.model_router import ResolvedModel
+from backend.copilot.response_model import (
+ StreamToolDisplayAvailable,
+ StreamToolOutputAvailable,
+)
+from backend.copilot.tool_display import emit_tool_display_name
+
+
+async def test_cancelled_stream_persists_named_calls_and_completed_sibling(
+ monkeypatch: pytest.MonkeyPatch, baseline_io: list[ChatSession]
+) -> None:
+ session = ChatSession.new("user-1", dry_run=False)
+ session.title = "Run two workflows"
+ session.messages.append(ChatMessage(role="user", content="Run both workflows"))
+ provider_stream = _tool_call_stream()
+ monkeypatch.setattr(
+ service, "call_provider_stream", AsyncMock(return_value=provider_stream)
+ )
+ interrupted = asyncio.Event()
+
+ async def execute(
+ *, tool_call_id: str, parameters: dict[str, str], **kwargs: object
+ ) -> StreamToolOutputAvailable:
+ assert parameters == {"library_agent_id": tool_call_id}
+ emit_tool_display_name(f"Workflow {tool_call_id}")
+ if tool_call_id == "pending":
+ try:
+ await asyncio.Future[None]()
+ finally:
+ interrupted.set()
+ return StreamToolOutputAvailable(
+ toolCallId=tool_call_id, output="actual completed result"
+ )
+
+ monkeypatch.setattr(service, "execute_tool", AsyncMock(side_effect=execute))
+ completed = asyncio.Event()
+ names: dict[str, str] = {}
+
+ async def consume() -> None:
+ async for event in service.stream_chat_completion_baseline(
+ session.session_id, user_id="user-1", session=session, is_user_message=False
+ ):
+ if isinstance(event, StreamToolDisplayAvailable):
+ names[event.data.toolCallId] = event.data.displayName
+ if isinstance(event, StreamToolOutputAvailable):
+ assert event.toolCallId == "completed"
+ completed.set()
+
+ consumer = asyncio.create_task(consume())
+ try:
+ await asyncio.wait_for(completed.wait(), timeout=5)
+ assert names == {
+ "pending": "Workflow pending",
+ "completed": "Workflow completed",
+ }
+ consumer.cancel()
+ with pytest.raises(asyncio.CancelledError):
+ await asyncio.wait_for(consumer, timeout=5)
+ finally:
+ consumer.cancel()
+ with suppress(asyncio.CancelledError):
+ await asyncio.wait_for(consumer, timeout=5)
+
+ assert interrupted.is_set()
+ provider_stream.close.assert_awaited_once()
+ [persisted] = baseline_io
+ assert [message.role for message in persisted.messages] == [
+ "user",
+ "assistant",
+ "tool",
+ ]
+ assistant, result = persisted.messages[1:]
+ assert assistant.content == "Running both workflows."
+ assert assistant.tool_calls is not None
+ assert [call["id"] for call in assistant.tool_calls] == ["pending", "completed"]
+ assert {call["id"]: call["display_name"] for call in assistant.tool_calls} == names
+ assert result.tool_call_id == "completed"
+ assert result.content == "actual completed result"
+
+
+async def test_resumed_stream_sends_clean_tool_calls_and_retains_saved_names(
+ monkeypatch: pytest.MonkeyPatch, baseline_io: list[ChatSession]
+) -> None:
+ call = {
+ "id": "saved-call",
+ "type": "function",
+ "function": {"name": "run_agent", "arguments": '{"library_agent_id":"id-1"}'},
+ }
+ assistant = ChatMessage(
+ role="assistant", tool_calls=[{**call, "display_name": "Daily report"}]
+ )
+ session = ChatSession.new("user-1", dry_run=False)
+ session.title = "Existing conversation"
+ session.messages = [
+ ChatMessage(role="user", content="Run the workflow"),
+ assistant,
+ ChatMessage(role="tool", tool_call_id="saved-call", content="Completed"),
+ ChatMessage(role="user", content="Continue"),
+ ]
+ stream = MagicMock()
+ stream.__aiter__.return_value = []
+ stream.close = AsyncMock()
+ provider = AsyncMock(return_value=stream)
+ monkeypatch.setattr(service, "call_provider_stream", provider)
+ monkeypatch.setattr(service, "download_transcript", AsyncMock(return_value=None))
+
+ async with asyncio.timeout(5):
+ async for _ in service.stream_chat_completion_baseline(
+ session.session_id, user_id="user-1", session=session, is_user_message=False
+ ):
+ pass
+
+ provider.assert_awaited_once()
+ assert provider.await_args is not None
+ [sent_assistant] = [
+ message
+ for message in provider.await_args.kwargs["messages"]
+ if message["role"] == "assistant"
+ ]
+ assert sent_assistant["tool_calls"] == [call]
+ assert assistant.tool_calls == [{**call, "display_name": "Daily report"}]
+ [persisted] = baseline_io
+ assert persisted.messages[1].tool_calls == assistant.tool_calls
+
+
+def baseline_io(monkeypatch: pytest.MonkeyPatch) -> Iterator[list[ChatSession]]:
+ persisted: list[ChatSession] = []
+
+ async def save(session: ChatSession) -> ChatSession:
+ persisted.append(session.model_copy(deep=True))
+ return session
+
+ monkeypatch.setattr(
+ service,
+ "config",
+ service.config.model_copy(
+ update={"use_e2b_sandbox": False, "use_local": False}
+ ),
+ )
+ for name, value in {
+ "drain_pending_safe": [],
+ "resolve_model_route": ResolvedModel(
+ model="anthropic/claude-sonnet-4-6", source="env"
+ ),
+ "_build_system_prompt": ("System prompt", None),
+ "is_enabled_for_user": False,
+ "is_feature_enabled": False,
+ "persist_and_record_usage": None,
+ }.items():
+ monkeypatch.setattr(service, name, AsyncMock(return_value=value))
+ monkeypatch.setattr(service, "_get_main_client", MagicMock())
+ monkeypatch.setattr(service, "upsert_chat_session", AsyncMock(side_effect=save))
+ try:
+ yield persisted
+ finally:
+ set_execution_context(None, None)
+
+
+def _tool_call_stream() -> MagicMock:
+ chunk = ChatCompletionChunk.model_validate(
+ {
+ "id": "round-1",
+ "object": "chat.completion.chunk",
+ "created": 0,
+ "model": "anthropic/claude-sonnet-4-6",
+ "choices": [
+ {
+ "index": 0,
+ "finish_reason": "tool_calls",
+ "delta": {
+ "content": "Running both workflows.",
+ "tool_calls": [
+ {
+ "index": index,
+ "id": call_id,
+ "type": "function",
+ "function": {
+ "name": "run_agent",
+ "arguments": f'{{"library_agent_id":"{call_id}"}}',
+ },
+ }
+ for index, call_id in enumerate(("pending", "completed"))
+ ],
+ },
+ }
+ ],
+ "usage": {
+ "prompt_tokens": 100,
+ "completion_tokens": 20,
+ "total_tokens": 120,
+ },
+ }
+ )
+ stream = MagicMock()
+ stream.__aiter__.return_value = [chunk]
+ stream.close = AsyncMock()
+ return stream
diff --git a/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.py b/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.py
index 066b8c185f..2dcf65d6a7 100644
--- a/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.py
+++ b/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.py
@@ -17,6 +17,7 @@ from backend.copilot.baseline.service import (
_baseline_llm_caller,
_baseline_tool_executor,
_BaselineStreamState,
+ _begin_baseline_tool_round,
_budget_exhausted_notice_text,
_build_budget_exhausted_fallback_events,
_build_cached_system_message,
@@ -263,6 +264,9 @@ class TestBaselineConversationUpdater:
tool_results = [
ToolCallResult(tool_call_id="tc_1", tool_name="search", content="ok"),
]
+ _begin_baseline_tool_round(state, response)
+ for result in tool_results:
+ state.tool_persistence.record_result(result)
_baseline_conversation_updater(
messages,
@@ -1255,6 +1259,9 @@ class TestMidLoopPendingFlushOrdering:
),
]
openai_messages: list = []
+ _begin_baseline_tool_round(state, response)
+ for result in tool_results:
+ state.tool_persistence.record_result(result)
_baseline_conversation_updater(
openai_messages,
response,
@@ -1290,6 +1297,9 @@ class TestMidLoopPendingFlushOrdering:
tool_call_id="tc_2", tool_name="calc", content="calc output"
),
]
+ _begin_baseline_tool_round(state, response2)
+ for result in tool_results2:
+ state.tool_persistence.record_result(result)
_baseline_conversation_updater(
openai_messages,
response2,
@@ -1356,14 +1366,15 @@ class TestMidLoopPendingFlushOrdering:
prompt_tokens=0,
completion_tokens=0,
)
+ result = ToolCallResult(
+ tool_call_id="tc_1", tool_name="search", content="result"
+ )
+ _begin_baseline_tool_round(state, response1)
+ state.tool_persistence.record_result(result)
_baseline_conversation_updater(
[],
response1,
- tool_results=[
- ToolCallResult(
- tool_call_id="tc_1", tool_name="search", content="result"
- )
- ],
+ tool_results=[result],
transcript_builder=builder,
state=state,
model="test-model",
diff --git a/autogpt_platform/backend/backend/copilot/baseline/tool_display_test.py b/autogpt_platform/backend/backend/copilot/baseline/tool_display_test.py
new file mode 100644
index 0000000000..eb7fb5bb07
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/baseline/tool_display_test.py
@@ -0,0 +1,99 @@
+"""Baseline tool names stream before execution finishes and survive hydration."""
+
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import pytest
+
+from backend.copilot.baseline import service
+from backend.copilot.baseline.service import (
+ _baseline_conversation_updater,
+ _baseline_tool_executor,
+ _BaselineStreamState,
+ _begin_baseline_tool_round,
+)
+from backend.copilot.model import ChatMessage, ChatSession
+from backend.copilot.response_model import StreamToolOutputAvailable
+from backend.copilot.sharing.models import sanitize_chat_message
+from backend.copilot.tool_display import emit_tool_display_name
+from backend.copilot.transcript_builder import TranscriptBuilder
+from backend.util.prompt import CompressResult
+from backend.util.tool_call_loop import LLMLoopResponse, LLMToolCall
+
+
[email protected]("fails", [False, True])
+async def test_tool_display_streams_and_persists_before_tool_result(fails: bool):
+ state = _BaselineStreamState()
+ session = ChatSession.new("user-1", dry_run=False)
+ call = LLMToolCall(
+ id="call-1", name="run_agent", arguments='{"library_agent_id":"id-1"}'
+ )
+ response = LLMLoopResponse(response_text="", tool_calls=[call], raw_response=None)
+ _begin_baseline_tool_round(state, response)
+
+ async def execute(**kwargs):
+ emit_tool_display_name("Daily report")
+ assert state.session_messages[0].tool_calls[0]["display_name"] == "Daily report"
+ event = state.emitted_events[-1]
+ assert event.model_dump(mode="json") == {
+ "type": "data-tool-display",
+ "id": "call-1",
+ "data": {"toolCallId": "call-1", "displayName": "Daily report"},
+ }
+ if fails:
+ raise RuntimeError("execution failed")
+ return StreamToolOutputAvailable(
+ toolCallId=kwargs["tool_call_id"], output="done"
+ )
+
+ with patch(
+ "backend.copilot.baseline.service.execute_tool",
+ new=AsyncMock(side_effect=execute),
+ ):
+ result = await _baseline_tool_executor(
+ call, [], state=state, user_id="user-1", session=session, disabled_groups=[]
+ )
+ messages: list[dict] = []
+ _baseline_conversation_updater(
+ messages,
+ response,
+ [result],
+ transcript_builder=TranscriptBuilder(),
+ state=state,
+ )
+ assistant = state.session_messages[0]
+ assert assistant.tool_calls[0]["display_name"] == "Daily report"
+ restored = ChatMessage.model_validate_json(assistant.model_dump_json())
+ assert (
+ sanitize_chat_message(restored).tool_calls[0]["display_name"] == "Daily report"
+ )
+
+
+async def test_compression_receives_clean_tool_calls_without_mutating_saved_names():
+ call = {
+ "id": "call-1",
+ "type": "function",
+ "function": {"name": "run_agent", "arguments": '{"library_agent_id":"id-1"}'},
+ }
+ message = ChatMessage(
+ role="assistant", tool_calls=[{**call, "display_name": "Daily report"}]
+ )
+ compress = AsyncMock(
+ return_value=CompressResult(messages=[], token_count=10, was_compacted=False)
+ )
+ with (
+ patch("backend.copilot.baseline.service.compress_context", new=compress),
+ patch(
+ "backend.copilot.baseline.service._get_main_client",
+ return_value=MagicMock(),
+ ),
+ ):
+ await service._compress_session_messages(
+ [message], model="anthropic/claude-sonnet-4-6"
+ )
+
+ compress.assert_awaited_once()
+ assert compress.await_args is not None
+ assert compress.await_args.kwargs["messages"][0]["tool_calls"] == [call]
+ assert message.tool_calls == [{**call, "display_name": "Daily report"}]
diff --git a/autogpt_platform/backend/backend/copilot/baseline/tool_persistence.py b/autogpt_platform/backend/backend/copilot/baseline/tool_persistence.py
new file mode 100644
index 0000000000..150880e81b
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/baseline/tool_persistence.py
@@ -0,0 +1,47 @@
+"""Retain a baseline tool round while its concurrent executions are pending."""
+
+from pydantic import BaseModel, Field
+
+from backend.copilot.model import ChatMessage
+from backend.util.tool_call_loop import ToolCallResult
+
+
+class BaselineToolPersistence(BaseModel):
+ pending_message: ChatMessage | None = None
+ results: dict[str, ToolCallResult] = Field(default_factory=dict)
+
+ def begin(self, message: ChatMessage, messages: list[ChatMessage]) -> None:
+ if self.pending_message is not None:
+ return
+ self.pending_message = message
+ messages.append(message)
+
+ def set_display_name(self, tool_call_id: str, name: str) -> None:
+ message = self.pending_message
+ if message is None:
+ return
+ for call in message.tool_calls or []:
+ if call["id"] == tool_call_id:
+ call["display_name"] = name
+ message.mark_tool_calls_pending_save()
+ return
+
+ def record_result(self, result: ToolCallResult) -> ToolCallResult:
+ self.results[result.tool_call_id] = result
+ return result
+
+ def finish(self, messages: list[ChatMessage]) -> None:
+ """Flush actual results once, leaving interrupted calls visibly pending.
+
+ Provider context drops incomplete rounds; saved history retains
+ the named calls and their actual results.
+ """
+ if self.pending_message is None:
+ return
+ messages.extend(
+ ChatMessage(role="tool", content=result.content, tool_call_id=call["id"])
+ for call in self.pending_message.tool_calls or []
+ if (result := self.results.get(call["id"])) is not None
+ )
+ self.pending_message = None
+ self.results.clear()
diff --git a/autogpt_platform/backend/backend/copilot/response_model.py b/autogpt_platform/backend/backend/copilot/response_model.py
index f1500b971b..c4f5967f76 100644
--- a/autogpt_platform/backend/backend/copilot/response_model.py
+++ b/autogpt_platform/backend/backend/copilot/response_model.py
@@ -47,6 +47,7 @@ class ResponseType(str, Enum):
TOOL_INPUT_START = "tool-input-start"
TOOL_INPUT_AVAILABLE = "tool-input-available"
TOOL_OUTPUT_AVAILABLE = "tool-output-available"
+ TOOL_DISPLAY_AVAILABLE = "data-tool-display"
# Other
ERROR = "error"
@@ -200,6 +201,19 @@ class StreamToolInputAvailable(StreamBaseResponse):
)
+class ToolDisplayData(BaseModel):
+ toolCallId: str
+ displayName: str
+
+
+class StreamToolDisplayAvailable(StreamBaseResponse):
+ """Resolved display name, retained as an AI SDK data part on replay."""
+
+ type: ResponseType = ResponseType.TOOL_DISPLAY_AVAILABLE
+ id: str
+ data: ToolDisplayData
+
+
_MAX_TOOL_OUTPUT_SIZE = 100_000 # ~100 KB; truncate to avoid bloating SSE/DB
diff --git a/autogpt_platform/backend/backend/copilot/response_model_test.py b/autogpt_platform/backend/backend/copilot/response_model_test.py
index b605e6797a..c993fe83d8 100644
--- a/autogpt_platform/backend/backend/copilot/response_model_test.py
+++ b/autogpt_platform/backend/backend/copilot/response_model_test.py
@@ -9,9 +9,23 @@ from backend.copilot.response_model import (
ResponseType,
StreamCompactionProgress,
StreamModeChanged,
+ StreamToolDisplayAvailable,
+ ToolDisplayData,
)
+def test_tool_display_serializes_as_persistent_ai_sdk_data_part():
+ event = StreamToolDisplayAvailable(
+ id="call-1",
+ data=ToolDisplayData(toolCallId="call-1", displayName='Résumé "Daily"'),
+ )
+ assert json.loads(event.to_sse().removeprefix("data: ")) == {
+ "type": "data-tool-display",
+ "id": "call-1",
+ "data": {"toolCallId": "call-1", "displayName": 'Résumé "Daily"'},
+ }
+
+
def test_mode_changed_serializes_as_ai_sdk_data_part():
"""The frontend reads ``dataPart.data.mode`` — mode must be nested under
``data``, not serialized as a top-level sibling of ``type``."""
diff --git a/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py b/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py
index ac5031f069..f646347792 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py
@@ -46,6 +46,7 @@ from backend.copilot.response_model import (
)
from .tool_adapter import MCP_TOOL_PREFIX, pop_pending_tool_output
+from .tool_display import strip_display_token
logger = logging.getLogger(__name__)
@@ -355,6 +356,7 @@ class SDKResponseAdapter:
# Strip MCP prefix so frontend sees "find_block"
# instead of "mcp__copilot__find_block".
tool_name = block.name.strip().removeprefix(MCP_TOOL_PREFIX)
+ tool_input = strip_display_token(block.input)
responses.append(
StreamToolInputStart(toolCallId=block.id, toolName=tool_name)
@@ -363,12 +365,12 @@ class SDKResponseAdapter:
StreamToolInputAvailable(
toolCallId=block.id,
toolName=tool_name,
- input=block.input,
+ input=tool_input,
)
)
self.current_tool_calls[block.id] = {
"name": tool_name,
- "input": block.input,
+ "input": tool_input,
}
elif isinstance(sdk_message, UserMessage):
diff --git a/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py b/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py
index c855167a15..d697220cc1 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py
@@ -26,6 +26,7 @@ from .tool_adapter import (
WORKSPACE_SCOPED_TOOLS,
stash_pending_tool_output,
)
+from .tool_display import SDKToolDisplayBridge
logger = logging.getLogger(__name__)
@@ -186,6 +187,7 @@ def create_security_hooks(
sdk_cwd: str | None = None,
max_subtasks: int = 3,
on_compact: Callable[[str], None] | None = None,
+ tool_display_bridge: SDKToolDisplayBridge | None = None,
) -> dict[HookEvent, list[HookMatcher]]:
"""Create the security hooks configuration for Claude Agent SDK.
@@ -276,6 +278,20 @@ def create_security_hooks(
subagent_tool_use_ids.add(tool_use_id)
logger.debug(f"[SDK] Tool start: {tool_name}, user={user_id}")
+ if (
+ is_copilot_tool
+ and clean_name in {"run_agent", "run_block", "continue_run_block"}
+ and tool_use_id is not None
+ and tool_display_bridge is not None
+ ):
+ return {
+ "hookSpecificOutput": {
+ "hookEventName": "PreToolUse",
+ "updatedInput": tool_display_bridge.prepare_call(
+ clean_name, tool_input, tool_use_id
+ ),
+ }
+ }
return cast(SyncHookJSONOutput, {})
def _release_subagent_slot(tool_name: str, tool_use_id: str | None) -> None:
diff --git a/autogpt_platform/backend/backend/copilot/sdk/service.py b/autogpt_platform/backend/backend/copilot/sdk/service.py
index 9d459e0dce..db6c3912d9 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/service.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/service.py
@@ -53,6 +53,7 @@ from backend.copilot.provider_failure import ProviderFailure
from backend.copilot.segments import Segment, stamp_segment
from backend.copilot.graphiti.ingest import enqueue_conversation_turn
from backend.copilot.sdk.codex_compat_gateway import CodexAnthropicGateway
+from backend.copilot.tool_display import tool_calls_for_provider
from backend.data.db_accessors import chat_db
from backend.data.redis_client import get_redis_async
from backend.executor.cluster_lock import AsyncClusterLock
@@ -139,6 +140,7 @@ from ..response_model import (
StreamTextDelta,
StreamTextEnd,
StreamTextStart,
+ StreamToolDisplayAvailable,
StreamToolInputAvailable,
StreamToolInputStart,
StreamToolOutputAvailable,
@@ -202,6 +204,11 @@ from .tool_adapter import (
set_execution_context,
wait_for_stash,
)
+from .tool_display import (
+ SDKToolDisplayBridge,
+ stamp_tool_display_name,
+ strip_display_token,
+)
logger = logging.getLogger(__name__)
config = ChatConfig()
@@ -376,7 +383,17 @@ async def _consume_sdk_until_done(
fires a synthetic re-prompt and invokes this again for the second
pass — bounded to one re-prompt per turn.
"""
- async for sdk_msg in _iter_sdk_messages(client, wake=ctx.compaction.hook_fired):
+ async for sdk_msg in _iter_sdk_messages(
+ client,
+ wake=ctx.compaction.hook_fired,
+ tool_display_wake=ctx.tool_display.ready if ctx.tool_display else None,
+ ):
+ for display in ctx.tool_display.drain() if ctx.tool_display else []:
+ dispatched = _dispatch_response(
+ display, acc, ctx, state, False, ctx.log_prefix
+ )
+ if dispatched is not None:
+ yield dispatched
# Heartbeat sentinel — refresh lock and keep SSE alive
if sdk_msg is None:
await ctx.lock.refresh()
@@ -1141,6 +1158,7 @@ _RETRYABLE_STREAM_ERROR_CODES: frozenset[str] = frozenset(
# ``None`` when ``events_yielded > 0``.
_EPHEMERAL_EVENT_TYPES = (
StreamHeartbeat,
+ StreamToolDisplayAvailable,
# Compaction UI events are cosmetic and must not block retry — they're
# emitted before the SDK query on compacted attempts.
StreamStartStep,
@@ -1370,6 +1388,7 @@ class _StreamContext:
# failed: by the time a provider failure reaches this layer it is CLI
# text, and the gateway holds the last point at which it was typed.
codex_gateway: "CodexAnthropicGateway | None" = None
+ tool_display: SDKToolDisplayBridge | None = None
# Per-retry token budgets for the no-transcript (use_resume=False) path.
@@ -2007,6 +2026,7 @@ async def _safe_close_sdk_client(
async def _iter_sdk_messages(
client: ClaudeSDKClient,
wake: asyncio.Event | None = None,
+ tool_display_wake: asyncio.Event | None = None,
) -> AsyncGenerator[Any, None]:
"""Yield SDK messages with heartbeat-based timeouts.
@@ -2032,7 +2052,7 @@ async def _iter_sdk_messages(
"""
msg_iter = client.receive_response().__aiter__()
pending_task: asyncio.Task[Any] | None = None
- wake_task: asyncio.Task[Any] | None = None
+ wake_tasks: dict[asyncio.Task[bool], asyncio.Event] = {}
async def _next_msg() -> Any:
"""Await the next SDK message, wrapped for use with `asyncio.Task`."""
@@ -2043,10 +2063,10 @@ async def _iter_sdk_messages(
if pending_task is None:
pending_task = asyncio.create_task(_next_msg())
waiters: set[asyncio.Task[Any]] = {pending_task}
- if wake is not None:
- if wake_task is None:
- wake_task = asyncio.create_task(wake.wait())
- waiters.add(wake_task)
+ for event in (wake, tool_display_wake):
+ if event is not None and event not in wake_tasks.values():
+ wake_tasks[asyncio.create_task(event.wait())] = event
+ waiters.update(wake_tasks)
done, _ = await asyncio.wait(
waiters,
@@ -2054,12 +2074,13 @@ async def _iter_sdk_messages(
return_when=asyncio.FIRST_COMPLETED,
)
- if wake is not None and wake_task in done:
+ completed_wakes = [task for task in wake_tasks if task in done]
+ if completed_wakes:
# Woken: hand the sentinel over BEFORE any message that
# landed in the same tick, or the row the hook announced
# would be closed by the very message meant to follow it.
- wake_task = None
- wake.clear()
+ for task in completed_wakes:
+ wake_tasks.pop(task).clear()
yield None
continue
@@ -2073,7 +2094,7 @@ async def _iter_sdk_messages(
except StopAsyncIteration:
return
finally:
- for task in (pending_task, wake_task):
+ for task in (pending_task, *wake_tasks):
if task is not None and not task.done():
task.cancel()
try:
@@ -2707,7 +2728,7 @@ def _format_sdk_content_blocks(blocks: list) -> list[dict[str, Any]]:
"type": "tool_use",
"id": block.id,
"name": block.name,
- "input": block.input,
+ "input": strip_display_token(block.input),
}
)
elif isinstance(block, ToolResultBlock):
@@ -2766,7 +2787,7 @@ def _to_compress_dict(msg: ChatMessage) -> dict[str, Any]:
if msg.content:
payload["content"] = msg.content
if msg.tool_calls:
- payload["tool_calls"] = msg.tool_calls
+ payload["tool_calls"] = tool_calls_for_provider(msg.tool_calls)
if msg.tool_call_id:
payload["tool_call_id"] = msg.tool_call_id
return payload
@@ -3594,6 +3615,7 @@ class _StreamAccumulator:
# inline with text/tool rows so they survive session reload; the reader
# filters role="reasoning" out of LLM context.
reasoning_response: ChatMessage | None = None
+ tool_display_names: dict[str, str] = dataclass_field(default_factory=dict)
def _dispatch_response(
@@ -3703,6 +3725,15 @@ def _dispatch_response(
ctx.session.messages.append(acc.assistant_response)
acc.has_appended_assistant = True
+ elif isinstance(response, StreamToolDisplayAvailable):
+ display = response.data
+ acc.tool_display_names[display.toolCallId] = display.displayName
+ stamp_tool_display_name(
+ [acc.assistant_response, *ctx.session.messages],
+ display.toolCallId,
+ display.displayName,
+ )
+
elif isinstance(response, StreamToolInputAvailable):
acc.accumulated_tool_calls.append(
{
@@ -3714,6 +3745,8 @@ def _dispatch_response(
},
}
)
+ if name := acc.tool_display_names.get(response.toolCallId):
+ acc.accumulated_tool_calls[-1]["display_name"] = name
acc.assistant_response.tool_calls = acc.accumulated_tool_calls
acc.assistant_response.mark_tool_calls_pending_save()
if not acc.has_appended_assistant:
@@ -4639,6 +4672,7 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
compaction: CompactionTracker | None = None
codex_effort: "CodexReasoningEffort | None" = None
codex_gateway: CodexAnthropicGateway | None = None
+ tool_display_bridge = SDKToolDisplayBridge()
deferred_codex_cleanup_error: BaseException | None = None
is_codex_transport = credential_lease is not None
turn_segment = _sdk_serving_segment(credential_lease)
@@ -4827,7 +4861,9 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
| {"get_agent_building_guide"}
)
mcp_server = create_copilot_mcp_server(
- use_e2b=use_e2b, hidden_tool_names=hidden_tools
+ use_e2b=use_e2b,
+ hidden_tool_names=hidden_tools,
+ tool_display_bridge=tool_display_bridge,
)
# Resolve model (request tier → LD per-user override → config default).
@@ -4882,6 +4918,7 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
sdk_cwd=sdk_cwd,
max_subtasks=config.claude_agent_max_subtasks,
on_compact=compaction.on_compact,
+ tool_display_bridge=tool_display_bridge,
)
if permissions is not None:
@@ -5297,6 +5334,7 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
compaction=compaction,
lock=lock,
codex_gateway=codex_gateway,
+ tool_display=tool_display_bridge,
)
# ---------------------------------------------------------------
@@ -5355,6 +5393,7 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
# the name-keyed FIFO would otherwise serve them (off-by-one) to
# this attempt's tool calls, corrupting frontend tool payloads.
reset_pending_tool_outputs()
+ tool_display_bridge.reset()
# Reset tool-level circuit breaker so failures from a previous
# (rolled-back) attempt don't carry over to the fresh attempt.
reset_tool_failure_counters()
@@ -5832,6 +5871,7 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
raise
finally:
turn_error = sys.exception()
+ tool_display_bridge.reset()
# Pending messages are drained atomically at the start of each
# turn (see drain_pending_messages call above), so there's
# nothing to clean up here — any message pushed after that
diff --git a/autogpt_platform/backend/backend/copilot/sdk/service_test.py b/autogpt_platform/backend/backend/copilot/sdk/service_test.py
index 8cdff18c11..ec7cf909b6 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/service_test.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/service_test.py
@@ -1586,7 +1586,7 @@ class TestConsumeSdkUntilDone:
acc = self._acc()
loop_state = self._loop_state()
- async def fake_iter(client, wake=None):
+ async def fake_iter(client, wake=None, tool_display_wake=None):
yield AssistantMessage(content=[TextBlock(text="hi")], model="test")
yield ResultMessage(
subtype="success",
@@ -1631,7 +1631,7 @@ class TestConsumeSdkUntilDone:
acc = self._acc()
loop_state = self._loop_state()
- async def fake_iter(client, wake=None):
+ async def fake_iter(client, wake=None, tool_display_wake=None):
yield None # heartbeat
yield ResultMessage(
subtype="success",
@@ -1680,7 +1680,7 @@ class TestConsumeSdkUntilDone:
acc = self._acc()
loop_state = self._loop_state()
- async def fake_iter(client, wake=None):
+ async def fake_iter(client, wake=None, tool_display_wake=None):
yield AssistantMessage(
content=[
ToolUseBlock(id="t1", name=f"{MCP_TOOL_PREFIX}find_block", input={})
@@ -1749,7 +1749,7 @@ class TestConsumeSdkUntilDone:
acc = self._acc()
loop_state = self._loop_state()
- async def fake_iter(client, wake=None):
+ async def fake_iter(client, wake=None, tool_display_wake=None):
yield SystemMessage(subtype="init", data={})
yield AssistantMessage(
content=[
@@ -1811,7 +1811,7 @@ class TestConsumeSdkUntilDone:
acc = self._acc()
loop_state = self._loop_state()
- async def fake_iter(client, wake=None):
+ async def fake_iter(client, wake=None, tool_display_wake=None):
yield ResultMessage(
subtype="error",
duration_ms=1,
@@ -1850,7 +1850,7 @@ class TestConsumeSdkUntilDone:
acc = self._acc()
loop_state = self._loop_state()
- async def fake_iter(client, wake=None):
+ async def fake_iter(client, wake=None, tool_display_wake=None):
yield SystemMessage(subtype="task_progress", data={"step": 1})
yield ResultMessage(
subtype="success",
@@ -1889,7 +1889,7 @@ class TestConsumeSdkUntilDone:
acc = self._acc()
loop_state = self._loop_state()
- async def fake_iter(client, wake=None):
+ async def fake_iter(client, wake=None, tool_display_wake=None):
# Two consecutive AssistantMessages with empty tool args —
# the breaker counter should advance but not yet trip.
for i in range(2):
@@ -2130,7 +2130,7 @@ class TestStreamEndedWithoutResultMessage:
ctx = self._ctx()
state = self._state()
- async def empty_iter(_client, wake=None):
+ async def empty_iter(_client, wake=None, tool_display_wake=None):
# Drain immediately — no ResultMessage ever arrives. Mirrors
# the CLI exiting on per-query ``max_budget_usd`` exhaustion
# mid-tool-call.
diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py
index 0a8b593819..90362b5238 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py
@@ -55,6 +55,7 @@ from .e2b_file_tools import (
get_read_tool_handler,
get_write_tool_handler,
)
+from .tool_display import SDKToolDisplayBridge
if TYPE_CHECKING:
from e2b import AsyncSandbox
@@ -722,6 +723,7 @@ def _make_truncating_wrapper(
tool_name: str,
input_schema: dict[str, Any] | None = None,
required_args: list[str] | None = None,
+ tool_display_bridge: SDKToolDisplayBridge | None = None,
):
"""Return a wrapper around *fn* that truncates output, stashes it for the
frontend SSE stream, and strips LLM-revealing fields before returning.
@@ -741,7 +743,7 @@ def _make_truncating_wrapper(
Swapping this order would cause the frontend to lose ``is_dry_run``.
"""
- async def wrapper(args: dict[str, Any]) -> dict[str, Any]:
+ async def execute(args: dict[str, Any]) -> dict[str, Any]:
# Detect empty-args truncation: args is empty AND the original tool
# declared at least one *required* property. Tools whose params are all
# optional (filters-only tools like list_schedules) legitimately accept
@@ -825,6 +827,12 @@ def _make_truncating_wrapper(
return truncated
+ async def wrapper(args: dict[str, Any]) -> dict[str, Any]:
+ if tool_display_bridge is None:
+ return await execute(args)
+ with tool_display_bridge.execution_context(tool_name, args) as clean_args:
+ return await execute(clean_args)
+
return wrapper
@@ -832,6 +840,7 @@ def create_copilot_mcp_server(
*,
use_e2b: bool = False,
hidden_tool_names: Iterable[str] = (),
+ tool_display_bridge: SDKToolDisplayBridge | None = None,
):
"""Create an in-process MCP server configuration for CoPilot tools.
@@ -880,7 +889,11 @@ def create_copilot_mcp_server(
annotations=_PARALLEL_ANNOTATION,
)(
_make_truncating_wrapper(
- handler, tool_name, input_schema=schema, required_args=required
+ handler,
+ tool_name,
+ input_schema=schema,
+ required_args=required,
+ tool_display_bridge=tool_display_bridge,
)
)
sdk_tools.append(decorated)
diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_display.py b/autogpt_platform/backend/backend/copilot/sdk/tool_display.py
new file mode 100644
index 0000000000..d5cc610797
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_display.py
@@ -0,0 +1,99 @@
+"""Correlate SDK MCP executions with provider tool calls without matching arguments."""
+
+import asyncio
+import uuid
+from collections.abc import Iterable, Iterator
+from contextlib import contextmanager
+from typing import TYPE_CHECKING, Any
+
+from pydantic import BaseModel
+
+from backend.copilot.response_model import StreamToolDisplayAvailable, ToolDisplayData
+from backend.copilot.tool_display import tool_display_context
+
+if TYPE_CHECKING:
+ from backend.copilot.model import ChatMessage
+
+_TOKEN_KEY = "__agpt_display_token"
+
+
+class _CallBinding(BaseModel):
+ tool_name: str
+ call_id: str
+ generation: int
+
+
+class SDKToolDisplayBridge:
+ """Bind PreToolUse IDs to MCP handlers, which receive only arguments.
+
+ A one-use token travels through the hook's updatedInput and is stripped
+ before execution. This also distinguishes concurrent identical calls.
+ Retry generations prevent callbacks from abandoned calls leaking forward.
+ """
+
+ def __init__(self) -> None:
+ self.ready = asyncio.Event()
+ self._generation = 0
+ self._bindings: dict[str, _CallBinding] = {}
+ self._pending: list[StreamToolDisplayAvailable] = []
+ self._names: dict[str, str] = {}
+
+ def prepare_call(
+ self, tool_name: str, arguments: dict[str, Any], call_id: str
+ ) -> dict[str, Any]:
+ token = uuid.uuid4().hex
+ self._bindings[token] = _CallBinding(
+ tool_name=tool_name, call_id=call_id, generation=self._generation
+ )
+ return {**strip_display_token(arguments), _TOKEN_KEY: token}
+
+ @contextmanager
+ def execution_context(
+ self, tool_name: str, arguments: dict[str, Any]
+ ) -> Iterator[dict[str, Any]]:
+ token = arguments.get(_TOKEN_KEY)
+ binding = self._bindings.pop(token, None) if isinstance(token, str) else None
+ if binding is not None and binding.tool_name != tool_name:
+ binding = None
+ with tool_display_context(lambda name: self._publish(binding, name)):
+ yield strip_display_token(arguments)
+
+ def drain(self) -> list[StreamToolDisplayAvailable]:
+ pending, self._pending = self._pending, []
+ self.ready.clear()
+ return pending
+
+ def reset(self) -> None:
+ self._generation += 1
+ self._bindings.clear()
+ self._pending.clear()
+ self._names.clear()
+ self.ready.clear()
+
+ def _publish(self, binding: _CallBinding | None, name: str) -> None:
+ if binding is None or binding.generation != self._generation:
+ return
+ if self._names.get(binding.call_id) == name:
+ return
+ self._names[binding.call_id] = name
+ self._pending.append(
+ StreamToolDisplayAvailable(
+ id=binding.call_id,
+ data=ToolDisplayData(toolCallId=binding.call_id, displayName=name),
+ )
+ )
+ self.ready.set()
+
+
+def strip_display_token(arguments: dict[str, Any]) -> dict[str, Any]:
+ return {key: value for key, value in arguments.items() if key != _TOKEN_KEY}
+
+
+def stamp_tool_display_name(
+ messages: Iterable["ChatMessage"], call_id: str, display_name: str
+) -> None:
+ for message in messages:
+ for call in message.tool_calls or []:
+ if call.get("id") == call_id and call.get("display_name") != display_name:
+ call["display_name"] = display_name
+ message.mark_tool_calls_pending_save()
diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_display_integration_test.py b/autogpt_platform/backend/backend/copilot/sdk/tool_display_integration_test.py
new file mode 100644
index 0000000000..9faedabb67
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_display_integration_test.py
@@ -0,0 +1,251 @@
+import asyncio
+import json
+import re
+from datetime import datetime, timezone
+from unittest.mock import AsyncMock, MagicMock
+
+import pytest
+from claude_agent_sdk import AssistantMessage, ToolUseBlock, create_sdk_mcp_server, tool
+from mcp.shared.memory import create_connected_server_and_client_session
+
+from backend.copilot.model import ChatMessage, ChatSession
+from backend.copilot.response_model import (
+ StreamToolDisplayAvailable,
+ StreamToolInputAvailable,
+ StreamToolOutputAvailable,
+ ToolDisplayData,
+)
+from backend.copilot.sdk.response_adapter import SDKResponseAdapter
+from backend.copilot.sdk.security_hooks import create_security_hooks
+from backend.copilot.sdk.service import (
+ _dispatch_response,
+ _format_sdk_content_blocks,
+ _iter_sdk_messages,
+ _StreamAccumulator,
+)
+from backend.copilot.sdk.tool_adapter import (
+ _build_input_schema,
+ _execute_tool_sync,
+ _make_truncating_wrapper,
+ pop_pending_tool_output,
+ set_execution_context,
+)
+from backend.copilot.sdk.tool_display import SDKToolDisplayBridge
+from backend.copilot.tool_display import emit_tool_display_name
+from backend.copilot.tools import TOOL_REGISTRY
+
+
+def make_session():
+ now = datetime.now(timezone.utc)
+ return ChatSession(
+ session_id="session",
+ user_id="user",
+ messages=[],
+ usage=[],
+ started_at=now,
+ updated_at=now,
+ )
+
+
+async def test_display_bridge_preserves_domain_execution_ids():
+ bridge = SDKToolDisplayBridge()
+ tagged = bridge.prepare_call("run_agent", {}, "toolu-provider")
+ base_tool = MagicMock()
+
+ async def execute(*, tool_call_id, **kwargs):
+ emit_tool_display_name("Daily Digest")
+ return StreamToolOutputAvailable(
+ toolCallId=tool_call_id,
+ output=f"tool-outputs/{tool_call_id}.json",
+ )
+
+ base_tool.execute = AsyncMock(side_effect=execute)
+ with bridge.execution_context("run_agent", tagged) as arguments:
+ result = await _execute_tool_sync(base_tool, "user", make_session(), arguments)
+
+ execution_id = base_tool.execute.call_args.kwargs["tool_call_id"]
+ assert re.fullmatch(r"sdk-[0-9a-f]{12}", execution_id)
+ assert result["content"][0]["text"] == f"tool-outputs/{execution_id}.json"
+ [display] = bridge.drain()
+ assert display.data.toolCallId == "toolu-provider"
+ assert display.data.displayName == "Daily Digest"
+
+
+ "tool_name,args,display_name,name_key",
+ [
+ (
+ "run_agent",
+ {"library_agent_id": "agent"},
+ "Actual Library Title",
+ "graph_name",
+ ),
+ (
+ "run_block",
+ {"block_id": "db7d8f02-2f44-4c55-ab7a-eae0941f0c30", "input_data": {}},
+ "FillTextTemplateBlock",
+ "block_name",
+ ),
+ (
+ "continue_run_block",
+ {"review_id": "review"},
+ "FillTextTemplateBlock",
+ "block_name",
+ ),
+ ],
+)
+async def test_hook_to_mcp_handler_keeps_provider_identity_and_clean_stash(
+ tool_name, args, display_name, name_key
+):
+ bridge = SDKToolDisplayBridge()
+ hooks = create_security_hooks("user", tool_display_bridge=bridge)
+ pre_hook = hooks["PreToolUse"][0].hooks[0]
+ decision = await pre_hook(
+ {
+ "hook_event_name": "PreToolUse",
+ "tool_name": f"mcp__copilot__{tool_name}",
+ "tool_input": args,
+ "session_id": "session",
+ "transcript_path": "",
+ "cwd": "",
+ "tool_use_id": "toolu-provider",
+ },
+ "toolu-provider",
+ {"signal": None},
+ )
+ tagged = decision["hookSpecificOutput"]["updatedInput"]
+ session = make_session()
+ set_execution_context("user", session)
+
+ async def execute(clean_args):
+ assert clean_args == args
+ emit_tool_display_name(display_name)
+ return {
+ "content": [{"type": "text", "text": json.dumps({name_key: display_name})}]
+ }
+
+ wrapper = _make_truncating_wrapper(execute, tool_name, tool_display_bridge=bridge)
+ schema = _build_input_schema(TOOL_REGISTRY[tool_name])
+ server = create_sdk_mcp_server(
+ "copilot", tools=[tool(tool_name, "Run tool", schema)(wrapper)]
+ )
+ try:
+ async with create_connected_server_and_client_session(
+ server["instance"]
+ ) as client:
+ result = await client.call_tool(tool_name, tagged)
+ assert not result.isError
+ assert bridge.ready.is_set()
+ [display] = bridge.drain()
+ assert display.id == "toolu-provider"
+ assert display.data.displayName == display_name
+ assert (
+ json.loads(pop_pending_tool_output(tool_name, args))[name_key]
+ == display_name
+ )
+ finally:
+ set_execution_context(None, None)
+
+
+def test_adapter_never_exposes_sdk_correlation_token_in_input():
+ bridge = SDKToolDisplayBridge()
+ args = {"preset_id": "preset"}
+ tagged = bridge.prepare_call("run_agent", args, "toolu-real")
+ adapter = SDKResponseAdapter()
+ responses = adapter.convert_message(
+ AssistantMessage(
+ content=[
+ ToolUseBlock(
+ id="toolu-real", name="mcp__copilot__run_agent", input=tagged
+ )
+ ],
+ model="test",
+ )
+ )
+ [part] = [
+ response
+ for response in responses
+ if isinstance(response, StreamToolInputAvailable)
+ ]
+ assert part.input == args
+ assert adapter.current_tool_calls["toolu-real"]["input"] == args
+
+
+def test_fallback_transcript_never_persists_sdk_correlation_token():
+ bridge = SDKToolDisplayBridge()
+ args = {"preset_id": "preset"}
+ tagged = bridge.prepare_call("run_agent", args, "toolu-real")
+ [block] = _format_sdk_content_blocks(
+ [ToolUseBlock(id="toolu-real", name="mcp__copilot__run_agent", input=tagged)]
+ )
+ assert block["input"] == args
+
+
[email protected]("name_first", [True, False])
+ "tool_name,tool_input,display_name",
+ [
+ ("run_agent", {"preset_id": "p"}, "Daily Digest"),
+ ("run_block", {"block_id": "b", "input_data": {}}, "FillTextTemplateBlock"),
+ ("continue_run_block", {"review_id": "r"}, "FillTextTemplateBlock"),
+ ],
+)
+def test_dispatch_persists_name_without_duplicate_call_and_flags_late_save(
+ name_first, tool_name, tool_input, display_name
+):
+ session = make_session()
+ ctx = MagicMock(session=session)
+ state = MagicMock()
+ acc = _StreamAccumulator(
+ assistant_response=ChatMessage(role="assistant"), accumulated_tool_calls=[]
+ )
+ display = StreamToolDisplayAvailable(
+ id="call", data=ToolDisplayData(toolCallId="call", displayName=display_name)
+ )
+ start = StreamToolInputAvailable(
+ toolCallId="call", toolName=tool_name, input=tool_input
+ )
+ events = [display, start] if name_first else [start, display]
+ for event in events:
+ _dispatch_response(event, acc, ctx, state, False, "[test]")
+ if isinstance(event, StreamToolInputAvailable):
+ acc.assistant_response.sequence = 0
+ _dispatch_response(display, acc, ctx, state, False, "[test]")
+ assert len(session.messages) == 1
+ assert len(session.messages[0].tool_calls) == 1
+ call = session.messages[0].tool_calls[0]
+ assert call["display_name"] == display_name
+ assert call["function"]["name"] == tool_name
+ assert json.loads(call["function"]["arguments"]) == tool_input
+ if not name_first:
+ assert session.messages[0].tool_calls_pending_save
+
+
+async def test_name_wakes_stream_without_cancelling_pending_sdk_read():
+ client = AsyncMock()
+ display_ready = asyncio.Event()
+ release = asyncio.Event()
+ cancelled = False
+
+ async def receive():
+ nonlocal cancelled
+ try:
+ await release.wait()
+ yield "result"
+ except asyncio.CancelledError:
+ cancelled = True
+ raise
+
+ client.receive_response = receive
+ stream = _iter_sdk_messages(client, tool_display_wake=display_ready)
+ asyncio.get_running_loop().call_soon(display_ready.set)
+ try:
+ assert await asyncio.wait_for(anext(stream), 1) is None
+ assert not cancelled
+ release.set()
+ assert await asyncio.wait_for(anext(stream), 1) == "result"
+ finally:
+ await stream.aclose()
diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_display_test.py b/autogpt_platform/backend/backend/copilot/sdk/tool_display_test.py
new file mode 100644
index 0000000000..46739bf185
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_display_test.py
@@ -0,0 +1,82 @@
+import asyncio
+
+import pytest
+
+from backend.copilot.sdk.tool_display import SDKToolDisplayBridge
+from backend.copilot.tool_display import emit_tool_display_name, tool_display_context
+
+
+def test_display_context_uses_provider_id_and_keeps_arguments_clean():
+ bridge = SDKToolDisplayBridge()
+ original = {"library_agent_id": "agent-a"}
+ tagged = bridge.prepare_call("run_agent", original, "toolu-a")
+ with bridge.execution_context("run_agent", tagged) as arguments:
+ assert arguments == original
+ emit_tool_display_name("Daily Digest")
+ [event] = bridge.drain()
+ assert event.id == "toolu-a"
+ assert event.data.toolCallId == "toolu-a"
+ assert event.data.displayName == "Daily Digest"
+ assert original == {"library_agent_id": "agent-a"}
+
+
+async def test_parallel_identical_calls_keep_exact_ids_when_started_in_reverse():
+ bridge = SDKToolDisplayBridge()
+ tagged_a = bridge.prepare_call("run_agent", {"preset_id": "p"}, "toolu-a")
+ tagged_b = bridge.prepare_call("run_agent", {"preset_id": "p"}, "toolu-b")
+
+ async def execute(tagged, name):
+ with bridge.execution_context("run_agent", tagged):
+ await asyncio.sleep(0)
+ emit_tool_display_name(name)
+
+ await asyncio.gather(execute(tagged_b, "Name B"), execute(tagged_a, "Name A"))
+ assert {event.id: event.data.displayName for event in bridge.drain()} == {
+ "toolu-a": "Name A",
+ "toolu-b": "Name B",
+ }
+
+
+def test_reset_invalidates_old_tokens_and_callbacks():
+ bridge = SDKToolDisplayBridge()
+ tagged = bridge.prepare_call("run_agent", {}, "old")
+ with bridge.execution_context("run_agent", tagged):
+ bridge.reset()
+ emit_tool_display_name("Late old task")
+ with bridge.execution_context("run_agent", tagged):
+ emit_tool_display_name("Replayed old token")
+ assert bridge.drain() == []
+ assert not bridge.ready.is_set()
+
+
+def test_untrusted_or_wrong_tool_tokens_cannot_label_another_call():
+ bridge = SDKToolDisplayBridge()
+ tagged = bridge.prepare_call("run_agent", {}, "real")
+ with bridge.execution_context("different_tool", tagged):
+ emit_tool_display_name("Wrong")
+ with bridge.execution_context("run_agent", {"__agpt_display_token": "forged"}):
+ emit_tool_display_name("Forged")
+ assert bridge.drain() == []
+
+
+def test_exception_resets_context_and_token_is_single_use():
+ bridge = SDKToolDisplayBridge()
+ tagged = bridge.prepare_call("run_agent", {}, "real")
+ with pytest.raises(RuntimeError):
+ with bridge.execution_context("run_agent", tagged):
+ raise RuntimeError("test")
+ emit_tool_display_name("Outside failed execution")
+ with bridge.execution_context("run_agent", tagged):
+ emit_tool_display_name("Duplicate")
+ assert bridge.drain() == []
+
+
+def test_sdk_scopes_do_not_inherit_outer_tool_display_callback():
+ names = []
+ bridge = SDKToolDisplayBridge()
+ with tool_display_context(names.append):
+ with bridge.execution_context("run_agent", {}):
+ emit_tool_display_name("Uncorrelated")
+ emit_tool_display_name("Outer")
+ assert names == ["Outer"]
diff --git a/autogpt_platform/backend/backend/copilot/sharing/models_test.py b/autogpt_platform/backend/backend/copilot/sharing/models_test.py
index 21d4842ad7..b8f0f6a158 100644
--- a/autogpt_platform/backend/backend/copilot/sharing/models_test.py
+++ b/autogpt_platform/backend/backend/copilot/sharing/models_test.py
@@ -141,6 +141,29 @@ class TestRedactSecretKeys:
class TestSanitizeChatMessage:
+ def test_preserves_canonical_tool_display_name(self):
+ msg = _msg(
+ tool_calls=[
+ {
+ "id": "call-1",
+ "type": "function",
+ "display_name": "Daily report",
+ "function": {
+ "name": "run_agent",
+ "arguments": {
+ "library_agent_id": "library-id",
+ "api_key": "secret",
+ },
+ },
+ }
+ ],
+ )
+ sanitized = sanitize_chat_message(msg)
+ assert sanitized.tool_calls[0]["display_name"] == "Daily report"
+ assert (
+ sanitized.tool_calls[0]["function"]["arguments"]["api_key"] == "[redacted]"
+ )
+
def test_drops_refusal_and_metadata(self):
msg = _msg(
role="assistant",
diff --git a/autogpt_platform/backend/backend/copilot/stream_registry.py b/autogpt_platform/backend/backend/copilot/stream_registry.py
index c58107ed1c..e08ac76501 100644
--- a/autogpt_platform/backend/backend/copilot/stream_registry.py
+++ b/autogpt_platform/backend/backend/copilot/stream_registry.py
@@ -60,6 +60,7 @@ from .response_model import (
StreamTextDelta,
StreamTextEnd,
StreamTextStart,
+ StreamToolDisplayAvailable,
StreamToolInputAvailable,
StreamToolInputStart,
StreamToolOutputAvailable,
@@ -1193,6 +1194,7 @@ CHUNK_TYPE_TO_CLASS: dict[str, type[StreamBaseResponse]] = {
ResponseType.TOOL_INPUT_START.value: StreamToolInputStart,
ResponseType.TOOL_INPUT_AVAILABLE.value: StreamToolInputAvailable,
ResponseType.TOOL_OUTPUT_AVAILABLE.value: StreamToolOutputAvailable,
+ ResponseType.TOOL_DISPLAY_AVAILABLE.value: StreamToolDisplayAvailable,
ResponseType.ERROR.value: StreamError,
ResponseType.USAGE.value: StreamUsage,
ResponseType.HEARTBEAT.value: StreamHeartbeat,
diff --git a/autogpt_platform/backend/backend/copilot/stream_registry_test.py b/autogpt_platform/backend/backend/copilot/stream_registry_test.py
index c33663dff2..a70b293dbd 100644
--- a/autogpt_platform/backend/backend/copilot/stream_registry_test.py
+++ b/autogpt_platform/backend/backend/copilot/stream_registry_test.py
@@ -1,6 +1,7 @@
"""Tests for disconnect_all_listeners in stream_registry."""
import asyncio
+import json
from unittest.mock import AsyncMock, patch
import pytest
@@ -11,6 +12,18 @@ from backend.copilot.constants import STREAM_LOCK_PREFIX
from backend.copilot.executor.utils import get_session_lock_key
+def test_tool_display_roundtrips_redis_and_sse():
+ payload = {
+ "type": "data-tool-display",
+ "id": "call-1",
+ "data": {"toolCallId": "call-1", "displayName": "Daily report"},
+ }
+ chunk = stream_registry._reconstruct_chunk(payload)
+ assert chunk is not None
+ assert json.loads(chunk.model_dump_json()) == payload
+ assert json.loads(chunk.to_sse().removeprefix("data: ")) == payload
+
+
@pytest.fixture(autouse=True)
def _clear_listener_sessions():
stream_registry._listener_sessions.clear()
diff --git a/autogpt_platform/backend/backend/copilot/tool_display.py b/autogpt_platform/backend/backend/copilot/tool_display.py
new file mode 100644
index 0000000000..42e962ca55
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/tool_display.py
@@ -0,0 +1,35 @@
+"""Presentation metadata published by the current tool execution."""
+
+from collections.abc import Callable, Iterator
+from contextlib import contextmanager
+from contextvars import ContextVar
+
+_display_callback: ContextVar[Callable[[str], None] | None] = ContextVar(
+ "tool_display_callback", default=None
+)
+
+
+@contextmanager
+def tool_display_context(on_display_name: Callable[[str], None]) -> Iterator[None]:
+ """Scope display updates to one tool task, including parallel executions."""
+ token = _display_callback.set(on_display_name)
+ try:
+ yield
+ finally:
+ _display_callback.reset(token)
+
+
+def emit_tool_display_name(display_name: str) -> None:
+ """Publish a resolved name without coupling tools to the stream transport."""
+ callback = _display_callback.get()
+ name = display_name.strip()
+ if callback is not None and name:
+ callback(name)
+
+
+def tool_calls_for_provider(tool_calls: list[dict]) -> list[dict]:
+ """Keep UI metadata out of the provider's tool-call protocol."""
+ return [
+ {key: value for key, value in call.items() if key != "display_name"}
+ for call in tool_calls
+ ]
diff --git a/autogpt_platform/backend/backend/copilot/tool_display_test.py b/autogpt_platform/backend/backend/copilot/tool_display_test.py
new file mode 100644
index 0000000000..6a14c2f337
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/tool_display_test.py
@@ -0,0 +1,54 @@
+"""Tool display metadata stays scoped to one concurrent execution."""
+
+import asyncio
+
+import pytest
+
+from backend.copilot.tool_display import (
+ emit_tool_display_name,
+ tool_calls_for_provider,
+ tool_display_context,
+)
+
+
+async def test_display_names_are_isolated_between_concurrent_calls():
+ received: dict[str, list[str]] = {"first": [], "second": []}
+ both_started = asyncio.Barrier(2)
+
+ async def execute(call_id: str, name: str):
+ with tool_display_context(received[call_id].append):
+ await both_started.wait()
+ emit_tool_display_name(name)
+
+ await asyncio.gather(execute("first", "Daily report"), execute("second", "Inbox"))
+ emit_tool_display_name("Outside any tool")
+ assert received == {"first": ["Daily report"], "second": ["Inbox"]}
+
+
+def test_display_context_restores_parent_after_failure_and_ignores_blank_names():
+ outer: list[str] = []
+ inner: list[str] = []
+ with tool_display_context(outer.append):
+ with pytest.raises(RuntimeError), tool_display_context(inner.append):
+ emit_tool_display_name(" Inner ")
+ raise RuntimeError("execution failed")
+ emit_tool_display_name(" ")
+ emit_tool_display_name("Outer")
+ emit_tool_display_name("Outside any tool")
+ assert outer == ["Outer"]
+ assert inner == ["Inner"]
+
+
+def test_provider_tool_calls_omit_display_metadata_without_mutating_saved_calls():
+ saved = [
+ {
+ "id": "call-1",
+ "display_name": "Daily report",
+ "function": {"name": "run_agent", "arguments": '{"display_name":"input"}'},
+ }
+ ]
+ provider = tool_calls_for_provider(saved)
+ assert "display_name" not in provider[0]
+ assert provider[0]["function"]["arguments"] == '{"display_name":"input"}'
+ assert saved[0]["display_name"] == "Daily report"
diff --git a/autogpt_platform/backend/backend/copilot/tools/block_display_test.py b/autogpt_platform/backend/backend/copilot/tools/block_display_test.py
new file mode 100644
index 0000000000..143e4b8842
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/tools/block_display_test.py
@@ -0,0 +1,236 @@
+"""Resolved block names are available before execution and setup responses."""
+
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import pytest
+from prisma.enums import ReviewStatus
+
+from backend.blocks._base import BlockType
+from backend.copilot.constants import COPILOT_SESSION_PREFIX
+from backend.copilot.model import ChatSession
+from backend.copilot.tool_display import tool_display_context
+from backend.copilot.tools.continue_run_block import ContinueRunBlockTool
+from backend.copilot.tools.models import BlockOutputResponse
+from backend.copilot.tools.run_block import RunBlockTool
+
+_BLOCK_ID = "b71fd24c-7623-4a73-a196-0538e436f4b8"
+_BLOCK_NAME = "HTTPDownloadBlock"
+_USER_ID = "block-display-user"
+
+
+ "scenario,expected_type",
+ [
+ ("execute", "block_output"),
+ ("credentials", "setup_requirements"),
+ ("unknown_input", "input_validation_error"),
+ ("invalid_schema", "error"),
+ ("validate_only", "block_details"),
+ ],
+)
+async def test_run_block_emits_name_before_execution_or_setup(
+ scenario: str, expected_type: str
+):
+ session = ChatSession.new(_USER_ID, dry_run=False)
+ block = _block()
+ published: list[str] = []
+ if scenario == "invalid_schema":
+ block.input_schema.jsonschema.side_effect = ValueError("Invalid schema")
+
+ async def resolve_credentials(*args):
+ assert published == [_BLOCK_NAME]
+ return {}, [MagicMock()] if scenario == "credentials" else []
+
+ execute = AsyncMock(return_value=_output(session))
+ with (
+ tool_display_context(published.append),
+ patch("backend.copilot.tools.helpers.get_block", return_value=block),
+ patch(
+ "backend.copilot.tools.helpers.resolve_block_credentials",
+ new=AsyncMock(side_effect=resolve_credentials),
+ ),
+ patch(
+ "backend.copilot.tools.helpers.expand_file_refs_in_args",
+ new=AsyncMock(side_effect=lambda data, *args, **kwargs: data),
+ ),
+ patch(
+ "backend.copilot.tools.run_block.check_hitl_review",
+ new=AsyncMock(return_value=("execution-id", {})),
+ ),
+ patch("backend.copilot.tools.run_block.execute_block", new=execute),
+ ):
+ result = await RunBlockTool()._execute(
+ user_id=_USER_ID,
+ session=session,
+ block_id=_BLOCK_ID,
+ input_data={"unknown": "value"} if scenario == "unknown_input" else {},
+ validate_only=scenario == "validate_only",
+ )
+
+ assert published == [_BLOCK_NAME]
+ assert result.type == expected_type
+ if scenario == "execute":
+ execute.assert_awaited_once()
+ else:
+ execute.assert_not_awaited()
+
+
[email protected]("unavailable", ["missing", "disabled", "excluded"])
+async def test_unavailable_block_does_not_emit_a_name(unavailable: str):
+ session = ChatSession.new(_USER_ID, dry_run=False)
+ block = _block()
+ block.disabled = unavailable == "disabled"
+ if unavailable == "excluded":
+ block.block_type = BlockType.INPUT
+ published: list[str] = []
+ with (
+ tool_display_context(published.append),
+ patch(
+ "backend.copilot.tools.helpers.get_block",
+ return_value=None if unavailable == "missing" else block,
+ ),
+ patch(
+ "backend.copilot.tools.helpers.resolve_block_credentials",
+ new_callable=AsyncMock,
+ ) as resolve,
+ ):
+ result = await RunBlockTool()._execute(
+ user_id=_USER_ID, session=session, block_id=_BLOCK_ID
+ )
+
+ assert result.type == "error"
+ assert published == []
+ resolve.assert_not_awaited()
+
+
[email protected]("missing_credentials", [False, True])
+async def test_approved_continuation_emits_name_before_credentials(
+ missing_credentials: bool,
+):
+ session = ChatSession.new(_USER_ID, dry_run=False)
+ review_id = f"copilot-node-{_BLOCK_ID}:12345678"
+ database = _review_database(session, review_id)
+ published: list[str] = []
+
+ async def resolve_credentials(*args):
+ assert published == [_BLOCK_NAME]
+ return {}, [MagicMock()] if missing_credentials else []
+
+ execute = AsyncMock(return_value=_output(session))
+ with (
+ tool_display_context(published.append),
+ patch(
+ "backend.copilot.tools.continue_run_block.review_db", return_value=database
+ ),
+ patch(
+ "backend.copilot.tools.continue_run_block.get_block", return_value=_block()
+ ),
+ patch(
+ "backend.copilot.tools.continue_run_block.resolve_block_credentials",
+ new=AsyncMock(side_effect=resolve_credentials),
+ ),
+ patch("backend.copilot.tools.continue_run_block.execute_block", new=execute),
+ ):
+ result = await ContinueRunBlockTool()._execute(
+ user_id=_USER_ID, session=session, review_id=review_id
+ )
+
+ assert published == [_BLOCK_NAME]
+ assert result.type == ("error" if missing_credentials else "block_output")
+ database.get_reviews_by_node_exec_ids.assert_awaited_once_with(
+ [review_id], _USER_ID
+ )
+ if missing_credentials:
+ execute.assert_not_awaited()
+ database.delete_review_by_node_exec_id.assert_not_awaited()
+ else:
+ execute.assert_awaited_once()
+ database.delete_review_by_node_exec_id.assert_awaited_once_with(
+ review_id, _USER_ID
+ )
+
+
+ "unavailable",
+ ["review_missing", "wrong_session", "waiting", "rejected", "block_missing"],
+)
+async def test_unavailable_continuation_does_not_emit_a_name(unavailable: str):
+ session = ChatSession.new(_USER_ID, dry_run=False)
+ review_id = f"copilot-node-{_BLOCK_ID}:12345678"
+ database = _review_database(session, review_id)
+ review = database.get_reviews_by_node_exec_ids.return_value[review_id]
+ if unavailable == "review_missing":
+ database.get_reviews_by_node_exec_ids.return_value = {}
+ elif unavailable == "wrong_session":
+ review.graph_exec_id = "another-session"
+ elif unavailable in ("waiting", "rejected"):
+ review.status = (
+ ReviewStatus.WAITING if unavailable == "waiting" else ReviewStatus.REJECTED
+ )
+ published: list[str] = []
+ with (
+ tool_display_context(published.append),
+ patch(
+ "backend.copilot.tools.continue_run_block.review_db", return_value=database
+ ),
+ patch(
+ "backend.copilot.tools.continue_run_block.get_block", return_value=None
+ ) as lookup,
+ patch(
+ "backend.copilot.tools.continue_run_block.resolve_block_credentials",
+ new_callable=AsyncMock,
+ ) as resolve,
+ ):
+ result = await ContinueRunBlockTool()._execute(
+ user_id=_USER_ID, session=session, review_id=review_id
+ )
+
+ assert result.type == "error"
+ assert published == []
+ resolve.assert_not_awaited()
+ if unavailable != "block_missing":
+ lookup.assert_not_called()
+
+
+def _block() -> MagicMock:
+ block = MagicMock()
+ block.id = _BLOCK_ID
+ block.name = _BLOCK_NAME
+ block.description = "Downloads HTTP content"
+ block.disabled = False
+ block.block_type = BlockType.STANDARD
+ block.input_schema.get_credentials_fields.return_value = {}
+ block.input_schema.get_credentials_fields_info.return_value = {}
+ block.input_schema.jsonschema.return_value = {"properties": {}, "required": []}
+ block.output_schema.jsonschema.return_value = {"properties": {}}
+ return block
+
+
+def _output(session: ChatSession) -> BlockOutputResponse:
+ return BlockOutputResponse(
+ message="Completed",
+ session_id=session.session_id,
+ block_id=_BLOCK_ID,
+ block_name=_BLOCK_NAME,
+ outputs={"result": ["downloaded"]},
+ success=True,
+ )
+
+
+def _review_database(session: ChatSession, review_id: str) -> MagicMock:
+ database = MagicMock()
+ database.get_reviews_by_node_exec_ids = AsyncMock(
+ return_value={
+ review_id: MagicMock(
+ graph_exec_id=f"{COPILOT_SESSION_PREFIX}{session.session_id}",
+ status=ReviewStatus.APPROVED,
+ payload={},
+ )
+ }
+ )
+ database.delete_review_by_node_exec_id = AsyncMock()
+ return database
diff --git a/autogpt_platform/backend/backend/copilot/tools/continue_run_block.py b/autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
index b1f8db4768..962baa9e69 100644
--- a/autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
+++ b/autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
@@ -12,6 +12,7 @@ from backend.copilot.constants import (
parse_node_id_from_exec_id,
)
from backend.copilot.model import ChatSession
+from backend.copilot.tool_display import emit_tool_display_name
from backend.data.db_accessors import review_db
from .base import BaseTool
@@ -113,6 +114,8 @@ class ContinueRunBlockTool(BaseTool):
message=f"Block '{block_id}' not found", session_id=session_id
)
+ emit_tool_display_name(block.name)
+
input_data: dict[str, Any] = (
review.payload if isinstance(review.payload, dict) else {}
)
diff --git a/autogpt_platform/backend/backend/copilot/tools/helpers.py b/autogpt_platform/backend/backend/copilot/tools/helpers.py
index bf1d022283..64ca2b9419 100644
--- a/autogpt_platform/backend/backend/copilot/tools/helpers.py
+++ b/autogpt_platform/backend/backend/copilot/tools/helpers.py
@@ -22,6 +22,7 @@ from backend.copilot.constants import (
from backend.copilot.model import ChatSession
from backend.copilot.sdk.env import config as chat_config
from backend.copilot.sdk.file_ref import FileRefExpansionError, expand_file_refs_in_args
+from backend.copilot.tool_display import emit_tool_display_name
from backend.data.credit import UsageTransactionMetadata
from backend.data.db_accessors import credit_db, review_db, user_db, workspace_db
from backend.data.execution import ExecutionContext
@@ -702,6 +703,8 @@ async def prepare_block_for_execution(
session_id=session_id,
)
+ emit_tool_display_name(block.name)
+
# LLMs sometimes pass `"credentials": null` instead of omitting the field.
# Treat null credential fields as absent so the injection path below can
# populate them, and so _base.validate_data doesn't reject null against a
diff --git a/autogpt_platform/backend/backend/copilot/tools/run_agent.py b/autogpt_platform/backend/backend/copilot/tools/run_agent.py
index 56dd410be3..d33b869a9c 100644
--- a/autogpt_platform/backend/backend/copilot/tools/run_agent.py
+++ b/autogpt_platform/backend/backend/copilot/tools/run_agent.py
@@ -9,6 +9,7 @@ from backend.api.features.library.model import LibraryAgentPresetCreatable
from backend.copilot.config import ChatConfig
from backend.copilot.constants import MAX_TOOL_WAIT_SECONDS
from backend.copilot.model import ChatSession
+from backend.copilot.tool_display import emit_tool_display_name
from backend.copilot.tracking import track_agent_run_success, track_agent_scheduled
from backend.data.db_accessors import execution_db, graph_db, library_db, user_db
from backend.data.execution import ExecutionStatus, GraphExecutionWithNodes
@@ -881,6 +882,7 @@ class RunAgentTool(BaseTool):
# Get or create library agent
library_agent = await get_or_create_library_agent(graph, user_id)
+ emit_tool_display_name(library_agent.name)
# Execute — ``add_graph_execution`` ultimately calls
# ``validate_and_construct_node_execution_input`` which raises
@@ -1158,6 +1160,7 @@ class RunAgentTool(BaseTool):
# Get or create library agent
library_agent = await get_or_create_library_agent(graph, user_id)
+ emit_tool_display_name(library_agent.name)
# Get user timezone
user = await user_db().get_user_by_id(user_id)
diff --git a/autogpt_platform/backend/backend/copilot/tools/run_agent_display_test.py b/autogpt_platform/backend/backend/copilot/tools/run_agent_display_test.py
new file mode 100644
index 0000000000..536d2beb6a
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/tools/run_agent_display_test.py
@@ -0,0 +1,48 @@
+"""Resolved library names arrive before starting or waiting for a workflow."""
+
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import pytest
+
+from backend.copilot.model import ChatSession
+from backend.copilot.tool_display import tool_display_context
+from backend.copilot.tools.run_agent import RunAgentTool
+
+
[email protected]("wait_for_result", [0, 30])
+async def test_canonical_library_name_is_published_before_execution(wait_for_result):
+ session = ChatSession.new("user-1", dry_run=False)
+ session.organization_id = "org-1"
+ library_agent = MagicMock(id="library-id", graph_id="graph-id")
+ library_agent.name = "My renamed workflow"
+ graph = MagicMock(id="graph-id")
+ graph.name = "Original graph name"
+ published: list[str] = []
+
+ async def start_execution(**kwargs):
+ assert published == ["My renamed workflow"]
+ raise RuntimeError("stop before actual execution")
+
+ with (
+ patch(
+ "backend.copilot.tools.run_agent.get_or_create_library_agent",
+ new=AsyncMock(return_value=library_agent),
+ ),
+ tool_display_context(published.append),
+ patch(
+ "backend.copilot.tools.run_agent.execution_utils.add_graph_execution",
+ new=AsyncMock(side_effect=start_execution),
+ ),
+ pytest.raises(RuntimeError, match="stop before actual execution"),
+ ):
+ await RunAgentTool()._run_agent(
+ user_id="user-1",
+ session=session,
+ graph=graph,
+ graph_credentials={},
+ inputs={},
+ dry_run=False,
+ wait_for_result=wait_for_result,
+ )
+ assert published == ["My renamed workflow"]
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
index e4369dc1b0..e51b87885b 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
@@ -39,6 +39,7 @@ import { WorkCard } from "../WorkCard/WorkCard";
import { getWorkRunMetadata, toPreview } from "../WorkCard/helpers";
import { AssistantMessageActions } from "./components/AssistantMessageActions";
import { ChainMessageParts } from "./components/ChainMessageParts";
+import { withToolDisplayNames } from "../../helpers/toolDisplay";
import { CopyButton } from "./components/CopyButton";
import { TailSpacer } from "./components/TailSpacer";
import { MessageAttachments } from "./components/MessageAttachments";
@@ -551,7 +552,7 @@ export function ChatMessagesContainer({
// they never reach the user UI, and so one landing between two
// tool calls can't split a chain. data-status surfaces via
// ThinkingIndicator; data-compaction via CompactionCard.
- const renderableParts = message.parts.filter(
+ const renderableParts = withToolDisplayNames(message.parts).filter(
(p) => !isBookkeepingPart(p),
);
// Only a message that is actively streaming can have a live
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/__tests__/ChatMessagesContainer.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/__tests__/ChatMessagesContainer.test.tsx
index 834a9dec27..5a1732d509 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/__tests__/ChatMessagesContainer.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/__tests__/ChatMessagesContainer.test.tsx
@@ -67,7 +67,9 @@ vi.mock("../components/AssistantMessageActions", () => ({
AssistantMessageActions: () => null,
}));
vi.mock("../components/ChainMessageParts", () => ({
- ChainMessageParts: () => <div data-testid="chain-message-parts" />,
+ ChainMessageParts: ({ parts }: { parts: unknown[] }) => (
+ <div data-testid="chain-message-parts" data-parts={JSON.stringify(parts)} />
+ ),
}));
vi.mock("../components/QueueBadge", () => ({
@@ -694,6 +696,52 @@ describe("ChatMessagesContainer — readOnly mode", () => {
vi.unstubAllGlobals();
});
+ it.each([false, true])(
+ "applies streamed tool names before stripping bookkeeping parts (readOnly=%s)",
+ (readOnly) => {
+ render(
+ <ChatMessagesContainer
+ {...baseProps}
+ readOnly={readOnly}
+ messages={[
+ {
+ id: "assistant-display",
+ role: "assistant",
+ parts: [
+ {
+ type: "tool-run_agent",
+ toolCallId: "call-one",
+ state: "input-available",
+ input: { library_agent_id: "library-id" },
+ },
+ {
+ type: "data-tool-display",
+ id: "call-one",
+ data: {
+ toolCallId: "call-one",
+ displayName: "Daily briefing",
+ },
+ },
+ ],
+ },
+ ]}
+ />,
+ );
+ const renderedParts = JSON.parse(
+ screen.getByTestId("chain-message-parts").dataset.parts ?? "[]",
+ );
+ expect(renderedParts).toEqual([
+ {
+ type: "tool-run_agent",
+ toolCallId: "call-one",
+ state: "input-available",
+ input: { library_agent_id: "library-id" },
+ title: "Daily briefing",
+ },
+ ]);
+ },
+ );
+
it("hides the load-older-messages sentinel even when more history exists", () => {
render(
<ChatMessagesContainer
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/BlockCards.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/BlockCards.tsx
index 5a0df2ab39..2a4cf68e75 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/BlockCards.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/BlockCards.tsx
@@ -8,6 +8,7 @@ import {
import Image from "next/image";
import { useState } from "react";
import { Icon } from "@/components/atoms/Icon/Icon";
+import { getBlockDisplayName } from "../../helpers/toolDisplay";
import { CARD, HALF, RESULT_GRID } from "./ResultCards";
import {
inline,
@@ -77,7 +78,7 @@ export function BlockListCard({ blocks }: BlockListCardProps) {
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-[13px] font-medium text-zinc-800">
- {str(block, "name", "block_name") ?? inline(block)}
+ {getBlockDisplayName(block.name, block) ?? "Block"}
</p>
{str(block, "description") && (
<p className="truncate text-xs text-zinc-500">
@@ -98,7 +99,7 @@ export function BlockListCard({ blocks }: BlockListCardProps) {
}
export function BlockOutputCard({ output }: BlockOutputCardProps) {
- const name = str(output, "block_name", "block_id") ?? "Block";
+ const name = getBlockDisplayName(undefined, output) ?? "Block";
const ok = output.success !== false;
const entries = Object.entries(
output.outputs && typeof output.outputs === "object"
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/SubSessionLive.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/SubSessionLive.tsx
index d4adce5391..31bb4594ad 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/SubSessionLive.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/SubSessionLive.tsx
@@ -17,6 +17,7 @@ import {
getToolCategory,
} from "../../tools/GenericTool/helpers";
import { useExpertMap } from "../../useExpertMap";
+import { extractToolOutputsFromRaw } from "../../helpers/convertChatSessionToUiMessages";
import type { ChainRow } from "./helpers";
import { CARD, StatusPill } from "./ResultCards";
import { asObject, str } from "./resultHelpers";
@@ -39,6 +40,8 @@ const POLL_CAP_MS = 5 * 60_000;
interface LiveStep {
name: string;
input: unknown;
+ displayName?: unknown;
+ output?: unknown;
}
/** The delegate's work, live inside the parent chain: its recent tool calls
@@ -180,17 +183,26 @@ function collectCurrentTurn(session: SessionDetailResponse) {
const messages =
lastUserIndex === -1 ? allMessages : allMessages.slice(lastUserIndex + 1);
const steps: LiveStep[] = [];
+ const outputs = extractToolOutputsFromRaw(messages);
let latestText: string | null = null;
for (const msg of messages) {
const toolCalls = Array.isArray(msg.tool_calls) ? msg.tool_calls : [];
for (const rawCall of toolCalls) {
if (!rawCall || typeof rawCall !== "object") continue;
const call = rawCall as {
+ id?: unknown;
+ display_name?: unknown;
function?: { name?: unknown; arguments?: unknown };
};
const name = String(call.function?.name ?? "").trim();
if (name)
- steps.push({ name, input: parseArguments(call.function?.arguments) });
+ steps.push({
+ name,
+ input: parseArguments(call.function?.arguments),
+ displayName: call.display_name,
+ output:
+ typeof call.id === "string" ? outputs.get(call.id) : undefined,
+ });
}
if (
msg.role === "assistant" &&
@@ -207,7 +219,10 @@ function collectCurrentTurn(session: SessionDetailResponse) {
* main chain's icons and labels instead of raw tool names. */
function toMiniRow(step: LiveStep, index: number, running: boolean): ChainRow {
const state = running ? "running" : "done";
- const catalog = getCatalogLabel(step.name, step.input, state);
+ const catalog = getCatalogLabel(step.name, step.input, state, {
+ displayName: step.displayName,
+ output: step.output,
+ });
const category = catalog?.category ?? getToolCategory(step.name);
const text =
catalog?.text ??
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/BlockCards.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/BlockCards.test.tsx
index 45c242153e..608dde4c16 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/BlockCards.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/BlockCards.test.tsx
@@ -64,10 +64,11 @@ describe("BlockListCard", () => {
expect(screen.getByAltText("github")).toBeDefined();
});
- it("falls back to inline JSON for unnamed blocks", () => {
- render(<BlockListCard blocks={[{ enabled: true }]} />);
+ it("keeps unnamed blocks generic", () => {
+ render(<BlockListCard blocks={[{ id: "block-9", enabled: true }]} />);
- expect(screen.getByText('{"enabled":true}')).toBeDefined();
+ expect(screen.getByText("Block")).toBeDefined();
+ expect(screen.queryByText(/block-9/)).toBeNull();
});
});
@@ -91,11 +92,12 @@ describe("BlockOutputCard", () => {
expect(screen.getByText('["a","b"]')).toBeDefined();
});
- it("falls back to the block id without outputs", () => {
+ it("keeps unnamed block outputs generic", () => {
render(
<BlockOutputCard output={{ block_id: "block-9", success: false }} />,
);
- expect(screen.getByText("block-9")).toBeDefined();
+ expect(screen.getByText("Block")).toBeDefined();
+ expect(screen.queryByText("block-9")).toBeNull();
});
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/SubSessionLive.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/SubSessionLive.test.tsx
index 4dd5470bf1..9ca8ed20d3 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/SubSessionLive.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/SubSessionLive.test.tsx
@@ -69,6 +69,96 @@ function subSession(
describe("SubSessionLive", () => {
afterEach(cleanup);
+ it.each([
+ ["run_agent", "Daily briefing", "Running agent", "Daily briefing"],
+ [
+ "run_block",
+ "FillTextTemplateBlock",
+ "Running block",
+ "Fill Text Template",
+ ],
+ [
+ "continue_run_block",
+ "FillTextTemplateBlock",
+ "Continuing block run",
+ "Fill Text Template",
+ ],
+ ])(
+ "shows persisted names in a delegate's live %s steps",
+ async (tool, displayName, label, name) => {
+ server.use(
+ subSession(
+ [
+ {
+ role: "assistant",
+ content: "",
+ tool_calls: [
+ {
+ id: "run-1",
+ display_name: displayName,
+ function: {
+ name: tool,
+ arguments: JSON.stringify(
+ tool === "run_agent"
+ ? { library_agent_id: "library-id" }
+ : tool === "run_block"
+ ? { block_id: "block-id", input_data: {} }
+ : { review_id: "review-id" },
+ ),
+ },
+ },
+ ],
+ },
+ ],
+ { chat_status: "running", active_stream: null },
+ ),
+ );
+ render(
+ <SubSessionCard
+ output={{ status: "running", sub_session_id: "sub-1" }}
+ />,
+ );
+ expect(await screen.findByText(`${label} "${name}"…`)).toBeDefined();
+ },
+ );
+
+ it("matches historical delegate output names by tool call ID", async () => {
+ server.use(
+ subSession(
+ [
+ {
+ role: "assistant",
+ content: "",
+ tool_calls: [
+ { id: "run-1", function: { name: "run_agent", arguments: "{}" } },
+ { id: "run-2", function: { name: "run_agent", arguments: "{}" } },
+ ],
+ },
+ {
+ role: "tool",
+ tool_call_id: "run-2",
+ content: '{"agent_name":"Second workflow"}',
+ tool_calls: null,
+ },
+ {
+ role: "tool",
+ tool_call_id: "run-1",
+ content: '{"graph_name":"First workflow"}',
+ tool_calls: null,
+ },
+ ],
+ { chat_status: "idle", active_stream: null },
+ ),
+ );
+ render(
+ <SubSessionCard
+ output={{ status: "running", sub_session_id: "sub-1" }}
+ />,
+ );
+ expect(await screen.findByText('Ran agent "First workflow"')).toBeDefined();
+ expect(screen.getByText('Ran agent "Second workflow"')).toBeDefined();
+ });
+
it("streams the delegate's recent tools and latest words while running", async () => {
server.use(
subSession([
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx
index bc7ff09b0c..cae092a080 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx
@@ -201,6 +201,26 @@ describe("ToolChain", () => {
expect(screen.getByText("Weighing the trade-offs")).toBeDefined();
});
+ it("renders the canonical agent name in both the live heading and its row", () => {
+ const { container } = render(
+ <ToolChain
+ parts={[
+ toolPart("run_agent", "input-available", {
+ title: "Daily briefing",
+ input: { library_agent_id: "b71fd24c-7623-4a73-a000-000000000000" },
+ }),
+ ]}
+ isStreaming
+ />,
+ );
+
+ expect(getChainHeader(/running agent "Daily briefing"/i)).toBeDefined();
+ expect(screen.getAllByText('Running agent "Daily briefing"…')).toHaveLength(
+ 2,
+ );
+ expect(container.textContent).not.toContain("b71fd24c");
+ });
+
it("renders the provider icon when the tool output names a provider", async () => {
const user = userEvent.setup();
const { container } = render(
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsx
index 66981ce94b..ec9054b768 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsx
@@ -401,6 +401,33 @@ describe("ToolResult", () => {
});
describe("block routing", () => {
+ it.each([
+ { block_name: "FillTextTemplateBlock", outputs: { output: ["Hello"] } },
+ { block: { name: "FillTextTemplateBlock" } },
+ ])("normalizes expanded block names from %j", (output) => {
+ render(<ToolResult row={row(output, "run_block")} />);
+ expect(screen.getByText("Fill Text Template")).toBeDefined();
+ expect(screen.queryByText("FillTextTemplateBlock")).toBeNull();
+ });
+
+ it("keeps unknown block output cards generic instead of showing a UUID", () => {
+ render(
+ <ToolResult
+ row={row(
+ {
+ block_id: "db7d8f02-2f44-4c55-ab7a-eae0941f0c30",
+ outputs: { output: ["Hello"] },
+ },
+ "run_block",
+ )}
+ />,
+ );
+ expect(screen.getByText("Block")).toBeDefined();
+ expect(
+ screen.queryByText("db7d8f02-2f44-4c55-ab7a-eae0941f0c30"),
+ ).toBeNull();
+ });
+
it("renders a single block card for run_block block payloads", () => {
render(
<ToolResult
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/toolCatalog.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/toolCatalog.test.ts
index bf0304fbc3..a34a187f8c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/toolCatalog.test.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/toolCatalog.test.ts
@@ -75,17 +75,12 @@ describe("getCatalogLabel", () => {
"done",
'Posted to "#general"',
],
- [
- "run_block",
- { block_name: "Web Search" },
- "done",
- 'Ran block "Web Search"',
- ],
+ ["run_block", { block_name: "Web Search" }, "done", "Ran block"],
[
"run_block",
{ block_id: "abcdefabcdefabcdefabcdef" },
"done",
- 'Ran block "abcdefabcdefabcdefab…"',
+ "Ran block",
],
[
"run_mcp_tool",
@@ -169,17 +164,12 @@ describe("getCatalogLabel", () => {
],
["create_folder", { name: "Reports" }, "done", 'Created folder "Reports"'],
["update_folder", { name: "Reports" }, "done", 'Updated folder "Reports"'],
- [
- "run_agent",
- { username_agent_slug: "abhi/scraper" },
- "done",
- 'Ran agent "abhi/scraper"',
- ],
+ ["run_agent", { username_agent_slug: "abhi/scraper" }, "done", "Ran agent"],
[
"run_agent",
{ library_agent_id: "0123456789012345678901234" },
"done",
- 'Ran agent "01234567890123456789…"',
+ "Ran agent",
],
["add_understanding", {}, "done", "Noted context"],
["enter_agent_building_mode", {}, "running", "Entering building mode…"],
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.ts
index 0e4c8eb03d..060b580512 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.ts
@@ -1,4 +1,5 @@
import type { ToolUIPart } from "ai";
+import { getBlockDisplayName } from "../../helpers/toolDisplay";
import type { MessagePart } from "../ChatMessagesContainer/helpers";
import {
extractToolName,
@@ -85,24 +86,30 @@ const ACTION_RESPONSE_TYPES = new Set([
"suggested_goal",
]);
-function actionLabel(output: unknown): string | null {
+function actionLabel(toolName: string, tool: ToolUIPart): string | null {
+ const output = tool.output;
const data = asObject(output);
if (!data) return null;
if (typeof data.type !== "string" || !ACTION_RESPONSE_TYPES.has(data.type)) {
return null;
}
+ const isBlock = toolName === "run_block" || toolName === "continue_run_block";
if (data.type === "setup_requirements") {
const setup =
data.setup_info && typeof data.setup_info === "object"
? (data.setup_info as Record<string, unknown>)
: null;
- const name = setup?.agent_name;
+ const name = isBlock
+ ? getBlockDisplayName(tool.title, output)
+ : setup?.agent_name;
return typeof name === "string" && name.trim()
? `Connect ${name.trim()} to continue`
: "Complete setup to continue";
}
if (data.type === "review_required") {
- const name = data.block_name;
+ const name = isBlock
+ ? getBlockDisplayName(tool.title, output)
+ : data.block_name;
return typeof name === "string" && name.trim()
? `Review ${name.trim()}`
: "Review this action";
@@ -225,7 +232,7 @@ export function toChainRow(part: MessagePart, index: number): ChainRow | null {
: tool;
const providerIconSrc = getProviderIconSrc(stableTool);
- const requiredActionLabel = actionLabel(tool.output);
+ const requiredActionLabel = actionLabel(toolName, tool);
const data = {
tool: toolName,
@@ -233,7 +240,10 @@ export function toChainRow(part: MessagePart, index: number): ChainRow | null {
output: tool.output,
};
- const catalogLabel = getCatalogLabel(toolName, stableTool.input, state);
+ const catalogLabel = getCatalogLabel(toolName, stableTool.input, state, {
+ displayName: tool.title,
+ output: tool.output,
+ });
if (catalogLabel) {
return {
key: tool.toolCallId,
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.agent.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.agent.ts
index f9d10fa749..c9fa8d2912 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.agent.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.agent.ts
@@ -1,4 +1,5 @@
-import { quoted, type ToolMeta } from "./toolCatalog.shared";
+import { quoted, quotedName, type ToolMeta } from "./toolCatalog.shared";
+import { getAgentDisplayName } from "../../helpers/toolDisplay";
export const AGENT_TOOL_CATALOG: Record<string, ToolMeta> = {
add_understanding: {
@@ -123,9 +124,8 @@ export const AGENT_TOOL_CATALOG: Record<string, ToolMeta> = {
category: "agent",
running: "Running agent",
done: "Ran agent",
- subject: (input) =>
- quoted(input, "username_agent_slug") ??
- quoted(input, "library_agent_id", 20),
+ subject: (_input, context) =>
+ quotedName(getAgentDisplayName(context.displayName, context.output)),
},
view_agent_output: {
category: "agent",
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.platform.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.platform.ts
index 39791ada14..0fd4516468 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.platform.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.platform.ts
@@ -1,5 +1,7 @@
+import { getBlockDisplayName } from "../../helpers/toolDisplay";
import {
quoted,
+ quotedName,
strField,
type ToolInput,
type ToolMeta,
@@ -126,8 +128,8 @@ export const PLATFORM_TOOL_CATALOG: Record<string, ToolMeta> = {
category: "block",
running: "Running block",
done: "Ran block",
- subject: (input) =>
- quoted(input, "block_name") ?? quoted(input, "block_id", 20),
+ subject: (_input, context) =>
+ quotedName(getBlockDisplayName(context.displayName, context.output)),
},
schedule_agent: {
category: "agent",
@@ -138,6 +140,8 @@ export const PLATFORM_TOOL_CATALOG: Record<string, ToolMeta> = {
category: "block",
running: "Continuing block run",
done: "Continued block run",
+ subject: (_input, context) =>
+ quotedName(getBlockDisplayName(context.displayName, context.output)),
},
run_mcp_tool: {
category: "mcp",
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.shared.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.shared.ts
index ddc3cd7eb6..5e1e4e8c11 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.shared.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.shared.ts
@@ -24,11 +24,16 @@ export type ChainCategory =
export type ToolInput = Record<string, unknown>;
+export interface ToolDisplayContext {
+ displayName?: unknown;
+ output?: unknown;
+}
+
export interface ToolMeta {
category: ChainCategory;
running: string;
done: string;
- subject?: (input: ToolInput) => string | null;
+ subject?: (input: ToolInput, context: ToolDisplayContext) => string | null;
}
export function strField(input: ToolInput, key: string): string | null {
@@ -41,6 +46,9 @@ export function quoted(
key: string,
maxLen = 50,
): string | null {
- const value = strField(input, key);
+ return quotedName(strField(input, key), maxLen);
+}
+
+export function quotedName(value: string | null, maxLen = 50): string | null {
return value ? `"${truncate(value, maxLen)}"` : null;
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.ts
index 66d0a536f0..aa04cc4ce8 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/toolCatalog.ts
@@ -1,6 +1,11 @@
import { AGENT_TOOL_CATALOG } from "./toolCatalog.agent";
import { PLATFORM_TOOL_CATALOG } from "./toolCatalog.platform";
-import type { ChainCategory, ToolInput, ToolMeta } from "./toolCatalog.shared";
+import type {
+ ChainCategory,
+ ToolDisplayContext,
+ ToolInput,
+ ToolMeta,
+} from "./toolCatalog.shared";
export type { ChainCategory } from "./toolCatalog.shared";
@@ -13,12 +18,14 @@ export function getCatalogLabel(
toolName: string,
input: unknown,
state: "running" | "done" | "error",
+ context: ToolDisplayContext = {},
): { category: ChainCategory; text: string } | null {
const meta = COPILOT_TOOL_CATALOG[toolName];
if (!meta) return null;
const subject =
meta.subject?.(
input && typeof input === "object" ? (input as ToolInput) : {},
+ context,
) ?? null;
const suffix = subject ? ` ${subject}` : "";
const text =
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.test.ts
index f2874b50c0..cd124caad3 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.test.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.test.ts
@@ -33,7 +33,7 @@ describe("getSessionActivity", () => {
expect(getSessionActivity(messages)).toEqual({ runs: [], schedules: [] });
});
- it("surfaces an in-flight run from the tool input, deslugifying the name", () => {
+ it("keeps an unresolved slug-launched run unnamed", () => {
const messages = messageOf(
toolPart({
output: undefined,
@@ -44,7 +44,7 @@ describe("getSessionActivity", () => {
const { runs } = getSessionActivity(messages);
expect(runs).toHaveLength(1);
expect(runs[0]).toMatchObject({
- name: "daily digest",
+ name: null,
status: "RUNNING",
libraryAgentId: null,
startedAt: null,
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.ts
index cba7c22e80..3b21937605 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFileCards/helpers.ts
@@ -1,10 +1,13 @@
-import type { UIMessage } from "ai";
+import type { ToolUIPart, UIMessage } from "ai";
import { asObject, str } from "../ToolChain/resultHelpers";
+import {
+ getAgentDisplayName,
+ withToolDisplayNames,
+} from "../../helpers/toolDisplay";
export interface SessionRun {
executionId: string;
- /** Null while a run is in flight and was started by library-agent id — the
- * tool input carries no name, so the row resolves one itself. */
+ /** Null without a resolved name; the row looks up libraryAgentId when present. */
name: string | null;
libraryAgentId: string | null;
status: string | null;
@@ -42,7 +45,7 @@ export function getSessionActivity(messages: UIMessage[]): {
const deletedScheduleIds = new Set<string>();
for (const message of messages) {
- for (const part of message.parts) {
+ for (const part of withToolDisplayNames(message.parts)) {
if (!part.type.startsWith("tool-")) continue;
const output = asObject((part as { output?: unknown }).output);
const toolInput = asObject((part as { input?: unknown }).input);
@@ -59,13 +62,9 @@ export function getSessionActivity(messages: UIMessage[]): {
const key =
(part as { toolCallId?: string }).toolCallId ??
`pending-${runs.size}`;
- // ``run_agent`` takes a slug or a library-agent id, never a name.
- // The slug's trailing segment is the agent, so it reads fine once
- // de-slugified; an id-launched run has to be looked up by the row.
- const slug = input ? str(input, "username_agent_slug") : null;
runs.set(key, {
executionId: key,
- name: slug ? deslugify(slug) : null,
+ name: getAgentDisplayName((part as ToolUIPart).title),
libraryAgentId: input ? str(input, "library_agent_id") : null,
status: "RUNNING",
startedAt: null,
@@ -76,7 +75,7 @@ export function getSessionActivity(messages: UIMessage[]): {
if (!output) continue;
if (RUN_TOOLS.has(part.type)) {
- const name = str(output, "graph_name", "agent_name");
+ const name = getAgentDisplayName((part as ToolUIPart).title, output);
// Async runs answer with an execution_started envelope
// (execution_id at the top level); synchronous waited runs answer
// with agent_output, nesting the id under `execution`.
@@ -162,9 +161,3 @@ export function getSessionActivity(messages: UIMessage[]): {
schedules: [...schedules.values()].reverse(),
};
}
-
-/** "creator/daily-digest" → "daily digest". */
-function deslugify(slug: string): string {
- const agent = slug.split("/").pop() ?? slug;
- return agent.replace(/[-_]+/g, " ").trim();
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/__tests__/blockDisplay.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/__tests__/blockDisplay.test.ts
new file mode 100644
index 0000000000..53ff1aacdc
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/__tests__/blockDisplay.test.ts
@@ -0,0 +1,182 @@
+import type { UIMessage } from "ai";
+import { describe, expect, it } from "vitest";
+import {
+ getChainHeading,
+ toChainRow,
+} from "../../components/ToolChain/helpers";
+import { convertChatSessionMessagesToUiMessages } from "../convertChatSessionToUiMessages";
+import {
+ getAgentDisplayName,
+ getBlockDisplayName,
+ withToolDisplayNames,
+} from "../toolDisplay";
+
+type Part = UIMessage["parts"][number];
+const blockID = "db7d8f02-2f44-4c55-ab7a-eae0941f0c30";
+
+function blockPart(
+ tool = "run_block",
+ extras: Record<string, unknown> = {},
+): Part {
+ return {
+ type: `tool-${tool}`,
+ toolCallId: "block-call",
+ state: "input-available",
+ input: { block_id: blockID },
+ ...extras,
+ } as Part;
+}
+
+describe("block display names", () => {
+ it.each(["run_block", "continue_run_block"])(
+ "renders canonical %s names in live rows and the heading",
+ (tool) => {
+ const input = { block_id: blockID };
+ const parts = withToolDisplayNames([
+ blockPart(tool, { input }),
+ {
+ type: "data-tool-display",
+ id: "block-call",
+ data: {
+ toolCallId: "block-call",
+ displayName: "FillTextTemplateBlock",
+ },
+ },
+ ]);
+ const row = toChainRow(parts[0], 0)!;
+ expect(row.text).toBe(
+ tool === "run_block"
+ ? 'Running block "Fill Text Template"…'
+ : 'Continuing block run "Fill Text Template"…',
+ );
+ expect(getChainHeading([row], true)).toBe(row.text);
+ expect(row.input).toEqual(input);
+ expect(row.text).not.toContain(blockID);
+ },
+ );
+
+ it.each([undefined, "", " ", 12, {}, []])(
+ "ignores malformed metadata %j and recovers historical names",
+ (name) => {
+ expect(
+ getBlockDisplayName(name, { block_name: "FillTextTemplateBlock" }),
+ ).toBe("Fill Text Template");
+ },
+ );
+
+ it.each([
+ [{ block_name: "FillTextTemplateBlock" }, "Fill Text Template"],
+ ['{"block":{"name":"HTTPAPIRequestBlock"}}', "HTTPAPI Request"],
+ [
+ {
+ type: "setup_requirements",
+ setup_info: { agent_name: "FillTextTemplateBlock" },
+ },
+ "Fill Text Template",
+ ],
+ [{ block_name: " ", block: { name: "TextBlock" } }, "Text"],
+ [{ block_id: blockID, outputs: { name: "unrelated output" } }, null],
+ ["{truncated", null],
+ ])("reads supported legacy result names from %j", (output, expected) => {
+ expect(getBlockDisplayName(undefined, output)).toBe(expected);
+ });
+
+ it("gives metadata priority and preserves human agent names unchanged", () => {
+ expect(
+ getBlockDisplayName("FillTextTemplateBlock", { block_name: "OldBlock" }),
+ ).toBe("Fill Text Template");
+ expect(getAgentDisplayName("Daily briefing Block")).toBe(
+ "Daily briefing Block",
+ );
+ });
+
+ it.each(["run_block", "continue_run_block"])(
+ "keeps unresolved %s and streaming input generic",
+ (tool) => {
+ for (const state of ["input-streaming", "input-available"]) {
+ const row = toChainRow(blockPart(tool, { state }), 0)!;
+ expect(row.text).toBe(
+ tool === "run_block" ? "Running block…" : "Continuing block run…",
+ );
+ expect(row.text).not.toContain(blockID);
+ }
+ },
+ );
+
+ it.each([
+ [
+ {
+ state: "output-available",
+ output: { block_name: "FillTextTemplateBlock" },
+ },
+ 'Ran block "Fill Text Template"',
+ ],
+ [
+ {
+ state: "output-error",
+ title: "FillTextTemplateBlock",
+ errorText: "Failed",
+ },
+ 'Failed while running block "Fill Text Template"',
+ ],
+ [
+ {
+ state: "output-available",
+ output: {
+ type: "review_required",
+ block_name: "FillTextTemplateBlock",
+ },
+ },
+ "Review Fill Text Template",
+ ],
+ [
+ {
+ state: "output-available",
+ output: {
+ type: "setup_requirements",
+ setup_info: { agent_name: "FillTextTemplateBlock" },
+ },
+ },
+ "Connect Fill Text Template to continue",
+ ],
+ ])(
+ "normalizes completed, failed and action-required rows %j",
+ (extras, expected) => {
+ expect(toChainRow(blockPart("run_block", extras), 0)?.text).toBe(
+ expected,
+ );
+ },
+ );
+
+ it.each(["run_block", "continue_run_block"])(
+ "retains %s names on reloaded/shared history",
+ (tool) => {
+ const { messages } = convertChatSessionMessagesToUiMessages(
+ "session",
+ [
+ {
+ role: "assistant",
+ sequence: 1,
+ tool_calls: [
+ {
+ id: "block-call",
+ type: "function",
+ display_name: "FillTextTemplateBlock",
+ function: {
+ name: tool,
+ arguments: JSON.stringify({ block_id: blockID }),
+ },
+ },
+ ],
+ },
+ ],
+ { isComplete: true },
+ );
+ expect(toChainRow(messages[0].parts[0], 0)?.text).toBe(
+ tool === "run_block"
+ ? 'Ran block "Fill Text Template"'
+ : 'Continued block run "Fill Text Template"',
+ );
+ },
+ );
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/__tests__/toolDisplay.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/__tests__/toolDisplay.test.ts
new file mode 100644
index 0000000000..3ab5451fb1
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/__tests__/toolDisplay.test.ts
@@ -0,0 +1,259 @@
+import { readUIMessageStream, type UIMessage, type UIMessageChunk } from "ai";
+import { describe, expect, it } from "vitest";
+import {
+ getChainHeading,
+ toChainRow,
+} from "../../components/ToolChain/helpers";
+import { getSessionActivity } from "../../components/WorkspaceFileCards/helpers";
+import { convertChatSessionMessagesToUiMessages } from "../convertChatSessionToUiMessages";
+import { getAgentDisplayName, withToolDisplayNames } from "../toolDisplay";
+
+type Part = UIMessage["parts"][number];
+
+function runPart(toolCallId = "call-one"): Part {
+ return {
+ type: "tool-run_agent",
+ toolCallId,
+ state: "input-available",
+ input: { library_agent_id: "b71fd24c-7623-4a73-a000-000000000000" },
+ };
+}
+
+function displayPart(toolCallId: string, displayName: unknown): Part {
+ return {
+ type: "data-tool-display",
+ id: toolCallId,
+ data: { toolCallId, displayName },
+ };
+}
+
+describe("agent display names", () => {
+ it("updates concurrent tool rows and the live heading by actual call ID", () => {
+ const first = runPart();
+ const second = runPart("call-two");
+ const parts = withToolDisplayNames([
+ first,
+ displayPart("call-two", "Second workflow"),
+ second,
+ displayPart("call-one", "Daily briefing"),
+ ]);
+ const rows = parts.flatMap((part, index) => toChainRow(part, index) ?? []);
+ expect(rows.map((row) => row.text)).toEqual([
+ 'Running agent "Daily briefing"…',
+ 'Running agent "Second workflow"…',
+ ]);
+ expect(getChainHeading(rows, true)).toBe(
+ 'Running agent "Second workflow"…',
+ );
+ expect(parts[0]).toMatchObject({
+ input: { library_agent_id: "b71fd24c-7623-4a73-a000-000000000000" },
+ });
+ expect(first).not.toHaveProperty("title");
+ expect(
+ getSessionActivity([{ id: "m", role: "assistant", parts }]).runs.map(
+ (run) => run.name,
+ ),
+ ).toEqual(["Second workflow", "Daily briefing"]);
+ });
+
+ it("shows a generic label for unresolved IDs, slugs and streaming input", () => {
+ for (const input of [
+ { library_agent_id: "b71fd24c-7623-4a73-a000-000000000000" },
+ { username_agent_slug: "creator/daily-briefing" },
+ { agent_name: "Untrusted argument" },
+ ]) {
+ expect(toChainRow({ ...runPart(), input } as Part, 0)?.text).toBe(
+ "Running agent…",
+ );
+ expect(
+ toChainRow({ ...runPart(), input, state: "input-streaming" } as Part, 0)
+ ?.text,
+ ).toBe("Running agent…");
+ }
+ });
+
+ it.each([
+ [{ graph_name: "Graph name" }, "Graph name"],
+ [
+ JSON.stringify({ type: "agent_output", agent_name: "Waited run" }),
+ "Waited run",
+ ],
+ [
+ { type: "agent_details", agent: { name: "Agent details" } },
+ "Agent details",
+ ],
+ [
+ { type: "setup_requirements", setup_info: { agent_name: "Setup name" } },
+ "Setup name",
+ ],
+ [{ name: "Unrelated name", outputs: { agent_name: "Output value" } }, null],
+ [{ agent: { name: "Untyped nested name" } }, null],
+ ["{truncated", null],
+ [{ graph_name: " ", agent_name: 42 }, null],
+ ])(
+ "resolves only supported historical result names from %j",
+ (output, expected) => {
+ expect(getAgentDisplayName(undefined, output)).toBe(expected);
+ },
+ );
+
+ it.each([undefined, null, "", " ", 42, {}, []])(
+ "ignores malformed display names %j",
+ (displayName) => {
+ const parts = withToolDisplayNames([
+ runPart(),
+ displayPart("call-one", displayName),
+ ]);
+ expect(toChainRow(parts[0], 0)?.text).toBe("Running agent…");
+ expect(
+ getAgentDisplayName(displayName, { graph_name: "Result fallback" }),
+ ).toBe("Result fallback");
+ },
+ );
+
+ it("keeps the latest valid name on replay and uses it for done and error labels", () => {
+ const parts = withToolDisplayNames([
+ runPart(),
+ displayPart("call-one", "First name"),
+ displayPart("call-one", " Canonical name "),
+ displayPart("call-one", " "),
+ { type: "data-tool-display", data: { displayName: "No call ID" } },
+ ]);
+ expect(
+ toChainRow(
+ {
+ ...parts[0],
+ state: "output-available",
+ output: { graph_name: "Older name" },
+ } as Part,
+ 0,
+ )?.text,
+ ).toBe('Ran agent "Canonical name"');
+ expect(
+ toChainRow(
+ {
+ ...parts[0],
+ state: "output-error",
+ errorText: "Execution failed",
+ } as Part,
+ 0,
+ )?.text,
+ ).toBe('Failed while running agent "Canonical name"');
+ });
+
+ it.each([
+ { graph_name: "Historical workflow" },
+ JSON.stringify({ agent_name: "Historical workflow" }),
+ ])(
+ "recovers names from historical object or JSON outputs across pages",
+ (output) => {
+ const { messages } = convertChatSessionMessagesToUiMessages(
+ "session",
+ [
+ {
+ role: "assistant",
+ sequence: 1,
+ tool_calls: [
+ {
+ id: "call-one",
+ type: "function",
+ function: {
+ name: "run_agent",
+ arguments: { library_agent_id: "library-id" },
+ },
+ },
+ ],
+ },
+ ],
+ { extraToolOutputs: new Map([["call-one", output]]) },
+ );
+ expect(toChainRow(messages[0].parts[0], 0)?.text).toBe(
+ 'Ran agent "Historical workflow"',
+ );
+ },
+ );
+
+ it.each([false, true])(
+ "hydrates persisted names for active/settled sessions and public shares (complete=%s)",
+ (isComplete) => {
+ const { messages } = convertChatSessionMessagesToUiMessages(
+ "session",
+ [
+ {
+ role: "assistant",
+ sequence: 1,
+ tool_calls: [
+ {
+ id: "call-one",
+ type: "function",
+ display_name: "Daily briefing",
+ function: {
+ name: "run_agent",
+ arguments: '{"library_agent_id":"library-id"}',
+ },
+ },
+ ],
+ },
+ ],
+ {
+ isComplete,
+ fileUrlBuilder: (id) =>
+ `/api/public/shared/chats/token/files/${id}/download`,
+ },
+ );
+ expect(messages[0].parts[0]).toMatchObject({
+ title: "Daily briefing",
+ input: { library_agent_id: "library-id" },
+ });
+ expect(toChainRow(messages[0].parts[0], 0)?.text).toBe(
+ isComplete
+ ? 'Ran agent "Daily briefing"'
+ : 'Running agent "Daily briefing"…',
+ );
+ },
+ );
+
+ it("consumes non-transient AI SDK display parts and upserts them during stream replay", async () => {
+ const chunks: UIMessageChunk[] = [
+ { type: "start", messageId: "message" },
+ {
+ type: "tool-input-available",
+ toolCallId: "call-one",
+ toolName: "run_agent",
+ input: { library_agent_id: "library-id" },
+ },
+ {
+ type: "data-tool-display",
+ id: "call-one",
+ data: { toolCallId: "call-one", displayName: "Daily briefing" },
+ },
+ {
+ type: "data-tool-display",
+ id: "call-one",
+ data: { toolCallId: "call-one", displayName: "Daily briefing updated" },
+ },
+ {
+ type: "tool-output-available",
+ toolCallId: "call-one",
+ output: { graph_name: "Old result name" },
+ },
+ { type: "finish" },
+ ];
+ const stream = new ReadableStream<UIMessageChunk>({
+ start(controller) {
+ chunks.forEach((chunk) => controller.enqueue(chunk));
+ controller.close();
+ },
+ });
+ let latest: UIMessage | undefined;
+ for await (const message of readUIMessageStream({ stream }))
+ latest = message;
+ expect(
+ latest?.parts.filter((part) => part.type === "data-tool-display"),
+ ).toHaveLength(1);
+ const parts = withToolDisplayNames(latest?.parts ?? []);
+ expect(toChainRow(parts[0], 0)?.text).toBe(
+ 'Ran agent "Daily briefing updated"',
+ );
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/convertChatSessionToUiMessages.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/convertChatSessionToUiMessages.ts
index 68d7c56dc2..819ad36498 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/convertChatSessionToUiMessages.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/convertChatSessionToUiMessages.ts
@@ -1,5 +1,6 @@
import { getGetWorkspaceDownloadFileByIdUrl } from "@/app/api/__generated__/endpoints/workspace/workspace";
import type { FileUIPart, UIMessage, UIDataTypes, UITools } from "ai";
+import { toolDisplayName } from "./toolDisplay";
export interface TurnStats {
durationMs?: number;
@@ -429,6 +430,7 @@ export function convertChatSessionMessagesToUiMessages(
if (!rawToolCall || typeof rawToolCall !== "object") continue;
const toolCall = rawToolCall as {
id?: unknown;
+ display_name?: unknown;
function?: { name?: unknown; arguments?: unknown };
};
@@ -438,11 +440,13 @@ export function convertChatSessionMessagesToUiMessages(
const input = toToolInput(toolCall.function?.arguments);
const output = toolOutputsByCallId.get(toolCallId);
+ const title = toolDisplayName(toolCall.display_name) ?? undefined;
if (output !== undefined) {
parts.push({
type: `tool-${toolName}`,
toolCallId,
+ title,
state: "output-available",
input,
output: typeof output === "string" ? safeJsonParse(output) : output,
@@ -453,6 +457,7 @@ export function convertChatSessionMessagesToUiMessages(
parts.push({
type: `tool-${toolName}`,
toolCallId,
+ title,
state: "output-available",
input,
output: "",
@@ -461,6 +466,7 @@ export function convertChatSessionMessagesToUiMessages(
parts.push({
type: `tool-${toolName}`,
toolCallId,
+ title,
state: "input-available",
input,
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/toolDisplay.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/toolDisplay.ts
new file mode 100644
index 0000000000..5ac03d8a0d
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers/toolDisplay.ts
@@ -0,0 +1,67 @@
+import type { ToolUIPart, UIMessage } from "ai";
+import { beautifyString } from "@/lib/utils";
+import { asObject } from "../components/ToolChain/resultHelpers";
+import { TOOL_DISPLAY_PART_TYPE } from "../messageParts";
+
+export function toolDisplayName(value: unknown): string | null {
+ return typeof value === "string" && value.trim() ? value.trim() : null;
+}
+
+export function withToolDisplayNames(
+ parts: UIMessage["parts"],
+): UIMessage["parts"] {
+ const names = new Map<string, string>();
+ for (const part of parts) {
+ if (part.type !== TOOL_DISPLAY_PART_TYPE || !("data" in part)) continue;
+ const data = asObject(part.data);
+ const toolCallID = toolDisplayName(data?.toolCallId);
+ const name = toolDisplayName(data?.displayName);
+ if (toolCallID && name) names.set(toolCallID, name);
+ }
+ if (names.size === 0) return parts;
+ return parts.map((part) => {
+ if (!part.type.startsWith("tool-")) return part;
+ const tool = part as ToolUIPart;
+ const title = names.get(tool.toolCallId);
+ return title ? { ...tool, title } : part;
+ });
+}
+
+export function getAgentDisplayName(
+ displayName: unknown,
+ output?: unknown,
+): string | null {
+ const name = toolDisplayName(displayName);
+ if (name) return name;
+ const result = asObject(output);
+ if (!result) return null;
+ const resultName =
+ toolDisplayName(result.graph_name) ?? toolDisplayName(result.agent_name);
+ if (resultName) return resultName;
+ if (result.type === "agent_details") {
+ return toolDisplayName(asObject(result.agent)?.name);
+ }
+ if (result.type === "setup_requirements") {
+ return toolDisplayName(asObject(result.setup_info)?.agent_name);
+ }
+ return null;
+}
+
+export function getBlockDisplayName(
+ displayName: unknown,
+ output?: unknown,
+): string | null {
+ const result = asObject(output);
+ const name =
+ toolDisplayName(displayName) ??
+ toolDisplayName(result?.block_name) ??
+ toolDisplayName(asObject(result?.block)?.name) ??
+ (result?.type === "setup_requirements"
+ ? toolDisplayName(asObject(result.setup_info)?.agent_name)
+ : null);
+ return name
+ ? beautifyString(name)
+ .replace(/ Block$/, "")
+ .trim()
+ : null;
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/messageParts.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/messageParts.ts
index 4237740500..f0d84d8559 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/messageParts.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/messageParts.ts
@@ -5,6 +5,7 @@ import { DREAM_OPERATIONS_PART_TYPE } from "./dreamOperations";
/** Transient copy for the Thinking indicator — never rendered inline. */
export const STATUS_PART_TYPE = "data-status";
+export const TOOL_DISPLAY_PART_TYPE = "data-tool-display";
/** Legacy resume metadata. */
const CURSOR_PART_TYPE = "data-cursor";
@@ -23,6 +24,7 @@ const BOOKKEEPING_PART_TYPES: ReadonlySet<string> = new Set([
STATUS_PART_TYPE,
DREAM_OPERATIONS_PART_TYPE,
COMPACTION_DATA_PART_TYPE,
+ TOOL_DISPLAY_PART_TYPE,
]);
export function isBookkeepingPart(part: { type: string }): boolean {
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunBlock/helpers.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunBlock/helpers.tsx
index 1588b6e0f9..cfd3723964 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunBlock/helpers.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunBlock/helpers.tsx
@@ -3,9 +3,9 @@ import type { BlockOutputResponse } from "@/app/api/__generated__/models/blockOu
import type { ErrorResponse } from "@/app/api/__generated__/models/errorResponse";
import { ResponseType } from "@/app/api/__generated__/models/responseType";
import type { SetupRequirementsResponse } from "@/app/api/__generated__/models/setupRequirementsResponse";
-import { beautifyString } from "@/lib/utils";
import type { ToolUIPart } from "ai";
import { ScaleLoader } from "../../components/ScaleLoader/ScaleLoader";
+import { getBlockDisplayName } from "../../helpers/toolDisplay";
import {
AlertDiamondIcon,
PlayCircleIcon,
@@ -210,10 +210,9 @@ export function getBlockNamesById(
if (response?.status !== 200) return undefined;
const names = new Map<string, string>();
for (const block of response.data) {
- if (typeof block.id === "string" && typeof block.name === "string") {
- // Same display treatment as the blocks menu: beautify and
- // drop the redundant "Block" suffix
- names.set(block.id, beautifyString(block.name).replace(/ Block$/, ""));
+ const name = getBlockDisplayName(block.name);
+ if (typeof block.id === "string" && name) {
+ names.set(block.id, name);
}
}
return names;