From b8daab721ddbb3479216691346034d3bc0293832 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 12 Mar 2025 16:39:24 -0400 Subject: [PATCH] Update agent message to use first-person perspective (#7197) Co-authored-by: openhands --- frontend/__tests__/services/actions.test.ts | 89 ++++++++++++++++++++- frontend/src/services/actions.ts | 7 +- 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/frontend/__tests__/services/actions.test.ts b/frontend/__tests__/services/actions.test.ts index 511473b1d6..1b71f3788a 100644 --- a/frontend/__tests__/services/actions.test.ts +++ b/frontend/__tests__/services/actions.test.ts @@ -1,7 +1,9 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; -import { handleStatusMessage } from "#/services/actions"; +import { handleStatusMessage, handleActionMessage } from "#/services/actions"; import store from "#/store"; import { trackError } from "#/utils/error-handler"; +import ActionType from "#/types/action-type"; +import { ActionMessage } from "#/types/message"; // Mock dependencies vi.mock("#/utils/error-handler", () => ({ @@ -56,4 +58,89 @@ describe("Actions Service", () => { })); }); }); + + describe("handleActionMessage", () => { + it("should use first-person perspective for task completion messages", () => { + // Test partial completion + const messagePartial: ActionMessage = { + id: 1, + action: ActionType.FINISH, + source: "agent", + message: "", + timestamp: new Date().toISOString(), + args: { + final_thought: "", + task_completed: "partial", + outputs: "", + thought: "" + } + }; + + // Mock implementation to capture the message + let capturedPartialMessage = ""; + (store.dispatch as any).mockImplementation((action: any) => { + if (action.type === "chat/addAssistantMessage" && + action.payload.includes("believe that the task was **completed partially**")) { + capturedPartialMessage = action.payload; + } + }); + + handleActionMessage(messagePartial); + expect(capturedPartialMessage).toContain("I believe that the task was **completed partially**"); + + // Test not completed + const messageNotCompleted: ActionMessage = { + id: 2, + action: ActionType.FINISH, + source: "agent", + message: "", + timestamp: new Date().toISOString(), + args: { + final_thought: "", + task_completed: "false", + outputs: "", + thought: "" + } + }; + + // Mock implementation to capture the message + let capturedNotCompletedMessage = ""; + (store.dispatch as any).mockImplementation((action: any) => { + if (action.type === "chat/addAssistantMessage" && + action.payload.includes("believe that the task was **not completed**")) { + capturedNotCompletedMessage = action.payload; + } + }); + + handleActionMessage(messageNotCompleted); + expect(capturedNotCompletedMessage).toContain("I believe that the task was **not completed**"); + + // Test completed successfully + const messageCompleted: ActionMessage = { + id: 3, + action: ActionType.FINISH, + source: "agent", + message: "", + timestamp: new Date().toISOString(), + args: { + final_thought: "", + task_completed: "true", + outputs: "", + thought: "" + } + }; + + // Mock implementation to capture the message + let capturedCompletedMessage = ""; + (store.dispatch as any).mockImplementation((action: any) => { + if (action.type === "chat/addAssistantMessage" && + action.payload.includes("believe that the task was **completed successfully**")) { + capturedCompletedMessage = action.payload; + } + }); + + handleActionMessage(messageCompleted); + expect(capturedCompletedMessage).toContain("I believe that the task was **completed successfully**"); + }); + }); }); diff --git a/frontend/src/services/actions.ts b/frontend/src/services/actions.ts index 485c807dd0..80b6dfd910 100644 --- a/frontend/src/services/actions.ts +++ b/frontend/src/services/actions.ts @@ -62,13 +62,12 @@ const messageActions = { let successPrediction = ""; if (message.args.task_completed === "partial") { successPrediction = - "The agent thinks that the task was **completed partially**."; + "I believe that the task was **completed partially**."; } else if (message.args.task_completed === "false") { - successPrediction = - "The agent thinks that the task was **not completed**."; + successPrediction = "I believe that the task was **not completed**."; } else if (message.args.task_completed === "true") { successPrediction = - "The agent thinks that the task was **completed successfully**."; + "I believe that the task was **completed successfully**."; } if (successPrediction) { // if final_thought is not empty, add a new line before the success prediction