Skip to content

Commit bcdae09

Browse files
remote-swe-userremote-swe-app[bot]
andauthored
Add WebUI URL to Slack messages at the end of agent loop (#272)
## Description This PR adds the WebUI URL link to Slack messages when the agent finishes its turn. This makes it easier for users to access the WebUI session from anywhere in a long Slack thread without having to scroll back to the beginning. ## Implementation - Added an optional `appendWebappUrl` parameter to `sendSystemMessage` function with default value of `false` - When `appendWebappUrl` is `true`, the function appends a markdown link to the webapp session URL at the end of the Slack message: `([webapp](URL))` - Modified the agent loop to use this parameter only at the end of the agent turn ## Changes - Modified `packages/agent-core/src/lib/messages.ts` to add the optional parameter and webapp URL handling - Modified `packages/worker/src/agent/index.ts` to pass `true` for the parameter at the end of the agent loop ## Related Issues Fixes #270 <!-- DO NOT EDIT: System generated metadata --> <!-- WORKER_ID:1751622968753739 --> --- **Open in Web UI**: https://d2c09i1k2ray87.cloudfront.net/sessions/1751622968753739 --------- Co-authored-by: remote-swe-app[bot] <123456+remote-swe-app[bot]@users.noreply.github.com>
1 parent 62e533a commit bcdae09

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/agent-core/src/lib/messages.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ddb, TableName } from './aws/ddb';
88
import { writeBytesToKey, getBytesFromKey } from './aws/s3';
99
import { sendWebappEvent } from './events';
1010
import { sendMessageToSlack } from './slack';
11+
import { getWebappSessionUrl } from './webapp-origin';
1112
import { MessageItem } from '../schema';
1213

1314
// Maximum input token count before applying middle-out strategy
@@ -305,9 +306,20 @@ const postProcessMessageContent = async (content: string) => {
305306
return flattenedArray;
306307
};
307308

308-
export const sendSystemMessage = async (workerId: string, message: string) => {
309-
await Promise.all([
310-
sendWebappEvent(workerId, { type: 'message', role: 'assistant', message }),
311-
sendMessageToSlack(message),
312-
]);
309+
export const sendSystemMessage = async (workerId: string, message: string, appendWebappUrl: boolean = false) => {
310+
// Always send original message to webapp
311+
await sendWebappEvent(workerId, { type: 'message', role: 'assistant', message });
312+
313+
// For Slack, optionally append webapp URL
314+
if (appendWebappUrl) {
315+
const sessionUrl = await getWebappSessionUrl(workerId);
316+
if (sessionUrl) {
317+
const slackMessage = `${message} ([webapp](${sessionUrl}))`;
318+
await sendMessageToSlack(slackMessage);
319+
} else {
320+
await sendMessageToSlack(message);
321+
}
322+
} else {
323+
await sendMessageToSlack(message);
324+
}
313325
};

packages/worker/src/agent/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ Users will primarily request software engineering assistance including bug fixes
434434
const responseText = finalMessage.content?.at(-1)?.text ?? finalMessage.content?.at(0)?.text ?? '';
435435
// remove <thinking> </thinking> part with multiline support
436436
const responseTextWithoutThinking = responseText.replace(/<thinking>[\s\S]*?<\/thinking>/g, '');
437-
await sendSystemMessage(workerId, `${mention}${responseTextWithoutThinking}`);
437+
// Pass true to appendWebappUrl parameter to add the webapp URL to the Slack message at the end of agent loop
438+
await sendSystemMessage(workerId, `${mention}${responseTextWithoutThinking}`, true);
438439
break;
439440
}
440441
}

0 commit comments

Comments
 (0)