From 613c53c70cf811b17de93791e6bad1d9267935fd Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 23 Jul 2025 12:16:36 +0700 Subject: [PATCH 1/2] fix: default Jan assistant prompt --- extensions/assistant-extension/src/index.ts | 2 +- web-app/src/hooks/useAssistant.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/assistant-extension/src/index.ts b/extensions/assistant-extension/src/index.ts index a0bbe71f1f..f50a4c2024 100644 --- a/extensions/assistant-extension/src/index.ts +++ b/extensions/assistant-extension/src/index.ts @@ -75,7 +75,7 @@ export default class JanAssistantExtension extends AssistantExtension { 'Jan is a helpful desktop assistant that can reason through complex tasks and use tools to complete them on the user’s behalf.', model: '*', instructions: - 'You have access to a set of tools to help you answer the user’s question. You can use only one tool per message, and you’ll receive the result of that tool in the user’s next response. To complete a task, use tools step by step—each step should be guided by the outcome of the previous one.\nTool Usage Rules:\n1. Always provide the correct values as arguments when using tools. Do not pass variable names—use actual values instead.\n2. You may perform multiple tool steps to complete a task.\n3. Avoid repeating a tool call with exactly the same parameters to prevent infinite loops.', + 'You are a helpful AI assistant. Your primary goal is to assist users with their questions and tasks to the best of your abilities.\n\nWhen responding:\n- Answer directly from your knowledge when you can\n- Be concise, clear, and helpful\n- Admit when you’re unsure rather than making things up\n\nIf tools are available to you:\n- Only use tools when they add real value to your response\n- Use tools when the user explicitly asks (e.g., "search for...", "calculate...", "run this code")\n- Use tools for information you don’t know or that needs verification\n- Never use tools just because they’re available\n\nWhen using tools:\n- Use one tool at a time and wait for results\n- Use actual values as arguments, not variable names\n- Learn from each result before deciding next steps\n- Avoid repeating the same tool call with identical parameters\n\nRemember: Most questions can be answered without tools. Think first whether you need them.', tools: [ { type: 'retrieval', diff --git a/web-app/src/hooks/useAssistant.ts b/web-app/src/hooks/useAssistant.ts index 1c31812765..1813a9c7b1 100644 --- a/web-app/src/hooks/useAssistant.ts +++ b/web-app/src/hooks/useAssistant.ts @@ -21,7 +21,7 @@ export const defaultAssistant: Assistant = { description: 'Jan is a helpful desktop assistant that can reason through complex tasks and use tools to complete them on the user’s behalf.', instructions: - 'You have access to a set of tools to help you answer the user’s question. You can use only one tool per message, and you’ll receive the result of that tool in the user’s next response. To complete a task, use tools step by step—each step should be guided by the outcome of the previous one.\nTool Usage Rules:\n1. Always provide the correct values as arguments when using tools. Do not pass variable names—use actual values instead.\n2. You may perform multiple tool steps to complete a task.\n3. Avoid repeating a tool call with exactly the same parameters to prevent infinite loops.', + 'You are a helpful AI assistant. Your primary goal is to assist users with their questions and tasks to the best of your abilities.\n\nWhen responding:\n- Answer directly from your knowledge when you can\n- Be concise, clear, and helpful\n- Admit when you’re unsure rather than making things up\n\nIf tools are available to you:\n- Only use tools when they add real value to your response\n- Use tools when the user explicitly asks (e.g., "search for...", "calculate...", "run this code")\n- Use tools for information you don’t know or that needs verification\n- Never use tools just because they’re available\n\nWhen using tools:\n- Use one tool at a time and wait for results\n- Use actual values as arguments, not variable names\n- Learn from each result before deciding next steps\n- Avoid repeating the same tool call with identical parameters\n\nRemember: Most questions can be answered without tools. Think first whether you need them.', } export const useAssistant = create()((set, get) => ({ From 02afdafe066ed2eca05ef6c4dcd2ec7ec75c1b52 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 23 Jul 2025 12:42:20 +0700 Subject: [PATCH 2/2] test: update tests --- .../src/hooks/__tests__/useAssistant.test.ts | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/web-app/src/hooks/__tests__/useAssistant.test.ts b/web-app/src/hooks/__tests__/useAssistant.test.ts index 1425efbb0d..aeb8375a07 100644 --- a/web-app/src/hooks/__tests__/useAssistant.test.ts +++ b/web-app/src/hooks/__tests__/useAssistant.test.ts @@ -22,14 +22,14 @@ describe('useAssistant', () => { it('should initialize with default state', () => { const { result } = renderHook(() => useAssistant()) - + expect(result.current.assistants).toEqual([defaultAssistant]) expect(result.current.currentAssistant).toEqual(defaultAssistant) }) it('should add assistant', () => { const { result } = renderHook(() => useAssistant()) - + const newAssistant = { id: 'assistant-2', name: 'New Assistant', @@ -37,37 +37,37 @@ describe('useAssistant', () => { description: 'A new assistant', instructions: 'Help the user', created_at: Date.now(), - parameters: {} + parameters: {}, } - + act(() => { result.current.addAssistant(newAssistant) }) - + expect(result.current.assistants).toHaveLength(2) expect(result.current.assistants).toContain(newAssistant) }) it('should update assistant', () => { const { result } = renderHook(() => useAssistant()) - + const updatedAssistant = { ...defaultAssistant, name: 'Updated Jan', - description: 'Updated description' + description: 'Updated description', } - + act(() => { result.current.updateAssistant(updatedAssistant) }) - + expect(result.current.assistants[0].name).toBe('Updated Jan') expect(result.current.assistants[0].description).toBe('Updated description') }) it('should delete assistant', () => { const { result } = renderHook(() => useAssistant()) - + const assistant2 = { id: 'assistant-2', name: 'Assistant 2', @@ -75,26 +75,26 @@ describe('useAssistant', () => { description: 'Second assistant', instructions: 'Help the user', created_at: Date.now(), - parameters: {} + parameters: {}, } - + act(() => { result.current.addAssistant(assistant2) }) - + expect(result.current.assistants).toHaveLength(2) - + act(() => { result.current.deleteAssistant('assistant-2') }) - + expect(result.current.assistants).toHaveLength(1) expect(result.current.assistants[0].id).toBe('jan') }) it('should set current assistant', () => { const { result } = renderHook(() => useAssistant()) - + const newAssistant = { id: 'assistant-2', name: 'New Current Assistant', @@ -102,19 +102,19 @@ describe('useAssistant', () => { description: 'New current assistant', instructions: 'Help the user', created_at: Date.now(), - parameters: {} + parameters: {}, } - + act(() => { result.current.setCurrentAssistant(newAssistant) }) - + expect(result.current.currentAssistant).toEqual(newAssistant) }) it('should set assistants', () => { const { result } = renderHook(() => useAssistant()) - + const assistants = [ { id: 'assistant-1', @@ -123,7 +123,7 @@ describe('useAssistant', () => { description: 'First assistant', instructions: 'Help the user', created_at: Date.now(), - parameters: {} + parameters: {}, }, { id: 'assistant-2', @@ -132,52 +132,56 @@ describe('useAssistant', () => { description: 'Second assistant', instructions: 'Help with tasks', created_at: Date.now(), - parameters: {} - } + parameters: {}, + }, ] - + act(() => { result.current.setAssistants(assistants) }) - + expect(result.current.assistants).toEqual(assistants) expect(result.current.assistants).toHaveLength(2) }) it('should maintain assistant structure', () => { const { result } = renderHook(() => useAssistant()) - + expect(result.current.currentAssistant.id).toBe('jan') expect(result.current.currentAssistant.name).toBe('Jan') expect(result.current.currentAssistant.avatar).toBe('👋') - expect(result.current.currentAssistant.description).toContain('helpful desktop assistant') - expect(result.current.currentAssistant.instructions).toContain('access to a set of tools') + expect(result.current.currentAssistant.description).toContain( + 'helpful desktop assistant' + ) + expect(result.current.currentAssistant.instructions).toContain( + 'Only use tools when they add real value to your response' + ) expect(typeof result.current.currentAssistant.created_at).toBe('number') expect(typeof result.current.currentAssistant.parameters).toBe('object') }) it('should handle empty assistants list', () => { const { result } = renderHook(() => useAssistant()) - + act(() => { result.current.setAssistants([]) }) - + expect(result.current.assistants).toEqual([]) }) it('should update assistant in current assistant if it matches', () => { const { result } = renderHook(() => useAssistant()) - + const updatedDefaultAssistant = { ...defaultAssistant, - name: 'Updated Jan Name' + name: 'Updated Jan Name', } - + act(() => { result.current.updateAssistant(updatedDefaultAssistant) }) - + expect(result.current.currentAssistant.name).toBe('Updated Jan Name') }) -}) \ No newline at end of file +})