slack: slim down the trace reply (drop greeting, suppress unfurl) (#1278)

Now that assistant.threads.setStatus carries the "is thinking…"
indicator, the per-run greeting phrase + auto-unfurl on the LangSmith
link are just visual noise stacking on top of it. The trace reply now
posts only `<url|View trace>` + a tip, with link unfurling off so the
smith.langchain.com card no longer appears.

Adds an `unfurl_links`/`unfurl_media` knob to post_slack_thread_reply_with_ts
(default-on to preserve behaviour for every other caller).
This commit is contained in:
Johannes du Plessis 2026-05-08 14:51:28 -07:00 • committed by GitHub
parent 148efeb269
commit b541f6d08a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 54 deletions

View file

@ -334,15 +334,24 @@ async def set_slack_assistant_status(
return False return False
async def post_slack_thread_reply_with_ts(channel_id: str, thread_ts: str, text: str) -> str | None: async def post_slack_thread_reply_with_ts(
channel_id: str,
thread_ts: str,
text: str,
*,
unfurl_links: bool = True,
unfurl_media: bool = True,
) -> str | None:
"""Post a reply in a Slack thread and return its Slack timestamp.""" """Post a reply in a Slack thread and return its Slack timestamp."""
if not SLACK_BOT_TOKEN: if not SLACK_BOT_TOKEN:
return None return None
payload = { payload: dict[str, Any] = {
"channel": channel_id, "channel": channel_id,
"thread_ts": thread_ts, "thread_ts": thread_ts,
"text": text, "text": text,
"unfurl_links": unfurl_links,
"unfurl_media": unfurl_media,
} }
async with httpx.AsyncClient() as http_client: async with httpx.AsyncClient() as http_client:
@ -682,19 +691,6 @@ async def resolve_slack_links_in_context(
return resolved_links_section, image_urls return resolved_links_section, image_urls
TRACE_REPLY_PHRASES: tuple[str, ...] = (
"Working on it!",
"On it!",
"Diving in!",
"Powering up!",
"Heads down.",
"Cracking knuckles...",
"Spinning up...",
"Looking...",
"Time to cook. 🧑‍🍳",
"Running to the roar!",
)
TRACE_REPLY_TIPS: tuple[str, ...] = ( TRACE_REPLY_TIPS: tuple[str, ...] = (
"You can message me in this thread while I'm running — I'll pick up your follow-up before my next step.", "You can message me in this thread while I'm running — I'll pick up your follow-up before my next step.",
"Kick off another task in parallel — each one runs in its own isolated sandbox, no queuing.", "Kick off another task in parallel — each one runs in its own isolated sandbox, no queuing.",
@ -707,22 +703,22 @@ TRACE_REPLY_TIPS: tuple[str, ...] = (
) )
def _format_trace_reply(message: str, trace_url: str | None) -> str: def _format_trace_reply(trace_url: str | None) -> str:
"""Format the initial trace reply with a randomly selected tip.""" """Format the initial trace reply with a randomly selected tip."""
tip = random.choice(TRACE_REPLY_TIPS) tip = random.choice(TRACE_REPLY_TIPS)
head = f"{message} <{trace_url}|View trace>" if trace_url else message head = f"<{trace_url}|View trace>\n" if trace_url else ""
return f"{head}\n_Tip: {tip}_" return f"{head}_Tip: {tip}_"
async def post_slack_trace_reply( async def post_slack_trace_reply(channel_id: str, thread_ts: str, thread_id: str) -> str | None:
channel_id: str, thread_ts: str, thread_id: str, message: str | None = None
) -> str | None:
"""Post a trace URL reply in a Slack thread and return its Slack timestamp.""" """Post a trace URL reply in a Slack thread and return its Slack timestamp."""
if message is None:
message = random.choice(TRACE_REPLY_PHRASES)
trace_url = get_langsmith_trace_url(thread_id) trace_url = get_langsmith_trace_url(thread_id)
return await post_slack_thread_reply_with_ts( return await post_slack_thread_reply_with_ts(
channel_id, thread_ts, _format_trace_reply(message, trace_url) channel_id,
thread_ts,
_format_trace_reply(trace_url),
unfurl_links=False,
unfurl_media=False,
) )

View file

@ -1021,9 +1021,7 @@ async def process_slack_pr_review_request(
if result.get("success"): if result.get("success"):
thread_id = result.get("thread_id") thread_id = result.get("thread_id")
if isinstance(thread_id, str) and thread_id: if isinstance(thread_id, str) and thread_id:
await post_slack_trace_reply( await post_slack_trace_reply(channel_id, thread_ts, thread_id)
channel_id, thread_ts, thread_id, message="Taking a look..."
)
await set_slack_assistant_status(channel_id, thread_ts) await set_slack_assistant_status(channel_id, thread_ts)
return return

View file

@ -603,14 +603,11 @@ def test_process_slack_pr_review_request_posts_trace_reply(monkeypatch) -> None:
captured["slack_thread_ts"] = slack_thread_ts captured["slack_thread_ts"] = slack_thread_ts
return {"success": True, "thread_id": "reviewer-thread-id", "pr_url": pr_ref.url} return {"success": True, "thread_id": "reviewer-thread-id", "pr_url": pr_ref.url}
async def fake_post_slack_trace_reply( async def fake_post_slack_trace_reply(channel_id: str, thread_ts: str, thread_id: str) -> None:
channel_id: str, thread_ts: str, thread_id: str, message: str = "Working on it!"
) -> None:
captured["trace_reply"] = { captured["trace_reply"] = {
"channel_id": channel_id, "channel_id": channel_id,
"thread_ts": thread_ts, "thread_ts": thread_ts,
"thread_id": thread_id, "thread_id": thread_id,
"message": message,
} }
async def fake_set_slack_assistant_status(channel_id: str, thread_ts: str) -> bool: async def fake_set_slack_assistant_status(channel_id: str, thread_ts: str) -> bool:
@ -641,7 +638,6 @@ def test_process_slack_pr_review_request_posts_trace_reply(monkeypatch) -> None:
"channel_id": "C123", "channel_id": "C123",
"thread_ts": "1700000000.000100", "thread_ts": "1700000000.000100",
"thread_id": "reviewer-thread-id", "thread_id": "reviewer-thread-id",
"message": "Taking a look...",
} }
assert captured["status_calls"] == [ assert captured["status_calls"] == [
("C123", "1700000000.000100"), ("C123", "1700000000.000100"),

View file

@ -5,7 +5,6 @@ import pytest
from agent import webapp from agent import webapp
from agent.utils import slack as slack_utils from agent.utils import slack as slack_utils
from agent.utils.slack import ( from agent.utils.slack import (
TRACE_REPLY_PHRASES,
TRACE_REPLY_TIPS, TRACE_REPLY_TIPS,
convert_mentions_to_slack_format, convert_mentions_to_slack_format,
format_slack_messages_for_prompt, format_slack_messages_for_prompt,
@ -222,15 +221,20 @@ def test_format_slack_messages_for_prompt_replaces_bot_id_mention_in_text() -> N
assert formatted == "@alice(U123): @open-swe status update?" assert formatted == "@alice(U123): @open-swe status update?"
def test_post_slack_trace_reply_picks_random_phrase_when_no_message( def test_post_slack_trace_reply_emits_tip_only_when_no_trace_url(
monkeypatch: pytest.MonkeyPatch, monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None:
posted: list[str] = [] posted: list[dict] = []
async def fake_post_slack_thread_reply_with_ts( async def fake_post_slack_thread_reply_with_ts(
channel_id: str, thread_ts: str, text: str channel_id: str,
thread_ts: str,
text: str,
*,
unfurl_links: bool = True,
unfurl_media: bool = True,
) -> str | None: ) -> str | None:
posted.append(text) posted.append({"text": text, "unfurl_links": unfurl_links, "unfurl_media": unfurl_media})
return "1.1" return "1.1"
monkeypatch.setattr( monkeypatch.setattr(
@ -241,35 +245,44 @@ def test_post_slack_trace_reply_picks_random_phrase_when_no_message(
asyncio.run(post_slack_trace_reply("C123", "1.0", "thread-id")) asyncio.run(post_slack_trace_reply("C123", "1.0", "thread-id"))
assert len(posted) == 1 assert len(posted) == 1
head, _, tip_line = posted[0].partition("\n") text = posted[0]["text"]
assert head in TRACE_REPLY_PHRASES assert text.startswith("_Tip: ") and text.endswith("_")
assert tip_line.startswith("_Tip: ") and tip_line.endswith("_") assert any(tip in text for tip in TRACE_REPLY_TIPS)
assert any(tip in tip_line for tip in TRACE_REPLY_TIPS) assert posted[0]["unfurl_links"] is False
assert posted[0]["unfurl_media"] is False
def test_post_slack_trace_reply_uses_explicit_message_when_provided( def test_post_slack_trace_reply_includes_trace_link_and_tip(
monkeypatch: pytest.MonkeyPatch, monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None:
posted: list[str] = [] posted: list[dict] = []
async def fake_post_slack_thread_reply_with_ts( async def fake_post_slack_thread_reply_with_ts(
channel_id: str, thread_ts: str, text: str channel_id: str,
thread_ts: str,
text: str,
*,
unfurl_links: bool = True,
unfurl_media: bool = True,
) -> str | None: ) -> str | None:
posted.append(text) posted.append({"text": text, "unfurl_links": unfurl_links, "unfurl_media": unfurl_media})
return "1.1" return "1.1"
monkeypatch.setattr( monkeypatch.setattr(
slack_utils, "post_slack_thread_reply_with_ts", fake_post_slack_thread_reply_with_ts slack_utils, "post_slack_thread_reply_with_ts", fake_post_slack_thread_reply_with_ts
) )
monkeypatch.setattr(slack_utils, "get_langsmith_trace_url", lambda thread_id: None) monkeypatch.setattr(slack_utils, "get_langsmith_trace_url", lambda thread_id: "https://smith/x")
asyncio.run(post_slack_trace_reply("C123", "1.0", "thread-id", message="Taking a look...")) asyncio.run(post_slack_trace_reply("C123", "1.0", "thread-id"))
assert len(posted) == 1 assert len(posted) == 1
head, _, tip_line = posted[0].partition("\n") text = posted[0]["text"]
assert head == "Taking a look..." head, _, tip_line = text.partition("\n")
assert head == "<https://smith/x|View trace>"
assert tip_line.startswith("_Tip: ") and tip_line.endswith("_") assert tip_line.startswith("_Tip: ") and tip_line.endswith("_")
assert any(tip in tip_line for tip in TRACE_REPLY_TIPS) assert any(tip in tip_line for tip in TRACE_REPLY_TIPS)
assert posted[0]["unfurl_links"] is False
assert posted[0]["unfurl_media"] is False
def test_select_slack_context_messages_detects_username_mention() -> None: def test_select_slack_context_messages_detects_username_mention() -> None:
@ -516,14 +529,11 @@ def _setup_slack_mention_fakes(
captured["active_thread_id"] = thread_id captured["active_thread_id"] = thread_id
return False return False
async def fake_post_slack_trace_reply( async def fake_post_slack_trace_reply(channel_id: str, thread_ts: str, thread_id: str) -> None:
channel_id: str, thread_ts: str, thread_id: str, message: str | None = None
) -> None:
captured["trace_reply"] = { captured["trace_reply"] = {
"channel_id": channel_id, "channel_id": channel_id,
"thread_ts": thread_ts, "thread_ts": thread_ts,
"thread_id": thread_id, "thread_id": thread_id,
"message": message,
} }
class _FakeRunsClient: class _FakeRunsClient:
@ -597,7 +607,6 @@ def test_process_slack_mention_creates_thread_first_run_with_trace_reply(
"channel_id": "C123", "channel_id": "C123",
"thread_ts": thread_ts, "thread_ts": thread_ts,
"thread_id": expected_thread_id, "thread_id": expected_thread_id,
"message": None,
} }
run_create = captured["run_create"] run_create = captured["run_create"]