π OpenHands: AI-Driven Development
Update agent message to use first-person perspective (#7197)
Xingyao Wangb8daab721ddb
diff --git a/frontend/__tests__/services/actions.test.ts b/frontend/__tests__/services/actions.test.tsindex 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 dependenciesvi.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.tsindex 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