diff --git a/backend/open_webui/tools/builtin.py b/backend/open_webui/tools/builtin.py index bc2ed83791..28b212fe88 100644 --- a/backend/open_webui/tools/builtin.py +++ b/backend/open_webui/tools/builtin.py @@ -1910,6 +1910,7 @@ async def view_chat( async def delegate_task( task: str, + title: str = '', context: str = '', file_ids: list[str] | None = None, background: bool = False, @@ -1924,6 +1925,7 @@ async def delegate_task( Delegate focused work to a parallel sub-agent using the current tools. :param task: The specific task for the sub-agent to complete + :param title: A short name for the task, 3 to 6 words :param context: Relevant context, decisions, or file paths for the task :param file_ids: Attached file IDs the sub-agent needs. Use this for images or files; do not put file IDs only in context. @@ -1942,6 +1944,7 @@ async def delegate_task( task, context, background, + title=title, file_ids=file_ids, model_id=model_id, request=__request__, diff --git a/backend/open_webui/utils/subagents.py b/backend/open_webui/utils/subagents.py index e0174fcb10..5325bbeb33 100644 --- a/backend/open_webui/utils/subagents.py +++ b/backend/open_webui/utils/subagents.py @@ -491,6 +491,7 @@ async def delegate( context: str, background: bool, *, + title: str = '', file_ids: list[str] | None = None, model_id: str | None = None, request: Request, @@ -504,6 +505,7 @@ async def delegate( task = task.strip() if not task: return 'Error: task must not be empty.' + title = ' '.join((title or '').split() or task.split())[:60] if not parent_chat_id or not user_data.get('id'): return 'Error: chat and user context are required.' @@ -645,7 +647,7 @@ async def delegate( ChatForm( chat={ 'id': chat_id, - 'title': f'Sub-agent: {task[:60]}', + 'title': title, 'models': [model_id], 'machine_id': machine_id_of(run), # Read when the user's answer or message continues this chat. @@ -836,6 +838,7 @@ async def delegate( 'to use the result or continue without it.' ), '', + f'Title: {title}', f'Original task: {task}', ] if context: diff --git a/src/lib/components/chat/Messages/SubagentResultRow.svelte b/src/lib/components/chat/Messages/SubagentResultRow.svelte index a26fa1d131..a7d0a93073 100644 --- a/src/lib/components/chat/Messages/SubagentResultRow.svelte +++ b/src/lib/components/chat/Messages/SubagentResultRow.svelte @@ -21,7 +21,7 @@ const [head, ...result] = report.split('--- RESULT ---'); const field = (pattern: RegExp) => head.match(pattern)?.[1]?.trim() ?? ''; return { - task: field(/^Original task: (.*)$/m), + title: field(/^Title: (.*)\nOriginal task: /m) || field(/^Original task: (.*)$/m), chatId: field(/^Subagent chat: (.*)$/m), status: field(/^Status: (\S+)/m), duration: field(/Duration: (\S+)/), @@ -44,7 +44,7 @@ aria-expanded={!!expanded[index]} on:click={() => (expanded[index] = !expanded[index])} > - {label(report.status)} · {report.task} + {label(report.status)} · {report.title} {report.duration} - appLayout?.openPageTab?.({ href: `/c/${report.chatId}`, label: report.task })} + appLayout?.openPageTab?.({ href: `/c/${report.chatId}`, label: report.title })} > {$i18n.t('Open thread')} diff --git a/src/lib/components/chat/Messages/structuredOutput.ts b/src/lib/components/chat/Messages/structuredOutput.ts index 22ac90887c..18d173d042 100644 --- a/src/lib/components/chat/Messages/structuredOutput.ts +++ b/src/lib/components/chat/Messages/structuredOutput.ts @@ -238,9 +238,7 @@ export function buildToolCallToken( typeof item.arguments === 'string' ? JSON.parse(item.arguments || '{}') : (item.arguments ?? {}); - const task = typeof args.task === 'string' && args.task ? args.task : '?'; - const label = args.background ? 'Background sub-agent' : 'Sub-agent'; - name = `${label}: "${task.length > 60 ? `${task.slice(0, 60)}...` : task}"`; + name = String(args.title || args.task || 'Sub-agent').slice(0, 60); } catch { name = 'Sub-agent'; }