π OpenHands: AI-Driven Development
fix(frontend): preserve saved prompt suffix for inline and profile launches (#17719)
Harsh Kashyap53ad0012f366
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.tsindex 2b58f195b0..bfc8b1cba9 100644--- a/__tests__/api/agent-server-adapter.test.ts+++ b/__tests__/api/agent-server-adapter.test.ts@@ -1520,8 +1520,99 @@ describe("agent_settings runtime services suffix", () => {).toContain("<RUNTIME_SERVICES>");});- it("carries runtime services on the profile path, where agent_settings can't be sent", () => {- // agent_profile_id and agent_settings are mutually exclusive.+ it("preserves a saved system_message_suffix when runtime services are advertised", () => {+ const payload = buildStartConversationRequest({+ settings: {+ ...DEFAULT_SETTINGS,+ agent_settings: {+ ...DEFAULT_SETTINGS.agent_settings,+ agent_context: {+ system_message_suffix: "MARKER-GLOBAL-RULES",+ },+ },+ },+ query: "hello",+ runtimeServicesInfo: {+ mode: "dev:automation",+ services: {+ agent_server: { url_from_agent: "http://localhost:18000" },+ automation: {+ url_from_agent: "http://localhost:18001",+ },+ },+ },+ }) as {+ agent_settings: { agent_context: Record<string, unknown> };+ };+ const suffix = payload.agent_settings.agent_context+ .system_message_suffix as string;+ expect(suffix).toMatch(/^MARKER-GLOBAL-RULES\n\n<RUNTIME_SERVICES>/);+ });++ it("keeps a saved suffix when no runtime services are advertised", () => {+ const payload = buildStartConversationRequest({+ settings: {+ ...DEFAULT_SETTINGS,+ agent_settings: {+ ...DEFAULT_SETTINGS.agent_settings,+ agent_context: { system_message_suffix: "MARKER-GLOBAL-RULES" },+ },+ },+ query: "hello",+ }) as { agent_settings: { agent_context: Record<string, unknown> } };++ expect(payload.agent_settings.agent_context.system_message_suffix).toBe(+ "MARKER-GLOBAL-RULES",+ );+ });++ it("omits the suffix when neither a saved suffix nor runtime services exist", () => {+ const payload = buildStartConversationRequest({+ settings: DEFAULT_SETTINGS,+ query: "hello",+ }) as { agent_settings: { agent_context: Record<string, unknown> } };++ expect(payload.agent_settings.agent_context).not.toHaveProperty(+ "system_message_suffix",+ );+ });++ it("combines saved and runtime suffixes on the profile path", () => {+ const payload = buildStartConversationRequest({+ settings: {+ ...DEFAULT_SETTINGS,+ agent_settings: {+ ...DEFAULT_SETTINGS.agent_settings,+ agent_context: { system_message_suffix: "MARKER-GLOBAL-RULES" },+ },+ },+ query: "hello",+ agentProfileId: "profile-openhands",+ agentProfileKind: "openhands",+ runtimeServicesInfo: {+ mode: "dev:automation",+ services: {+ agent_server: { url_from_agent: "http://localhost:18000" },+ automation: { url_from_agent: "http://localhost:18001" },+ },+ },+ }) as {+ agent_profile_id?: string;+ agent_settings?: unknown;+ agent_launch_additions?: { system_message_suffix_append?: string };+ };++ expect(payload.agent_profile_id).toBe("profile-openhands");+ expect(payload.agent_settings).toBeUndefined();+ expect(+ payload.agent_launch_additions?.system_message_suffix_append,+ ).toMatch(/^MARKER-GLOBAL-RULES\n\n<RUNTIME_SERVICES>/);+ expect(+ payload.agent_launch_additions?.system_message_suffix_append,+ ).toContain("http://localhost:18001");+ });++ it("carries runtime services on the profile path", () => {const payload = buildStartConversationRequest({settings: DEFAULT_SETTINGS,query: "hello",@@ -1596,15 +1687,14 @@ describe("agent_settings runtime services suffix", () => {).toContain("<RUNTIME_SERVICES>");});- it("omits the additions entirely when there is no runtime services info", () => {- // A deployment without them must send no deployment context at all, not an- // empty string the server would append as a blank line.+ it("omits profile additions without a saved suffix or runtime services", () => {const payload = buildStartConversationRequest({settings: DEFAULT_SETTINGS,query: "hello",agentProfileId: "profile-openhands",agentProfileKind: "openhands",}) as { agent_launch_additions?: unknown };+expect(payload.agent_launch_additions).toBeUndefined();});});diff --git a/src/api/agent-server-adapter.test.ts b/src/api/agent-server-adapter.test.tsindex 3e2759c345..03781758f4 100644--- a/src/api/agent-server-adapter.test.ts+++ b/src/api/agent-server-adapter.test.ts@@ -712,6 +712,22 @@ describe("buildStartPlanningConversationRequestWithEncryptedSettings", () => {});describe("buildStartConversationRequest β agentProfileId path", () => {+ it("appends the saved global suffix to a profile launch", () => {+ const payload = buildStartConversationRequest({+ settings: makeSettings({+ agent_kind: "openhands",+ agent_context: { system_message_suffix: "MARKER-GLOBAL-RULES" },+ }),+ agentProfileId: "profile-xyz",+ agentProfileKind: "openhands",+ });++ expect(payload.agent_launch_additions).toEqual({+ system_message_suffix_append: "MARKER-GLOBAL-RULES",+ });+ expect(payload.agent_settings).toBeUndefined();+ });+it("sends agent_profile_id and omits agent_settings (mutually exclusive)", () => {const settings = makeSettings({agent_kind: "openhands",@@ -726,6 +742,7 @@ describe("buildStartConversationRequest β agentProfileId path", () => {expect(payload.agent_profile_id).toBe("profile-xyz");expect(payload.agent_settings).toBeUndefined();+ expect(payload.agent_launch_additions).toBeUndefined();expect(payload.client_tools.map((tool) => tool.name)).toEqual([CANVAS_UI_CLIENT_TOOL_NAME,LAUNCH_CHILD_CONVERSATION_TOOL_NAME,diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.tsindex 59a7514819..fa1140d93e 100644--- a/src/api/agent-server-adapter.ts+++ b/src/api/agent-server-adapter.ts@@ -915,7 +915,13 @@ function buildAgentContext(disabled_skills: disabledSkills,...(runtimeServicesSuffix || routerAtStartSuffix? {- system_message_suffix: [runtimeServicesSuffix, routerAtStartSuffix]+ system_message_suffix: [+ typeof existingContext.system_message_suffix === "string"+ ? existingContext.system_message_suffix+ : undefined,+ runtimeServicesSuffix,+ routerAtStartSuffix,+ ].filter((s): s is string => Boolean(s)).join("\n\n"),}@@ -1271,11 +1277,17 @@ export function buildStartConversationRequest(options.query,options.hasActiveMetaProfile,);- // The router-at-start instruction stays inline-only: a profile-resolved- // agent has no ``route_task_to_model`` tool to act on it.- const profileLaunchSuffix = buildRuntimeServicesSystemSuffix(- options.runtimeServicesInfo,- );+ const savedSuffix = toRecord(+ toRecord(sourceAgentSettings.agent_settings).agent_context,+ ).system_message_suffix;+ // Router-at-start stays inline-only because profile-resolved agents do not+ // have the route_task_to_model tool.+ const profileLaunchSuffix = [+ typeof savedSuffix === "string" ? savedSuffix : undefined,+ buildRuntimeServicesSystemSuffix(options.runtimeServicesInfo),+ ]+ .filter((suffix): suffix is string => Boolean(suffix))+ .join("\n\n");const acpServerTag = acpMode? getAcpServerTag(sourceAgentSettings): undefined;@@ -1309,8 +1321,9 @@ export function buildStartConversationRequest(// Finish/Think). The Canvas UI tool is a top-level client tool and// therefore works on both inline-agent and profile launch paths.//- // ``RUNTIME_SERVICES`` (this stack's sandbox-facing URLs) only exists- // client-side, so the profile path sends it as ``agent_launch_additions``.+ // The saved global suffix and ``RUNTIME_SERVICES`` are not part of the+ // stored profile, so the profile path sends them as+ // ``agent_launch_additions``.//// Persistent memory is NOT on that boundary: ``load_memory`` is a global// user preference, so the agent-server stamps the stored