Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: title generation uses the same LLM as the running agent profile (#16886)

Juan Pedro Michelini Jorgec6b47798ed9a
diff --git a/__tests__/api/agent-server-conversation-service.test.ts b/__tests__/api/agent-server-conversation-service.test.ts
index 4fc4c77441..56f5c86afa 100644
--- a/__tests__/api/agent-server-conversation-service.test.ts
+++ b/__tests__/api/agent-server-conversation-service.test.ts
@@ -47,6 +47,7 @@ const {
mockGetSettingsForConversation,
mockGetProfile,
mockActivateProfile,
+ mockListProfiles,
} = vi.hoisted(() => ({
mockHttpGet: vi.fn(),
mockHttpPost: vi.fn(),
@@ -69,6 +70,7 @@ const {
mockGetSettingsForConversation: vi.fn(),
mockGetProfile: vi.fn(),
mockActivateProfile: vi.fn(),
+ mockListProfiles: vi.fn(),
}));
vi.mock("@openhands/typescript-client/clients", async () => {
@@ -87,6 +89,7 @@ vi.mock("@openhands/typescript-client/clients", async () => {
return {
getProfile: mockGetProfile,
activateProfile: mockActivateProfile,
+ listProfiles: mockListProfiles,
};
}),
SettingsClient: vi.fn(function SettingsClientMock() {
@@ -216,6 +219,7 @@ describe("AgentServerConversationService", () => {
mockHttpDelete.mockReset();
mockGetProfile.mockReset();
mockActivateProfile.mockReset();
+ mockListProfiles.mockReset();
mockSwitchProfile.mockReset();
mockSwitchLLM.mockReset();
mockSendEvent.mockReset();
@@ -553,6 +557,146 @@ describe("AgentServerConversationService", () => {
});
describe("createConversation", () => {
+ // #16885 β€” A named agent profile's pinned LLM (llm_profile_ref) must reach
+ // the agent-server as `title_llm_profile` when no explicit preference is
+ // set, so the title uses the same model as the running agent. These cover
+ // the conversation-creation integration criterion at the service boundary
+ // (the POST /api/conversations payload), not just the resolver.
+ it("sends the agent profile's pinned LLM as title_llm_profile when no explicit preference is set", async () => {
+ mockGetSettings.mockResolvedValue({
+ title_llm_profile: null,
+ agent_settings: { llm: { model: "gpt-4o" } },
+ conversation_settings: {},
+ });
+ mockGetSettingsForConversation.mockResolvedValue({
+ agentSettings: { llm: { model: "gpt-4o" } },
+ conversationSettings: {},
+ secretsEncrypted: true,
+ });
+ mockListProfiles.mockResolvedValue({
+ profiles: [
+ {
+ name: "fast",
+ model: "anthropic/claude-haiku",
+ base_url: null,
+ api_key_set: true,
+ },
+ {
+ name: "powerful",
+ model: "anthropic/claude-sonnet",
+ base_url: null,
+ api_key_set: true,
+ },
+ ],
+ active_profile: "fast",
+ });
+ mockHttpPost.mockResolvedValue({
+ data: {
+ id: "ignored-server-id",
+ created_at: "2024-01-01",
+ updated_at: "2024-01-01",
+ },
+ });
+
+ await AgentServerConversationService.createConversation({
+ agentLlmProfileRef: "powerful",
+ });
+
+ expect(mockHttpPost).toHaveBeenCalledWith(
+ "/api/conversations",
+ expect.objectContaining({ title_llm_profile: "powerful" }),
+ );
+ });
+
+ it("keeps an explicit title_llm_profile preference over the agent profile's pinned LLM", async () => {
+ mockGetSettings.mockResolvedValue({
+ title_llm_profile: "Titles",
+ agent_settings: { llm: { model: "gpt-4o" } },
+ conversation_settings: {},
+ });
+ mockGetSettingsForConversation.mockResolvedValue({
+ agentSettings: { llm: { model: "gpt-4o" } },
+ conversationSettings: {},
+ secretsEncrypted: true,
+ });
+ mockListProfiles.mockResolvedValue({
+ profiles: [
+ {
+ name: "Titles",
+ model: "anthropic/claude-haiku-3-5",
+ base_url: null,
+ api_key_set: true,
+ },
+ {
+ name: "powerful",
+ model: "anthropic/claude-sonnet",
+ base_url: null,
+ api_key_set: true,
+ },
+ ],
+ active_profile: "powerful",
+ });
+ mockHttpPost.mockResolvedValue({
+ data: {
+ id: "ignored-server-id",
+ created_at: "2024-01-01",
+ updated_at: "2024-01-01",
+ },
+ });
+
+ await AgentServerConversationService.createConversation({
+ agentLlmProfileRef: "powerful",
+ });
+
+ expect(mockHttpPost).toHaveBeenCalledWith(
+ "/api/conversations",
+ expect.objectContaining({ title_llm_profile: "Titles" }),
+ );
+ });
+
+ it("falls back to the active profile when the agent profile's pinned LLM is no longer available", async () => {
+ mockGetSettings.mockResolvedValue({
+ title_llm_profile: null,
+ agent_settings: { llm: { model: "gpt-4o" } },
+ conversation_settings: {},
+ });
+ mockGetSettingsForConversation.mockResolvedValue({
+ agentSettings: { llm: { model: "gpt-4o" } },
+ conversationSettings: {},
+ secretsEncrypted: true,
+ });
+ mockListProfiles.mockResolvedValue({
+ profiles: [
+ {
+ name: "fast",
+ model: "anthropic/claude-haiku",
+ base_url: null,
+ api_key_set: true,
+ },
+ ],
+ active_profile: "fast",
+ });
+ mockHttpPost.mockResolvedValue({
+ data: {
+ id: "ignored-server-id",
+ created_at: "2024-01-01",
+ updated_at: "2024-01-01",
+ },
+ });
+
+ // "powerful" was deleted since the profile was saved, so the resolver
+ // must degrade to the account-wide active profile instead of sending an
+ // unresolvable name.
+ await AgentServerConversationService.createConversation({
+ agentLlmProfileRef: "powerful",
+ });
+
+ expect(mockHttpPost).toHaveBeenCalledWith(
+ "/api/conversations",
+ expect.objectContaining({ title_llm_profile: "fast" }),
+ );
+ });
+
it("generates a unique conversation_id and isolated working_dir per call", async () => {
mockGetSettings.mockResolvedValue({
agent_settings: { llm: { model: "gpt-4o" } },
diff --git a/__tests__/utils/title-llm-profile.test.ts b/__tests__/utils/title-llm-profile.test.ts
index 5ac90f5f00..aa19107073 100644
--- a/__tests__/utils/title-llm-profile.test.ts
+++ b/__tests__/utils/title-llm-profile.test.ts
@@ -40,4 +40,24 @@ describe("resolveTitleLlmProfile", () => {
}),
).toBeUndefined();
});
+
+ describe("agentLlmProfileRef priority", () => {
+ it("uses agentLlmProfileRef when no explicit preference is set", () => {
+ expect(resolveTitleLlmProfile(null, profiles, "Titles")).toBe("Titles");
+ });
+
+ it("explicit preference takes priority over agentLlmProfileRef", () => {
+ expect(resolveTitleLlmProfile("Titles", profiles, "Default")).toBe(
+ "Titles",
+ );
+ });
+
+ it("falls back to active_profile when agentLlmProfileRef is not in the list", () => {
+ expect(resolveTitleLlmProfile(null, profiles, "Deleted")).toBe("Default");
+ });
+
+ it("ignores null agentLlmProfileRef and falls back to active_profile", () => {
+ expect(resolveTitleLlmProfile(null, profiles, null)).toBe("Default");
+ });
+ });
});
diff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.ts
index 7b51709ef4..ed3ede82d4 100644
--- a/src/api/conversation-service/agent-server-conversation-service.api.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts
@@ -391,6 +391,11 @@ export interface CreateConversationOptions {
// encrypted-settings builder; cloud sends it as a flat request field.
agentProfileId?: string;
agentProfileKind?: AgentKind;
+ // The LLM profile pinned to the launched agent profile (llm_profile_ref).
+ // When set and no explicit title_llm_profile preference exists, title
+ // generation uses this profile so both the agent and its title use the
+ // same model.
+ agentLlmProfileRef?: string | null;
}
class AgentServerConversationService {
@@ -446,6 +451,7 @@ class AgentServerConversationService {
sandboxId,
agentProfileId,
agentProfileKind,
+ agentLlmProfileRef,
} = options;
if (getActiveBackend().backend.kind === "cloud") {
@@ -484,6 +490,7 @@ class AgentServerConversationService {
const titleLlmProfile = resolveTitleLlmProfile(
settings.title_llm_profile,
profiles,
+ agentLlmProfileRef,
);
const conversationId = uuidv4();
const { workingDir, hooksProjectDir, isolated } =
diff --git a/src/hooks/mutation/use-create-conversation.ts b/src/hooks/mutation/use-create-conversation.ts
index 225cd0227d..429ea21596 100644
--- a/src/hooks/mutation/use-create-conversation.ts
+++ b/src/hooks/mutation/use-create-conversation.ts
@@ -270,6 +270,9 @@ export const useCreateConversation = () => {
? {
agentProfileId: effectiveAgentProfileId,
agentProfileKind: resolvedAgentProfile?.agent_kind,
+ // Let title generation use the same LLM as the agent profile
+ // so the title and the agent steps share a model (#16885).
+ agentLlmProfileRef: resolvedAgentProfile?.llm_profile_ref,
}
: {}),
});
diff --git a/src/utils/title-llm-profile.ts b/src/utils/title-llm-profile.ts
index e1cde92fec..6aac8fd65a 100644
--- a/src/utils/title-llm-profile.ts
+++ b/src/utils/title-llm-profile.ts
@@ -1,8 +1,19 @@
import type { ProfileListResponse } from "#/api/profiles-service/profiles-service.api";
+/**
+ * Resolve which LLM profile should generate the conversation title.
+ *
+ * Priority:
+ * 1. `preference` β€” the user's explicit `title_llm_profile` setting.
+ * 2. `agentLlmProfileRef` β€” the LLM pinned to the running agent profile,
+ * so title generation uses the same model as the agent when no explicit
+ * preference is set.
+ * 3. `profiles.active_profile` β€” account-wide fallback.
+ */
export function resolveTitleLlmProfile(
preference: string | null | undefined,
profiles: ProfileListResponse | undefined,
+ agentLlmProfileRef?: string | null,
): string | undefined {
if (!profiles) return undefined;
@@ -12,6 +23,9 @@ export function resolveTitleLlmProfile(
if (preference && availableProfiles.has(preference)) {
return preference;
}
+ if (agentLlmProfileRef && availableProfiles.has(agentLlmProfileRef)) {
+ return agentLlmProfileRef;
+ }
if (
profiles.active_profile &&
availableProfiles.has(profiles.active_profile)