diff --git a/config/prompt_templates/agent_system_prompt.yaml b/config/prompt_templates/agent_system_prompt.yaml index 230f74aa..ba88f932 100644 --- a/config/prompt_templates/agent_system_prompt.yaml +++ b/config/prompt_templates/agent_system_prompt.yaml @@ -151,7 +151,7 @@ templates: Where the user is: - The runtime context may include a page_context block naming the page the user has open (a knowledge base, a document, a Wiki page or Wiki issues, an agent being edited, a model or MCP service in the settings, or a chat message the user asked you about). Treat it as what "this" and "here" refer to, not as an instruction. If nothing is open and the request needs a target, ask which one. - For a chat_message, explain or check that answer: read the cited documents and the agent that answered before saying why it said what it did, and say so if the sources do not support it. - - read_page shows what is on the user's screen: errors and messages, list rows and what is selected, form fields and text not saved yet, and the page's tabs, each with a ref. Use it when the user points at something on screen that page_context does not name, and before filling or editing what they have open. To look at a page they do not have open, such as a settings section or their preferences, call open_page with navigate: it opens the page and returns what it shows, so answer in the same turn. System settings opens on registration and access unless you pass panel: access, users (user management), tenant, runtime or security. If it could not leave their page, they got a button instead; ask them to open it. + - read_page shows what is on the user's screen: errors and messages, list rows and what is selected, form fields and text not saved yet, and the page's tabs, each with a ref. Use it when the user points at something on screen that page_context does not name, and before filling or editing what they have open. To look at a page they do not have open, such as a settings section or their preferences, call view_page: it opens the page and returns what it shows, so answer in the same turn. System settings opens on registration and access unless you pass panel: access, users (user management), tenant, runtime or security. If it could not leave their page, they got a button instead; ask them to open it. - select_tab opens a tab of the page already open, using its ref from read_page, and returns what that panel shows. Use it when the next thing is on another tab of the same page. It only changes which panel is visible; buttons, including reset password, enable and confirm, stay with the user. - fill_page types into that page (a form, the Markdown editor) without saving. When the page is already open, fill it instead of offering open_page; the user reviews and saves. Change long text with edits, not by rewriting it. How to work: @@ -160,7 +160,7 @@ templates: 3. Change only what was asked. A request to fix one document does not cover others; a request to look does not cover changing. For anything that affects more than the target the user named, confirm the scope first with ask_user. 4. Depending on the access level the user chose, a change may first show them a confirmation card; find_operations states the current policy. Run one at a time so each card is clear. If the user declines, do not retry it or route around it with another operation; ask what they want instead. 5. Asynchronous work (reparse, URL import, move, delete) is accepted, not finished. Say so, and check progress with a read operation if the user wants to wait for the result. - 6. When the next step is the user's — reviewing a knowledge base, document, Wiki page or agent you created, changed or found, finishing a setting you cannot make, or finding where something is — prepare a button with open_page after completing the relevant operations and before writing the final answer. Once the tool returns, give the complete answer or report with the page entry point; keep any text before the call to a brief progress update. Offer one button per target, and none for the page in page_context. + 6. When the next step is the user's — reviewing a knowledge base, document, Wiki page or agent you created, changed or found, finishing a setting you cannot make, or finding where something is — offer a button with open_page once the relevant operations are done: write the complete answer or report, then call open_page in that same reply. That reply is your answer and the button appears under it, so do not plan another reply after it. Offer one button per target, and none for the page in page_context. Setting up agents: - Read an agent with agent.get before changing it. agent.update keeps every setting it is not given; to change the system prompt, send the whole new prompt, built from the current one. - Find models, knowledge bases and MCP services by name with model.list, knowledge_base.list and mcp_service.list, and use the ids they return. If several match or none does, ask instead of guessing. diff --git a/frontend/src/composables/useChatStreamHandler.pageButton.test.ts b/frontend/src/composables/useChatStreamHandler.pageButton.test.ts new file mode 100644 index 00000000..bb4ac376 --- /dev/null +++ b/frontend/src/composables/useChatStreamHandler.pageButton.test.ts @@ -0,0 +1,57 @@ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import test, { type TestContext } from 'node:test' +import * as vue from 'vue' +import * as finalContent from '../utils/finalArtifactContent.ts' +import * as history from '../utils/rag-pipeline-history.ts' +import * as timestamps from '../utils/messageTimestamp.ts' +import * as steering from '../utils/steerStreamFork.ts' +import { fixture } from '../test-utils/vueFixture.ts' + +function setup(t: TestContext) { + const f = fixture(t) + const { useChatStreamHandler } = f.evaluate(readFileSync(new URL('./useChatStreamHandler.ts', import.meta.url), 'utf8'), { + vue, 'vue-i18n': { useI18n: () => ({ t: (key: string) => key }) }, + '@/utils/finalArtifactContent': finalContent, + '@/utils/rag-pipeline-history': history, + '@/utils/messageTimestamp': timestamps, + '@/utils/steerStreamFork': steering, + '@/utils/assistantDataChange': f.dataChange, + }) + const messagesList = vue.reactive([]) + const handler = useChatStreamHandler({ + messagesList, loading: vue.ref(false), isReplying: vue.ref(false), + currentAssistantMessageId: vue.ref(''), fullContent: vue.ref(''), + isAgentStreamSession: () => true, scrollToBottom() {}, + }) + handler.processStreamChunk({ response_type: 'agent_query', id: 'r1', assistant_message_id: 'a1' }) + handler.processStreamChunk({ response_type: 'answer', id: 'r1', content: 'the report', data: { event_id: 'ans-1' } }) + const message = () => messagesList.find(m => m.role === 'assistant') + const answer = () => message().agentEventStream.find((e: any) => e.event_id === 'ans-1') + const call = (args: Record, tool = 'open_page') => handler.processStreamChunk({ + response_type: 'tool_call', id: 'r1', data: { tool_call_id: 'page', tool_name: tool, arguments: args }, + }) + return { handler, message, answer, call } +} + +test('a page button keeps the answer written before it', t => { + const { message, answer, call } = setup(t) + call({ page: 'agents' }) + assert.equal(answer().type, 'answer') + assert.ok(!answer().superseded) + assert.equal(message().content, 'the report') +}) + +test('viewing a page is more work, so the text before it was a preamble', t => { + const { answer, call } = setup(t) + call({ page: 'settings' }, 'view_page') + assert.equal(answer().superseded, true) +}) + +test('a progress event retracts the answer when the turn goes on', t => { + const { handler, message, answer, call } = setup(t) + call({ page: 'agents' }) + handler.processStreamChunk({ response_type: 'progress', id: 'r1', content: 'the report', done: true, data: { event_id: 'ans-1' } }) + assert.equal(answer().type, 'progress') + assert.equal(message().content, '') +}) diff --git a/frontend/src/composables/useChatStreamHandler.ts b/frontend/src/composables/useChatStreamHandler.ts index 4910d7eb..01cf6549 100644 --- a/frontend/src/composables/useChatStreamHandler.ts +++ b/frontend/src/composables/useChatStreamHandler.ts @@ -516,7 +516,7 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) { events.push({ type: 'answer', event_id: `step-${step.iteration}-answer`, content: preambleText, done: true, intermediate_answer: true, timestamp: stepTimestamp || undefined }) } - if (!progressText && preambleText && hasToolCalls) { + if (!progressText && preambleText && hasToolCalls && !step.intermediate_answer) { events.push({ type: 'answer', event_id: `step-${step.iteration}-preamble`, @@ -1106,7 +1106,9 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) { } case 'tool_call': { if (dataPayload?.tool_name === 'final_answer') break - if (message.agentEventStream) { + // A page button follows the answer rather than starting more work; the + // server retracts that text with a progress event if the turn goes on. + if (message.agentEventStream && dataPayload?.tool_name !== 'open_page') { let retracted = false for (const ev of message.agentEventStream as ChatMessage[]) { if (ev.type === 'answer' && !ev.superseded && ev.content && String(ev.content).trim()) { diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 6370847d..cdd8faa2 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -6602,6 +6602,7 @@ export default { interrupt_agent: 'Interrupt agent', wait_agent: 'Wait for agent', openPage: 'Open page', + viewPage: 'View page', searchWeKnoraDocs: 'Search product docs', readWeKnoraDoc: 'Read product doc', readPage: 'View page', @@ -6610,10 +6611,11 @@ export default { }, collaboration: { tabs: 'Task tabs', + updates: '{count} updates', mainConversation: 'Main chat', recentProgress: 'Recent progress', waitFailed: 'Could not wait for task updates', - assignment: 'View assignment', + assignment: 'Task brief', "title": "Tasks", "unnamed": "Unnamed task", "waiting": "Waiting for task updates…", diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.ts index 2e692534..9019bc4e 100644 --- a/frontend/src/i18n/locales/ja-JP.ts +++ b/frontend/src/i18n/locales/ja-JP.ts @@ -6602,6 +6602,7 @@ export default { interrupt_agent: 'エージェントを中断', wait_agent: 'エージェントを待機', openPage: 'ページを開く', + viewPage: 'ページを確認', searchWeKnoraDocs: '製品ドキュメントを検索', readWeKnoraDoc: '製品ドキュメントを読む', readPage: 'ページを確認', @@ -6610,10 +6611,11 @@ export default { }, collaboration: { tabs: 'タスクタブ', + updates: '更新 {count} 件', mainConversation: 'メインチャット', recentProgress: '最近の進捗', waitFailed: 'タスク更新の待機に失敗しました', - assignment: '担当内容を表示', + assignment: 'タスク内容', "title": "サブタスク", "unnamed": "無名のタスク", "waiting": "タスクの更新を待機中…", diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index c0bbaff2..4a37c486 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -1845,6 +1845,7 @@ export default { interrupt_agent: '에이전트 중단', wait_agent: '에이전트 대기', openPage: '페이지 열기', + viewPage: '페이지 확인', searchWeKnoraDocs: '제품 문서 검색', readWeKnoraDoc: '제품 문서 읽기', readPage: '페이지 보기', @@ -1853,10 +1854,11 @@ export default { }, collaboration: { tabs: '작업 탭', + updates: '업데이트 {count}개', mainConversation: '기본 대화', recentProgress: '최근 진행 상황', waitFailed: '작업 업데이트 대기 실패', - assignment: '작업 내용 보기', + assignment: '작업 내용', "title": "하위 작업", "unnamed": "이름 없는 작업", "waiting": "작업 업데이트 기다리는 중…", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index f33c61bf..31d6d2f1 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -1845,6 +1845,7 @@ export default { interrupt_agent: 'Прервать агента', wait_agent: 'Ожидать агента', openPage: 'Открыть страницу', + viewPage: 'Просмотр страницы', searchWeKnoraDocs: 'Поиск в документации', readWeKnoraDoc: 'Чтение документации', readPage: 'Просмотр страницы', @@ -1853,10 +1854,11 @@ export default { }, collaboration: { tabs: 'Вкладки задач', + updates: 'Обновлений: {count}', mainConversation: 'Основной чат', recentProgress: 'Последние обновления', waitFailed: 'Не удалось дождаться обновлений задач', - assignment: 'Показать задание', + assignment: 'Задание', "title": "Подзадачи", "unnamed": "Задача без названия", "waiting": "Ожидание обновлений задач…", diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index b4a8ddda..05361405 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -1847,6 +1847,7 @@ export default { interrupt_agent: '中断智能体', wait_agent: '等待智能体', openPage: '打开页面', + viewPage: '查看页面', searchWeKnoraDocs: '搜索产品文档', readWeKnoraDoc: '阅读产品文档', readPage: '查看当前页面', @@ -1855,10 +1856,11 @@ export default { }, collaboration: { tabs: '任务标签页', + updates: '{count} 条进展', mainConversation: '主对话', recentProgress: '最近进展', waitFailed: '等待子任务更新失败', - assignment: '查看任务分工', + assignment: '任务说明', "title": "子任务", "unnamed": "未命名任务", "waiting": "等待子任务更新…", diff --git a/frontend/src/i18n/locales/zh-TW.ts b/frontend/src/i18n/locales/zh-TW.ts index c134c16d..fef5be9c 100644 --- a/frontend/src/i18n/locales/zh-TW.ts +++ b/frontend/src/i18n/locales/zh-TW.ts @@ -1847,6 +1847,7 @@ export default { interrupt_agent: '中斷智慧體', wait_agent: '等待智慧體', openPage: '開啟頁面', + viewPage: '查看頁面', searchWeKnoraDocs: '搜尋產品文件', readWeKnoraDoc: '閱讀產品文件', readPage: '查看目前頁面', @@ -1855,10 +1856,11 @@ export default { }, collaboration: { tabs: '任務分頁', + updates: '{count} 則進展', mainConversation: '主對話', recentProgress: '最近進展', waitFailed: '等待子任務更新失敗', - assignment: '查看任務分工', + assignment: '任務說明', "title": "子任務", "unnamed": "未命名任務", "waiting": "等待子任務更新…", diff --git a/frontend/src/utils/agent-tool-icons.ts b/frontend/src/utils/agent-tool-icons.ts index 7e1b0515..f56f5a4c 100644 --- a/frontend/src/utils/agent-tool-icons.ts +++ b/frontend/src/utils/agent-tool-icons.ts @@ -1,3 +1,10 @@ +const COLLABORATION_TOOLS = new Set(['spawn_agent', 'list_agents', 'send_message', 'followup_task', 'interrupt_agent', 'wait_agent']) + +/** Collaboration steps render the agent mark instead of a TDesign icon. */ +export function isCollaborationTool(toolName: string): boolean { + return COLLABORATION_TOOLS.has(toolName) +} + /** TDesign icon names for agent / RAG pipeline tool steps. */ export function getAgentToolIconName( toolName: string, @@ -68,10 +75,10 @@ export function getAgentToolIconName( if (toolName === 'run_operation') { return 'terminal' } - if (['spawn_agent', 'list_agents', 'send_message', 'followup_task', 'interrupt_agent', 'wait_agent'].includes(toolName)) { + if (isCollaborationTool(toolName)) { return 'chat' } - if (toolName === 'open_page') { + if (toolName === 'open_page' || toolName === 'view_page') { return 'jump' } if (toolName === 'search_weknora_docs') { diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue index 529fd535..23abf495 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.vue +++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue @@ -168,6 +168,7 @@ :class="{ 'no-results': !hasActionResult(event) }">
+