Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
feat(ui): display exceeding max iteration alert in chat page (#2381)
DavdGaoad4d2839e8ad
diff --git a/examples/web_ui/frontend/src/components/chat/ASMessageBubble.tsx b/examples/web_ui/frontend/src/components/chat/ASMessageBubble.tsxindex 3d08b86a4..3c8c43621 100644--- a/examples/web_ui/frontend/src/components/chat/ASMessageBubble.tsx+++ b/examples/web_ui/frontend/src/components/chat/ASMessageBubble.tsx@@ -410,14 +410,6 @@ export function ASMessageBubble({ message }: MessageBubbleProps) {const blocks = groupToolCalls(message.content);- // A fatal error terminated this reply. ``finished_reason`` / ``error`` are- // reply-level fields set by ``appendEvent`` on a ``REPLY_END`` with- // ``finished_reason === ReplyFinishedReason.ERROR`` — they are NOT content- // blocks, so the body above is always genuine agent output. Rendered as a- // separate alert below the body.- const errorInfo = message.error;- const isError = message.finished_reason === ReplyFinishedReason.ERROR || !!errorInfo;-const startMs = new Date(message.created_at).getTime();const endMs = isRunning ? now : new Date(message.finished_at!).getTime();const elapsedSeconds = Math.max(0, (endMs - startMs) / 1000);@@ -435,7 +427,7 @@ export function ASMessageBubble({ message }: MessageBubbleProps) {</BubbleContent></Bubble>))}- {isError && (+ {message.finished_reason === ReplyFinishedReason.ERROR && (<Alertvariant="destructive"className="m-2 w-[calc(100%-1rem)] border-red-200 bg-red-50 text-destructive dark:border-red-900 dark:bg-red-950 dark:text-red-50"@@ -443,9 +435,9 @@ export function ASMessageBubble({ message }: MessageBubbleProps) {<TriangleAlert /><AlertTitle>{t('messageBubble.error.title')}</AlertTitle><AlertDescription>- {t(`messageBubble.error.${errorInfo?.type ?? 'unknown'}`, {+ {t(`messageBubble.error.${message.error?.type ?? 'unknown'}`, {defaultValue:- errorInfo?.message ?? t('messageBubble.error.unknown'),+ message.error?.message ?? t('messageBubble.error.unknown'),})}</AlertDescription></Alert>diff --git a/examples/web_ui/frontend/src/components/chat/ChatContent.tsx b/examples/web_ui/frontend/src/components/chat/ChatContent.tsxindex 4ed92bc4d..3aeedf083 100644--- a/examples/web_ui/frontend/src/components/chat/ChatContent.tsx+++ b/examples/web_ui/frontend/src/components/chat/ChatContent.tsx@@ -1,10 +1,12 @@+import { ReplyFinishedReason } from '@agentscope-ai/agentscope/event';import {type ContentBlock,getContentBlocks,type Msg,+ type TextBlock,type ToolCallBlock,} from '@agentscope-ai/agentscope/message';-import { GitBranch } from 'lucide-react';+import { GitBranch, TriangleAlert } from 'lucide-react';import React, { useEffect, useMemo, useState } from 'react';import { Button } from '../ui/button';@@ -15,6 +17,7 @@ import { ConfirmCard } from '@/components/chat/ConfirmCard.tsx';import { FlipCard } from '@/components/chat/FlipCard.tsx';import { TextInput } from '@/components/chat/TextInput.tsx';import { WorkingDirectoryDialog } from '@/components/dialog/WorkingDirectoryDialog';+import { Alert, AlertAction, AlertDescription, AlertTitle } from '@/components/ui/alert.tsx';import {MessageScroller,MessageScrollerButton,@@ -164,6 +167,45 @@ const ChatContentComponent: React.FC<ChatContentProps> = ({/></MessageScrollerItem>))}+ {msgs.length > 0 &&+ msgs[msgs.length - 1].finished_reason ===+ ReplyFinishedReason.EXCEED_MAX_ITERS &&+ phase === 'idle' && (+ <Alert+ variant={'default'}+ className="border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-50"+ >+ <TriangleAlert />+ <AlertTitle>+ {t('chat.maxItersExceeded.title')}+ </AlertTitle>+ <AlertDescription>+ {t('chat.maxItersExceeded.description')}+ </AlertDescription>+ <AlertAction>+ <Button+ size={'xs'}+ onClick={() => {+ onSend([+ {+ id: crypto.randomUUID(),+ type: 'text',+ text: t(+ 'chat.maxItersExceeded.continue',+ ),+ created_at:+ new Date().toISOString(),+ finished_at:+ new Date().toISOString(),+ } as TextBlock,+ ]);+ }}+ >+ {t('chat.maxItersExceeded.continue')}+ </Button>+ </AlertAction>+ </Alert>+ )}</MessageScrollerContent></MessageScrollerViewport><MessageScrollerButton className="rounded-full" />diff --git a/examples/web_ui/frontend/src/i18n/locales/en.json b/examples/web_ui/frontend/src/i18n/locales/en.jsonindex dc2d9423e..939641c7b 100644--- a/examples/web_ui/frontend/src/i18n/locales/en.json+++ b/examples/web_ui/frontend/src/i18n/locales/en.json@@ -140,6 +140,11 @@"subagentConfirmTitle": "{{name}} requests confirmation","newSession": "New Session","greeting": "Where should we start?",+ "maxItersExceeded": {+ "title": "Reached the iteration limit",+ "description": "Send a new message to keep going, or continue the current task.",+ "continue": "Continue"+ },"agent": {"selectPlaceholder": "Select an agent","emptyTitle": "No agents",diff --git a/examples/web_ui/frontend/src/i18n/locales/zh.json b/examples/web_ui/frontend/src/i18n/locales/zh.jsonindex 62926125d..2c9ceb301 100644--- a/examples/web_ui/frontend/src/i18n/locales/zh.json+++ b/examples/web_ui/frontend/src/i18n/locales/zh.json@@ -140,6 +140,11 @@"subagentConfirmTitle": "{{name}} 请求确认","newSession": "新会话","greeting": "我们从哪儿开始?",+ "maxItersExceeded": {+ "title": "已达到最大迭代次数",+ "description": "输入新消息可继续对话,或点击继续以完成当前任务。",+ "continue": "继续"+ },"agent": {"selectPlaceholder": "选择智能体","emptyTitle": "暂无智能体",