Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(goal): split goal creation from task creation and teach the concept on the empty state (#18047)

Arvin Xu86f6b2684af5
diff --git a/apps/server/src/services/verify/goalBudget.ts b/apps/server/src/services/verify/goalBudget.ts
index 1f62e8bbd64..494c668fa47 100644
--- a/apps/server/src/services/verify/goalBudget.ts
+++ b/apps/server/src/services/verify/goalBudget.ts
@@ -1,3 +1,4 @@
+import { DEFAULT_GOAL_MAX_ROUNDS } from '@lobechat/const/verify';
import type { TaskGoalConfig } from '@lobechat/types';
/**
@@ -11,8 +12,11 @@ import type { TaskGoalConfig } from '@lobechat/types';
* Applied when the user left the round budget untouched. `null` in the config
* means the user explicitly opted out of a cap — that maps to Infinity, not to
* this default.
+ *
+ * Re-exported from `@lobechat/const/verify` so the create-goal UI and this loop
+ * agree on one number; the const package is the single source of truth.
*/
-export const DEFAULT_GOAL_MAX_ROUNDS = 3;
+export { DEFAULT_GOAL_MAX_ROUNDS };
/** Round budget: `null` = user opted out of a cap, absent = default. */
export const resolveGoalRoundBudget = (goal: TaskGoalConfig): number => {
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index c73d1f069e8..13bc14944a2 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -216,6 +216,36 @@
"connectAgent.providerDesc.opencode": "Open-source coding agent CLI",
"connectAgent.providerDesc.pi": "Minimal coding agent CLI",
"connectAgent.providerDesc.qoder": "Qoder coding agent CLI",
+ "createGoal.addCriterion": "Add criterion",
+ "createGoal.back": "Back",
+ "createGoal.contextHint": "Add constraints, source material, or anything the Agent should know",
+ "createGoal.contextLabel": "Context for the Agent",
+ "createGoal.costBudgetHint": "Stops once total spend reaches this amount; leave blank for no cap.",
+ "createGoal.costBudgetLabel": "Cost budget",
+ "createGoal.costBudgetPlaceholder": "No cap",
+ "createGoal.createFailed": "Failed to create goal",
+ "createGoal.criteriaHint": "Review and edit these before the goal starts",
+ "createGoal.criteriaTitle": "What counts as done",
+ "createGoal.criterionPlaceholder": "Describe a result that can be clearly checked",
+ "createGoal.describeHint": "Describe the outcome first, then complete its execution plan.",
+ "createGoal.generateFailed": "Could not draft acceptance criteria. Try again.",
+ "createGoal.instructionPlaceholder": "Add any context the agent needs — scope, constraints, where to look…",
+ "createGoal.next": "Next",
+ "createGoal.preparing": "Preparing plan…",
+ "createGoal.regenerate": "Draft again",
+ "createGoal.removeCriterion": "Remove criterion",
+ "createGoal.requirementHint": "Judged at the end of every round",
+ "createGoal.requirementLabel": "What counts as done",
+ "createGoal.requirementPlaceholder": "Write it so it can be ticked off: what has to exist, where the boundary is, what makes it pass.",
+ "createGoal.reviewStep": "Step 2 of 2 · Complete the execution plan",
+ "createGoal.roundBudget.rounds": "{{count}} rounds",
+ "createGoal.roundBudget.uncapped": "No cap",
+ "createGoal.roundBudgetHint": "If it runs out without reaching the goal, it stops and waits for you.",
+ "createGoal.roundBudgetLabel": "Round budget",
+ "createGoal.roundBudgetUncappedHint": "It keeps going until the goal is reached — watch the cost.",
+ "createGoal.roundsUnit": "rounds",
+ "createGoal.submit": "Create goal",
+ "createGoal.titlePlaceholder": "The outcome you want",
"createModal.createBlank": "Start Blank",
"createModal.groupPlaceholder": "Describe what this Group should do...",
"createModal.groupTitle": "What should this Group do?",
@@ -343,10 +373,36 @@
"goalDetail.taskStatus": "Execution status",
"goalDetail.unnamedRun": "Untitled run",
"goalDetail.viewPlan": "View execution plan",
+ "goalEmpty.create": "Create your first goal",
+ "goalEmpty.examples.backlog.requirement": "Tag each item with a type and priority, dedupe into one table, and list the 10 most frequent issues.",
+ "goalEmpty.examples.backlog.tag": "One-off cleanup",
+ "goalEmpty.examples.backlog.title": "Turn this quarter's user feedback into one categorized table",
+ "goalEmpty.examples.digest.requirement": "At least 5 notable developments, each with a date, a one-line summary and a source link, compiled into a ready-to-read brief.",
+ "goalEmpty.examples.digest.tag": "Recurring delivery",
+ "goalEmpty.examples.digest.title": "Give me last week's AI industry highlights every Monday morning",
+ "goalEmpty.examples.metric.requirement": "At least 20 ideas, each with a headline, an angle and a target reader, deduped and excluding anything already published.",
+ "goalEmpty.examples.metric.tag": "Reach a target count",
+ "goalEmpty.examples.metric.title": "Build up 20 workable article ideas for the newsletter",
+ "goalEmpty.examples.requirementPrefix": "Done when: {{requirement}}",
+ "goalEmpty.examplesHint": "Click to prefill",
+ "goalEmpty.examplesTitle": "Start from an example",
+ "goalEmpty.howTitle": "What happens after you create one",
+ "goalEmpty.judge.bad": "“Keep an eye on competitors” — that is an activity, not an outcome. The agent can never tell when it is done.",
+ "goalEmpty.judge.good": "“Ship a weekly digest covering 5 named products, each with a source link” — a deliverable, a boundary, a verdict.",
+ "goalEmpty.lead": "Spell out the outcome you want and what counts as done. The agent takes it from there — working round after round, checking each attempt against your bar until it's actually met.",
+ "goalEmpty.loop": "Not passed? It carries this round’s verdict into the next one and keeps going, until the goal is reached or the round budget runs out. Rounds and cost stay visible, and you can pause at any time.",
+ "goalEmpty.step1.desc": "Write down the outcome and how it will be judged. The more checkable it is, the less the agent drifts.",
+ "goalEmpty.step1.title": "Set the outcome and the bar",
+ "goalEmpty.step2.desc": "Each round is one full agent run; its output, time and cost all hang off this goal.",
+ "goalEmpty.step2.title": "The agent runs a round on its own",
+ "goalEmpty.step3.desc": "Every check is judged one by one. All passed means achieved; anything needing your call stops at pending acceptance.",
+ "goalEmpty.step3.title": "Acceptance runs every round",
+ "goalEmpty.title": "Chase goals without limits",
"goalList.acceptanceProgress": "{{passed}}/{{total}} passed",
"goalList.agentRuns": "{{count}} runs",
"goalList.empty": "No goals yet",
- "goalList.loadError": "Could not load goals.",
+ "goalList.loadError": "Could not load goals",
+ "goalList.loadErrorDescription": "The service is temporarily unavailable. Your goals are not lost.",
"goalList.retry": "Retry",
"goalList.roundProgress": "Round {{current}}/{{total}}",
"goalList.status.achieved": "Achieved",
@@ -363,8 +419,6 @@
"goalPage.allGoals": "All goals",
"goalPage.create": "Create goal",
"goalPage.description": "Track what this agent is pursuing and how close each goal is to acceptance.",
- "goalPage.emptyDescription": "Goals created for this agent will appear here with their progress.",
- "goalPage.emptyTitle": "No goals yet",
"goalPage.filter.active": "In progress",
"goalPage.filter.all": "All",
"goalPage.filter.open": "Open goals",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index d43e5832709..66130e9a430 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -216,6 +216,36 @@
"connectAgent.providerDesc.opencode": "开源编码助理 CLI",
"connectAgent.providerDesc.pi": "轻量编码助理 CLI",
"connectAgent.providerDesc.qoder": "Qoder 编码助理 CLI",
+ "createGoal.addCriterion": "添加验收标准",
+ "createGoal.back": "返回",
+ "createGoal.contextHint": "补充约束、参考资料或 Agent 开始前需要知道的信息",
+ "createGoal.contextLabel": "给 Agent 的补充背景",
+ "createGoal.costBudgetHint": "累计花费达到这个金额就停下,留空表示不限。",
+ "createGoal.costBudgetLabel": "成本预算",
+ "createGoal.costBudgetPlaceholder": "不限",
+ "createGoal.createFailed": "创建目标失败",
+ "createGoal.criteriaHint": "目标开始前,你可以逐条检查和修改",
+ "createGoal.criteriaTitle": "什么算做到了",
+ "createGoal.criterionPlaceholder": "描述一个能够明确检查的结果",
+ "createGoal.describeHint": "先描述想要的结果,下一步再完善完整执行计划。",
+ "createGoal.generateFailed": "没能起草验收标准,请重试。",
+ "createGoal.instructionPlaceholder": "补充 Agent 需要的背景 —— 范围、约束、从哪里入手……",
+ "createGoal.next": "下一步",
+ "createGoal.preparing": "正在准备计划…",
+ "createGoal.regenerate": "重新起草",
+ "createGoal.removeCriterion": "删除这条标准",
+ "createGoal.requirementHint": "每一轮结束都会照这个判定",
+ "createGoal.requirementLabel": "什么算做到了",
+ "createGoal.requirementPlaceholder": "写成可以逐条打勾的样子:要有哪些交付物、边界在哪、什么条件下算通过。",
+ "createGoal.reviewStep": "第 2 步,共 2 步 · 完善执行计划",
+ "createGoal.roundBudget.rounds": "{{count}} 轮",
+ "createGoal.roundBudget.uncapped": "不限轮次",
+ "createGoal.roundBudgetHint": "跑满仍未达成会停下来等你。",
+ "createGoal.roundBudgetLabel": "轮次预算",
+ "createGoal.roundBudgetUncappedHint": "会一直跑到达成为止,注意花费。",
+ "createGoal.roundsUnit": "轮",
+ "createGoal.submit": "创建目标",
+ "createGoal.titlePlaceholder": "你想要的结果",
"createModal.createBlank": "从空白开始",
"createModal.groupPlaceholder": "描述这个群组要完成什么…",
"createModal.groupTitle": "这个群组要做什么?",
@@ -343,10 +373,36 @@
"goalDetail.taskStatus": "执行状态",
"goalDetail.unnamedRun": "未命名运行",
"goalDetail.viewPlan": "查看执行计划",
+ "goalEmpty.create": "创建第一个目标",
+ "goalEmpty.examples.backlog.requirement": "逐条标注类型与优先级,去重后汇总成一张表,并附出现最多的 10 个问题。",
+ "goalEmpty.examples.backlog.tag": "一次性整理",
+ "goalEmpty.examples.backlog.title": "把这一季度的用户反馈整理成一张分类表",
+ "goalEmpty.examples.digest.requirement": "至少 5 条重要进展,每条含日期、一句话摘要和原文链接,汇总成一篇能直接读的简报。",
+ "goalEmpty.examples.digest.tag": "周期性交付",
+ "goalEmpty.examples.digest.title": "每周一早上给我一份上周 AI 行业要闻",
+ "goalEmpty.examples.metric.requirement": "不少于 20 个选题,每个含标题、切入点和目标读者,去重并排除已发布过的。",
+ "goalEmpty.examples.metric.tag": "攒到目标量",
+ "goalEmpty.examples.metric.title": "为公众号攒够 20 个能写的选题",
+ "goalEmpty.examples.requirementPrefix": "验收:{{requirement}}",
+ "goalEmpty.examplesHint": "点击即可预填",
+ "goalEmpty.examplesTitle": "从一个例子开始",
+ "goalEmpty.howTitle": "创建之后会发生什么",
+ "goalEmpty.judge.bad": "「帮我盯一下竞品」—— 这是一件事,不是一个结果,Agent 无法判断什么时候算做完。",
+ "goalEmpty.judge.good": "「每周产出竞品汇总,覆盖 5 个指定产品,每条带原始链接」—— 有交付物、有边界、可判定。",
+ "goalEmpty.lead": "写清楚你要什么结果、怎样才算做到,剩下的交给 Agent —— 它会自己一轮轮地做,每轮都拿你的标准核对,直到真正达成。",
+ "goalEmpty.loop": "没通过就带着这一轮的结论进入下一轮继续,直到达成或用完轮次预算。轮次和花费随时可见,你可以中途暂停。",
+ "goalEmpty.step1.desc": "写下你要的结果,以及它会被怎么判定。越能被检查,Agent 越不会跑偏。",
+ "goalEmpty.step1.title": "定下结果与验收标准",
+ "goalEmpty.step2.desc": "每一轮是一次完整的 Agent 运行,产出、耗时和花费都挂在这个目标下。",
+ "goalEmpty.step2.title": "Agent 自主跑一轮",
+ "goalEmpty.step3.desc": "逐条判定验收检查项。全部通过即「已达成」;需要你拍板的会停在「待验收」。",
+ "goalEmpty.step3.title": "每轮自动验收",
+ "goalEmpty.title": "追逐目标,永无止境",
"goalList.acceptanceProgress": "已通过 {{passed}}/{{total}}",
"goalList.agentRuns": "{{count}} 次运行",
"goalList.empty": "暂无目标",
- "goalList.loadError": "无法加载目标。",
+ "goalList.loadError": "无法加载目标",
+ "goalList.loadErrorDescription": "服务暂时不可用,你的目标没有丢失。",
"goalList.retry": "重试",
"goalList.roundProgress": "第 {{current}}/{{total}} 轮",
"goalList.status.achieved": "已达成",
@@ -363,8 +419,6 @@
"goalPage.allGoals": "全部目标",
"goalPage.create": "创建目标",
"goalPage.description": "掌握 Agent 正在追逐什么,以及每个目标距离验收还有多远。",
- "goalPage.emptyDescription": "为这个 Agent 创建目标后,目标及其进度会显示在这里。",
- "goalPage.emptyTitle": "还没有目标",
"goalPage.filter.active": "进行中",
"goalPage.filter.all": "全部",
"goalPage.filter.open": "待处理目标",
diff --git a/packages/builtin-tool-task/src/index.ts b/packages/builtin-tool-task/src/index.ts
index 67931fa2ab7..3c4ef3ffa23 100644
--- a/packages/builtin-tool-task/src/index.ts
+++ b/packages/builtin-tool-task/src/index.ts
@@ -6,4 +6,5 @@ export {
} from './listTasks';
export { TaskIdentifier, TaskManifest } from './manifest';
export { systemPrompt } from './systemRole';
+export type { CreateGoalParams, GoalCriterionDraft } from './types';
export { TaskApiName } from './types';
diff --git a/packages/const/src/verify.ts b/packages/const/src/verify.ts
index 340a0f2265e..bae40abadcf 100644
--- a/packages/const/src/verify.ts
+++ b/packages/const/src/verify.ts
@@ -201,6 +201,21 @@ export type VerifyEvidenceCapturedBy = (typeof verifyEvidenceCapturedBy)[number]
/** Default cap on automatic repair rounds when a rubric doesn't override it. */
export const DEFAULT_MAX_REPAIR_ROUNDS = 3;
+/**
+ * Round budget applied when the user left a goal's round cap untouched.
+ *
+ * A goal has *two* independent budgets and they must never be written from one
+ * value: this one caps the outer loop (how many task topics the goal may spawn,
+ * `tasks.config.goal.maxIterations`), while {@link DEFAULT_MAX_REPAIR_ROUNDS}
+ * caps the inner auto-repair loop *within* a single round
+ * (`tasks.config.verify.maxIterations`). Their product is the worst-case number
+ * of agent runs a goal can pay for.
+ */
+export const DEFAULT_GOAL_MAX_ROUNDS = 3;
+
+/** Bounds the round budget a goal may be created with. */
+export const GOAL_MAX_ROUNDS_RANGE = { max: 10, min: 2 } as const;
+
/**
* The LobeHub conversation an ingested report was authored in. Lets the report
* link back to (and later resume) the agent session that produced it. Lives here
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 285a691eb69..2ca48d13132 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -1428,6 +1428,41 @@ export default {
'taskDetail.publishToWorkspace.errorPrivateAgent':
'This task is assigned to a private agent. Reassign to a workspace agent, or publish the agent first.',
+ 'createGoal.addCriterion': 'Add criterion',
+ 'createGoal.costBudgetHint':
+ 'Stops once total spend reaches this amount; leave blank for no cap.',
+ 'createGoal.costBudgetLabel': 'Cost budget',
+ 'createGoal.costBudgetPlaceholder': 'No cap',
+ 'createGoal.createFailed': 'Failed to create goal',
+ 'createGoal.back': 'Back',
+ 'createGoal.contextLabel': 'Context for the Agent',
+ 'createGoal.contextHint': 'Add constraints, source material, or anything the Agent should know',
+ 'createGoal.criterionPlaceholder': 'Describe a result that can be clearly checked',
+ 'createGoal.criteriaHint': 'Review and edit these before the goal starts',
+ 'createGoal.criteriaTitle': 'What counts as done',
+ 'createGoal.describeHint': 'Describe the outcome first, then complete its execution plan.',
+ 'createGoal.generateFailed': 'Could not draft acceptance criteria. Try again.',
+ 'createGoal.instructionPlaceholder':
+ 'Add any context the agent needs — scope, constraints, where to look…',
+ 'createGoal.next': 'Next',
+ 'createGoal.preparing': 'Preparing plan…',
+ 'createGoal.regenerate': 'Draft again',
+ 'createGoal.removeCriterion': 'Remove criterion',
+ 'createGoal.reviewStep': 'Step 2 of 2 · Complete the execution plan',
+ 'createGoal.requirementHint': 'Judged at the end of every round',
+ 'createGoal.requirementLabel': 'What counts as done',
+ 'createGoal.requirementPlaceholder':
+ 'Write it so it can be ticked off: what has to exist, where the boundary is, what makes it pass.',
+ 'createGoal.roundBudget.rounds': '{{count}} rounds',
+ 'createGoal.roundBudget.uncapped': 'No cap',
+ 'createGoal.roundBudgetHint':
+ 'If it runs out without reaching the goal, it stops and waits for you.',
+ 'createGoal.roundBudgetLabel': 'Round budget',
+ 'createGoal.roundsUnit': 'rounds',
+ 'createGoal.roundBudgetUncappedHint':
+ 'It keeps going until the goal is reached — watch the cost.',
+ 'createGoal.submit': 'Create goal',
+ 'createGoal.titlePlaceholder': 'The outcome you want',
'createTask.assignee': 'Assignee',
'createTask.collapse': 'Hide input',
'createTask.createFailed': 'Failed to create task',
@@ -1444,10 +1479,49 @@ export default {
'createTask.visibility.privateAgentLocked': 'Private agents can only run private tasks.',
'createTask.visibility.private': 'Private',
'createTask.visibility.workspace': 'Workspace',
+ 'goalEmpty.create': 'Create your first goal',
+ 'goalEmpty.examples.backlog.requirement':
+ 'Tag each item with a type and priority, dedupe into one table, and list the 10 most frequent issues.',
+ 'goalEmpty.examples.backlog.tag': 'One-off cleanup',
+ 'goalEmpty.examples.backlog.title':
+ "Turn this quarter's user feedback into one categorized table",
+ 'goalEmpty.examples.digest.requirement':
+ 'At least 5 notable developments, each with a date, a one-line summary and a source link, compiled into a ready-to-read brief.',
+ 'goalEmpty.examples.digest.tag': 'Recurring delivery',
+ 'goalEmpty.examples.digest.title':
+ "Give me last week's AI industry highlights every Monday morning",
+ 'goalEmpty.examples.metric.requirement':
+ 'At least 20 ideas, each with a headline, an angle and a target reader, deduped and excluding anything already published.',
+ 'goalEmpty.examples.metric.tag': 'Reach a target count',
+ 'goalEmpty.examples.metric.title': 'Build up 20 workable article ideas for the newsletter',
+ 'goalEmpty.examples.requirementPrefix': 'Done when: {{requirement}}',
+ 'goalEmpty.examplesHint': 'Click to prefill',
+ 'goalEmpty.examplesTitle': 'Start from an example',
+ 'goalEmpty.howTitle': 'What happens after you create one',
+ 'goalEmpty.judge.bad':
+ '“Keep an eye on competitors” — that is an activity, not an outcome. The agent can never tell when it is done.',
+ 'goalEmpty.judge.good':
+ '“Ship a weekly digest covering 5 named products, each with a source link” — a deliverable, a boundary, a verdict.',
+ 'goalEmpty.lead':
+ "Spell out the outcome you want and what counts as done. The agent takes it from there — working round after round, checking each attempt against your bar until it's actually met.",
+ 'goalEmpty.loop':
+ 'Not passed? It carries this round’s verdict into the next one and keeps going, until the goal is reached or the round budget runs out. Rounds and cost stay visible, and you can pause at any time.',
+ 'goalEmpty.step1.desc':
+ 'Write down the outcome and how it will be judged. The more checkable it is, the less the agent drifts.',
+ 'goalEmpty.step1.title': 'Set the outcome and the bar',
+ 'goalEmpty.step2.desc':
+ 'Each round is one full agent run; its output, time and cost all hang off this goal.',
+ 'goalEmpty.step2.title': 'The agent runs a round on its own',
+ 'goalEmpty.step3.desc':
+ 'Every check is judged one by one. All passed means achieved; anything needing your call stops at pending acceptance.',
+ 'goalEmpty.step3.title': 'Acceptance runs every round',
+ 'goalEmpty.title': 'Chase goals without limits',
'goalList.acceptanceProgress': '{{passed}}/{{total}} passed',
'goalList.agentRuns': '{{count}} runs',
'goalList.empty': 'No goals yet',
- 'goalList.loadError': 'Could not load goals.',
+ 'goalList.loadError': 'Could not load goals',
+ 'goalList.loadErrorDescription':
+ 'The service is temporarily unavailable. Your goals are not lost.',
'goalList.retry': 'Retry',
'goalList.roundProgress': 'Round {{current}}/{{total}}',
'goalList.status.achieved': 'Achieved',
@@ -1512,8 +1586,6 @@ export default {
'goalPage.description':
'Track what this agent is pursuing and how close each goal is to acceptance.',
'goalPage.create': 'Create goal',
- 'goalPage.emptyDescription': 'Goals created for this agent will appear here with their progress.',
- 'goalPage.emptyTitle': 'No goals yet',
'goalPage.filteredEmptyDescription': 'Switch to All to review completed or canceled goals.',
'goalPage.filteredEmptyTitle': 'No open goals',
'goalPage.filter.active': 'In progress',
diff --git a/src/features/AgentGoals/AgentGoalsPage.tsx b/src/features/AgentGoals/AgentGoalsPage.tsx
index 6c69eaa3ba4..cdd519e295e 100644
--- a/src/features/AgentGoals/AgentGoalsPage.tsx
+++ b/src/features/AgentGoals/AgentGoalsPage.tsx
@@ -9,13 +9,15 @@ import { useTranslation } from 'react-i18next';
import NeuralNetworkLoading from '@/components/NeuralNetworkLoading';
import AgentBreadcrumb from '@/features/AgentBreadcrumb';
-import { createTaskModal } from '@/features/AgentTasks/CreateTaskModal';
import NavHeader from '@/features/NavHeader';
import WideScreenContainer from '@/features/WideScreenContainer';
import { goalSelectors, useGoalStore } from '@/store/goal';
import { useVerifyStore } from '@/store/verify';
+import { createGoalModal } from './CreateGoalModal';
import { GoalCardItem } from './GoalCardItem';
+import GoalEmptyState from './GoalEmptyState';
+import type { GoalExampleSeed } from './goalExamples';
import { GoalListItem } from './GoalListItem';
import { getGoalPresentation } from './goalPresentation';
import { shouldShowGoal } from './goalViewModel';
@@ -106,12 +108,12 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId }) => {
}, [acceptanceBundleMap, acceptanceBySubjectMap, filter, goals]);
const visibleGoalCount = filteredGoals.length;
const GoalItem = viewMode === 'list' ? GoalListItem : GoalCardItem;
- const openCreateGoal = () => {
- createTaskModal({
+ const openCreateGoal = (seed?: GoalExampleSeed) => {
+ createGoalModal({
agentId,
- goal: true,
- lockAssignee: true,
- showInlineToggle: false,
+ initialRequirement: seed?.requirement,
+ initialRoundBudget: seed?.roundBudget,
+ initialTitle: seed?.title,
onCreated: () => void refreshGoals(agentId),
});
};
@@ -121,7 +123,7 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId }) => {
<NavHeader
left={<AgentBreadcrumb agentId={agentId} title={t('goalList.title')} />}
right={
- <Button icon={PlusIcon} size={'small'} onClick={openCreateGoal}>
+ <Button icon={PlusIcon} size={'small'} type={'fill'} onClick={() => openCreateGoal()}>
{t('goalPage.create')}
</Button>
}
@@ -137,22 +139,23 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId }) => {
<NeuralNetworkLoading />
</Flexbox>
) : error ? (
- <Flexbox align={'center'} flex={1} gap={12} justify={'center'}>
- <Text type={'secondary'}>{t('goalList.loadError')}</Text>
- <ActionIcon
- icon={RefreshCwIcon}
- title={t('goalList.retry')}
- onClick={() => void refreshGoals(agentId)}
- />
- </Flexbox>
- ) : goals.length === 0 ? (
<Block padding={32} variant={'outlined'}>
- <Empty description={t('goalPage.emptyDescription')} title={t('goalPage.emptyTitle')}>
- <Button icon={PlusIcon} onClick={openCreateGoal}>
- {t('goalPage.create')}
+ <Flexbox align={'center'} gap={12}>
+ <Text weight={600}>{t('goalList.loadError')}</Text>
+ <Text fontSize={13} type={'secondary'}>
+ {t('goalList.loadErrorDescription')}
+ </Text>
+ <Button
+ icon={RefreshCwIcon}
+ size={'small'}
+ onClick={() => void refreshGoals(agentId)}
+ >
+ {t('goalList.retry')}
</Button>
- </Empty>
+ </Flexbox>
</Block>
+ ) : goals.length === 0 ? (
+ <GoalEmptyState onCreate={openCreateGoal} />
) : (
<>
<Flexbox className={styles.overview}>
diff --git a/src/features/AgentGoals/CreateGoalModal/CreateGoalContent.tsx b/src/features/AgentGoals/CreateGoalModal/CreateGoalContent.tsx
new file mode 100644
index 00000000000..34c8f1915aa
--- /dev/null
+++ b/src/features/AgentGoals/CreateGoalModal/CreateGoalContent.tsx
@@ -0,0 +1,567 @@
+'use client';
+
+import type { CreateGoalParams, GoalCriterionDraft } from '@lobechat/builtin-tool-task';
+import { DEFAULT_GOAL_MAX_ROUNDS } from '@lobechat/const/verify';
+import { useEditor } from '@lobehub/editor/react';
+import { ActionIcon, Flexbox, Icon, Input, Text } from '@lobehub/ui';
+import { Button, toast, useModalContext } from '@lobehub/ui/base-ui';
+import { InputNumber } from 'antd';
+import { createStaticStyles, cssVar } from 'antd-style';
+import {
+ ArrowLeft,
+ CheckCircle2,
+ CircleDollarSign,
+ Paperclip,
+ Plus,
+ RotateCcw,
+ Trash2,
+ X,
+} from 'lucide-react';
+import { type KeyboardEvent, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
+import AssigneeAvatar from '@/features/AgentTasks/features/AssigneeAvatar';
+import TaskVisibilityChipLabel from '@/features/AgentTasks/features/TaskVisibilityChipLabel';
+import TaskVisibilityTag from '@/features/AgentTasks/features/TaskVisibilityTag';
+import { useAgentDisplayMeta } from '@/features/AgentTasks/shared/useAgentDisplayMeta';
+import { useAgentVisibility } from '@/features/AgentTasks/shared/useAgentVisibility';
+import { EditorCanvas } from '@/features/EditorCanvas';
+import { pickAndInsertAttachments } from '@/features/EditorCanvas/editorAttachments';
+import { usePermission } from '@/hooks/usePermission';
+import { verifyService } from '@/services/verify';
+import { useTaskStore } from '@/store/task';
+
+import { buildGoalTaskConfig } from './goalConfig';
+
+const styles = createStaticStyles(({ css }) => ({
+ budgetCard: css`
+ min-width: 0;
+ padding: 16px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadius};
+
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ budgetGrid: css`
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 12px;
+
+ @media (width <= 640px) {
+ grid-template-columns: minmax(0, 1fr);
+ }
+ `,
+ body: css`
+ overflow-y: auto;
+ min-height: 0;
+ padding-block: 8px 24px;
+ padding-inline: 24px;
+ `,
+ criteriaList: css`
+ overflow-y: auto;
+ max-height: 240px;
+ `,
+ criterion: css`
+ padding-block: 8px;
+ padding-inline: 10px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadius};
+
+ background: ${cssVar.colorBgElevated};
+ `,
+ criterionIndex: css`
+ display: flex;
+ flex: none;
+ align-items: center;
+ justify-content: center;
+
+ width: 24px;
+ height: 24px;
+ border-radius: ${cssVar.borderRadiusSM};
+
+ font-family: ${cssVar.fontFamilyCode};
+ font-size: 12px;
+ color: ${cssVar.colorTextSecondary};
+
+ background: ${cssVar.colorFillSecondary};
+ `,
+ footer: css`
+ padding-block: 8px;
+ padding-inline: 16px;
+ border-block-start: 1px solid ${cssVar.colorBorderSecondary};
+ `,
+ head: css`
+ padding-block: 16px 8px;
+ padding-inline: 24px;
+ `,
+ inputShell: css`
+ padding: 1px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadiusLG};
+ background: ${cssVar.colorBgElevated};
+ `,
+ inputShellLoading: css`
+ border-color: transparent;
+ background: linear-gradient(
+ 90deg,
+ ${cssVar.colorPrimary},
+ ${cssVar.colorInfo},
+ ${cssVar.colorSuccess},
+ ${cssVar.colorPrimary}
+ );
+ background-size: 300% 100%;
+ animation: goal-input-flow 1.4s linear infinite;
+
+ @keyframes goal-input-flow {
+ from {
+ background-position: 0% 50%;
+ }
+
+ to {
+ background-position: 150% 50%;
+ }
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ animation: none;
+ }
+ `,
+ section: css`
+ padding: 16px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadiusLG};
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ sectionIcon: css`
+ flex: none;
+ color: ${cssVar.colorTextSecondary};
+ `,
+ title: css`
+ width: 100%;
+ padding-block: 4px;
+ border: none;
+
+ font-family: inherit;
+ font-size: 20px;
+ font-weight: 600;
+ line-height: 1.4;
+ color: inherit;
+
+ background: transparent;
+ outline: none;
+ `,
+ titleDescribe: css`
+ padding-block: 10px;
+ padding-inline: 12px;
+ border-radius: ${cssVar.borderRadiusLG};
+ background: ${cssVar.colorBgElevated};
+ `,
+}));
+
+const criterionRequirement = (drafts: GoalCriterionDraft[]) =>
+ drafts
+ .map((draft) => draft.title.trim())
+ .filter(Boolean)
+ .map((title) => `- ${title}`)
+ .join('\n');
+
+export interface CreateGoalContentProps {
+ /** The agent that owns the goal. Goals are always agent-scoped. */
+ agentId?: string;
+ /** Seed from an empty-state example. Only the plain fields — the instruction
+ * body falls back to the title, so the editor is never fought over. */
+ initialRequirement?: string;
+ initialRoundBudget?: number;
+ initialTitle?: string;
+ onCreated?: (goal: { agentId?: string; identifier: string }) => void;
+}
+
+/**
+ * Create a goal — deliberately *not* the task modal with a flag.
+ *
+ * A goal commits the user to something a task never does: a standing acceptance
+ * bar and a budget of autonomous rounds spent against it. Both were previously
+ * invisible (the acceptance silently reused the instruction, the budget was
+ * hardcoded), so this form asks for them outright.
+ */
+const CreateGoalContent = memo<CreateGoalContentProps>((props) => {
+ const { agentId, initialRequirement, initialRoundBudget, initialTitle, onCreated } = props;
+ const { t } = useTranslation('chat');
+ const { close } = useModalContext();
+ const { allowed: canCreate, reason } = usePermission('create_content');
+
+ const createTask = useTaskStore((s) => s.createTask);
+ const isCreating = useTaskStore((s) => s.isCreatingTask);
+ const activeWorkspaceId = useActiveWorkspaceId();
+
+ const [step, setStep] = useState<'describe' | 'preparing' | 'review'>('describe');
+ const [plan, setPlan] = useState<CreateGoalParams>({
+ criteria: [],
+ instruction: initialRequirement ?? initialTitle ?? '',
+ maxIterations: initialRoundBudget ?? DEFAULT_GOAL_MAX_ROUNDS,
+ maxTotalCost: null,
+ name: initialTitle ?? '',
+ });
+ // Default to private in workspace mode so sharing is opt-in; personal mode
+ // ignores the field and hides the chip.
+ const [visibility, setVisibility] = useState<'private' | 'public'>('private');
+
+ // A private agent can only run a private task, goals included.
+ const isPrivateAgent = useAgentVisibility(agentId) === 'private';
+ useEffect(() => {
+ if (isPrivateAgent && visibility === 'public') setVisibility('private');
+ }, [isPrivateAgent, visibility]);
+
+ const editor = useEditor();
+ const prepareTimerRef = useRef<ReturnType<typeof setTimeout>>(null);
+ useEffect(
+ () => () => {
+ if (prepareTimerRef.current) clearTimeout(prepareTimerRef.current);
+ },
+ [],
+ );
+ const instructionRef = useRef(plan.instruction);
+ const assigneeMeta = useAgentDisplayMeta(agentId);
+ const requirement = useMemo(() => criterionRequirement(plan.criteria), [plan.criteria]);
+
+ const handleContentChange = useCallback(() => {
+ if (!canCreate || !editor) return;
+ instructionRef.current = String(editor.getDocument('markdown') ?? '');
+ setPlan((current) => ({ ...current, instruction: instructionRef.current }));
+ }, [canCreate, editor]);
+
+ const handleAttach = useCallback(() => {
+ pickAndInsertAttachments(editor);
+ }, [editor]);
+
+ const handleNext = useCallback(() => {
+ if (!canCreate || !plan.name.trim()) return;
+ const seededCriterion = initialRequirement?.trim();
+ setPlan((current) => ({
+ ...current,
+ criteria:
+ current.criteria.length > 0
+ ? current.criteria
+ : [
+ {
+ onFail: 'auto_repair',
+ required: true,
+ title: seededCriterion ?? '',
+ verifierType: 'agent',
+ },
+ ],
+ instruction: current.instruction.trim() || current.name.trim(),
+ }));
+ instructionRef.current = plan.instruction.trim() || plan.name.trim();
+ setStep('preparing');
+ prepareTimerRef.current = setTimeout(() => setStep('review'), 700);
+ }, [canCreate, initialRequirement, plan.instruction, plan.name]);
+
+ const updateCriterion = useCallback((index: number, value: string) => {
+ setPlan((current) => ({
+ ...current,
+ criteria: current.criteria.map((criterion, criterionIndex) =>
+ criterionIndex === index ? { ...criterion, title: value } : criterion,
+ ),
+ }));
+ }, []);
+
+ const removeCriterion = useCallback((index: number) => {
+ setPlan((current) => ({
+ ...current,
+ criteria: current.criteria.filter((_, criterionIndex) => criterionIndex !== index),
+ }));
+ }, []);
+
+ const addCriterion = useCallback(() => {
+ setPlan((current) => ({
+ ...current,
+ criteria: [
+ ...current.criteria,
+ { onFail: 'auto_repair', required: true, title: '', verifierType: 'agent' },
+ ],
+ }));
+ }, []);
+
+ const handleSubmit = useCallback(async () => {
+ if (!canCreate) return;
+ const instruction =
+ instructionRef.current.trim() || plan.instruction.trim() || plan.name.trim();
+ const editorData = instructionRef.current.trim()
+ ? (editor?.getDocument?.('json') as unknown)
+ : undefined;
+ const reviewedCriteria = plan.criteria.filter((criterion) => criterion.title.trim());
+ if (!instruction || reviewedCriteria.length === 0) return;
+
+ let verifyCriteriaIds: string[] = [];
+ try {
+ verifyCriteriaIds = await verifyService.createCriteria(reviewedCriteria);
+ const result = await createTask({
+ assigneeAgentId: agentId,
+ config: buildGoalTaskConfig({
+ costBudget: plan.maxTotalCost,
+ instruction,
+ requirement,
+ roundBudget: plan.maxIterations,
+ verifyCriteriaIds,
+ }),
+ editorData,
+ instruction,
+ name: plan.name.trim() || undefined,
+ visibility: activeWorkspaceId ? visibility : undefined,
+ });
+
+ if (!result) throw new Error('The goal was not created.');
+
+ close();
+ onCreated?.({
+ agentId: result.assigneeAgentId ?? undefined,
+ identifier: result.identifier,
+ });
+ } catch (error) {
+ console.error('[CreateGoalContent] create failed:', error);
+ await Promise.allSettled(verifyCriteriaIds.map((id) => verifyService.deleteCriterion(id)));
+ toast.error(t('createGoal.createFailed'));
+ }
+ }, [
+ activeWorkspaceId,
+ agentId,
+ canCreate,
+ close,
+ createTask,
+ editor,
+ onCreated,
+ plan,
+ requirement,
+ t,
+ visibility,
+ ]);
+
+ const handlePrimaryAction =
+ step === 'describe' ? handleNext : step === 'review' ? handleSubmit : undefined;
+ const handleSubmitRef = useRef(handlePrimaryAction);
+ useEffect(() => {
+ handleSubmitRef.current = handlePrimaryAction;
+ }, [handlePrimaryAction]);
+
+ const handleKeyDown = useCallback((e: KeyboardEvent<HTMLDivElement>) => {
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
+ e.preventDefault();
+ e.stopPropagation();
+ void handleSubmitRef.current?.();
+ }
+ }, []);
+
+ return (
+ <Flexbox height={step === 'review' ? 'min(86vh, 800px)' : undefined} onKeyDown={handleKeyDown}>
+ <Flexbox horizontal className={styles.head}>
+ <Flexbox flex={1} gap={6}>
+ {step === 'review' && (
+ <Flexbox horizontal align={'center'} gap={8}>
+ <ActionIcon
+ icon={ArrowLeft}
+ size={'small'}
+ title={t('createGoal.back')}
+ onClick={() => setStep('describe')}
+ />
+ <Text fontSize={12} type={'secondary'}>
+ {t('createGoal.reviewStep')}
+ </Text>
+ </Flexbox>
+ )}
+ {step === 'review' ? (
+ <Text fontSize={20} weight={600}>
+ {plan.name}
+ </Text>
+ ) : (
+ <div
+ className={`${styles.inputShell} ${step === 'preparing' ? styles.inputShellLoading : ''}`}
+ >
+ <input
+ autoFocus={canCreate}
+ className={`${styles.title} ${styles.titleDescribe}`}
+ disabled={!canCreate || step === 'preparing'}
+ placeholder={t('createGoal.titlePlaceholder')}
+ value={plan.name}
+ onChange={(e) => setPlan((current) => ({ ...current, name: e.target.value }))}
+ />
+ </div>
+ )}
+ {step !== 'review' && <Text type={'secondary'}>{t('createGoal.describeHint')}</Text>}
+ </Flexbox>
+ <ActionIcon icon={X} style={{ flexShrink: 0 }} onClick={close} />
+ </Flexbox>
+
+ {step === 'review' && (
+ <Flexbox className={styles.body} flex={1} gap={12}>
+ <Flexbox className={styles.section} gap={12}>
+ <Flexbox horizontal align={'flex-start'} gap={10}>
+ <Icon className={styles.sectionIcon} icon={Paperclip} size={18} />
+ <Flexbox gap={2}>
+ <Text fontSize={14} weight={600}>
+ {t('createGoal.contextLabel')}
+ </Text>
+ <Text fontSize={12} type={'secondary'}>
+ {t('createGoal.contextHint')}
+ </Text>
+ </Flexbox>
+ </Flexbox>
+ <EditorCanvas
+ disabled={!canCreate}
+ editor={editor}
+ editorData={{ content: plan.instruction }}
+ entityId={'create-goal-instruction'}
+ floatingToolbar={false}
+ placeholder={t('createGoal.instructionPlaceholder')}
+ style={{ fontSize: 14, minHeight: 120 }}
+ onContentChange={handleContentChange}
+ />
+ </Flexbox>
+
+ <Flexbox className={styles.section} gap={12}>
+ <Flexbox horizontal align={'center'} gap={8} justify={'space-between'}>
+ <Flexbox horizontal align={'flex-start'} gap={10}>
+ <Icon className={styles.sectionIcon} icon={CheckCircle2} size={18} />
+ <Flexbox gap={2}>
+ <Text fontSize={14} weight={600}>
+ {t('createGoal.criteriaTitle')}
+ </Text>
+ <Text fontSize={12} type={'secondary'}>
+ {t('createGoal.criteriaHint')}
+ </Text>
+ </Flexbox>
+ </Flexbox>
+ <Button icon={Plus} size={'small'} type={'text'} onClick={addCriterion}>
+ {t('createGoal.addCriterion')}
+ </Button>
+ </Flexbox>
+ <Flexbox className={styles.criteriaList} gap={8}>
+ {plan.criteria.map((criterion, index) => (
+ <Flexbox
+ horizontal
+ align={'center'}
+ className={styles.criterion}
+ gap={8}
+ key={index}
+ >
+ <span className={styles.criterionIndex}>C{index + 1}</span>
+ <Input
+ disabled={!canCreate}
+ placeholder={t('createGoal.criterionPlaceholder')}
+ value={criterion.title}
+ variant={'borderless'}
+ onChange={(e) => updateCriterion(index, e.target.value)}
+ />
+ <ActionIcon
+ icon={Trash2}
+ size={'small'}
+ title={t('createGoal.removeCriterion')}
+ onClick={() => removeCriterion(index)}
+ />
+ </Flexbox>
+ ))}
+ </Flexbox>
+ </Flexbox>
+
+ <div className={styles.budgetGrid}>
+ <Flexbox className={styles.budgetCard} gap={12}>
+ <Flexbox horizontal align={'center'} gap={8}>
+ <Icon className={styles.sectionIcon} icon={RotateCcw} size={16} />
+ <Text fontSize={14} weight={600}>
+ {t('createGoal.roundBudgetLabel')}
+ </Text>
+ </Flexbox>
+ <InputNumber
+ disabled={!canCreate}
+ min={2}
+ suffix={t('createGoal.roundsUnit')}
+ value={plan.maxIterations ?? undefined}
+ variant={'filled'}
+ onChange={(value) => setPlan((current) => ({ ...current, maxIterations: value }))}
+ />
+ <Text fontSize={12} type={'secondary'}>
+ {t('createGoal.roundBudgetHint')}
+ </Text>
+ </Flexbox>
+
+ <Flexbox className={styles.budgetCard} gap={12}>
+ <Flexbox horizontal align={'center'} gap={8}>
+ <Icon className={styles.sectionIcon} icon={CircleDollarSign} size={16} />
+ <Text fontSize={14} weight={600}>
+ {t('createGoal.costBudgetLabel')}
+ </Text>
+ </Flexbox>
+ <InputNumber
+ controls={false}
+ disabled={!canCreate}
+ min={0}
+ placeholder={t('createGoal.costBudgetPlaceholder')}
+ prefix={'$'}
+ value={plan.maxTotalCost}
+ variant={'filled'}
+ onChange={(value) => setPlan((current) => ({ ...current, maxTotalCost: value }))}
+ />
+ <Text fontSize={12} type={'secondary'}>
+ {t('createGoal.costBudgetHint')}
+ </Text>
+ </Flexbox>
+ </div>
+ </Flexbox>
+ )}
+
+ <Flexbox horizontal align={'center'} className={styles.footer} justify={'space-between'}>
+ <Flexbox horizontal align={'center'} gap={8} wrap={'wrap'}>
+ <Flexbox horizontal align={'center'} gap={6}>
+ <AssigneeAvatar agentId={agentId} size={18} />
+ <Text fontSize={12}>{assigneeMeta?.title}</Text>
+ </Flexbox>
+ {activeWorkspaceId && (
+ <TaskVisibilityTag
+ visibility={visibility}
+ lockedReason={
+ isPrivateAgent ? t('createTask.visibility.privateAgentLocked') : undefined
+ }
+ onChange={setVisibility}
+ >
+ <TaskVisibilityChipLabel visibility={visibility} />
+ </TaskVisibilityTag>
+ )}
+ {step === 'review' && (
+ <ActionIcon
+ icon={Paperclip}
+ title={t('upload.action.tooltip')}
+ onClick={handleAttach}
+ />
+ )}
+ </Flexbox>
+
+ <Button
+ loading={isCreating || step === 'preparing'}
+ shape={'round'}
+ size={'small'}
+ title={canCreate ? undefined : reason}
+ type={'primary'}
+ disabled={
+ !canCreate ||
+ isCreating ||
+ step === 'preparing' ||
+ !plan.name.trim() ||
+ (step === 'review' && plan.criteria.every((criterion) => !criterion.title.trim()))
+ }
+ onClick={step === 'describe' ? handleNext : handleSubmit}
+ >
+ {step === 'preparing'
+ ? t('createGoal.preparing')
+ : step === 'describe'
+ ? t('createGoal.next')
+ : t('createGoal.submit')}
+ </Button>
+ </Flexbox>
+ </Flexbox>
+ );
+});
+
+CreateGoalContent.displayName = 'CreateGoalContent';
+
+export default CreateGoalContent;
diff --git a/src/features/AgentGoals/CreateGoalModal/goalConfig.test.ts b/src/features/AgentGoals/CreateGoalModal/goalConfig.test.ts
new file mode 100644
index 00000000000..ebe8c5d6425
--- /dev/null
+++ b/src/features/AgentGoals/CreateGoalModal/goalConfig.test.ts
@@ -0,0 +1,80 @@
+import { DEFAULT_GOAL_MAX_ROUNDS, DEFAULT_MAX_REPAIR_ROUNDS } from '@lobechat/const/verify';
+import { describe, expect, it } from 'vitest';
+
+import { buildGoalTaskConfig } from './goalConfig';
+
+describe('buildGoalTaskConfig', () => {
+ it('keeps the round budget and the repair budget independent', () => {
+ // Regression: the create-goal path used to reuse the task modal and write the
+ // same number into both caps, so a 10-round goal also bought 10 auto-repair
+ // re-runs per round (up to 100 agent runs).
+ const config = buildGoalTaskConfig({ instruction: 'ship it', roundBudget: 10 });
+
+ expect(config.goal.maxIterations).toBe(10);
+ expect(config.verify.maxIterations).toBe(DEFAULT_MAX_REPAIR_ROUNDS);
+ });
+
+ it('falls back to the documented round default when the budget is untouched', () => {
+ expect(buildGoalTaskConfig({ instruction: 'ship it' }).goal.maxIterations).toBe(
+ DEFAULT_GOAL_MAX_ROUNDS,
+ );
+ });
+
+ it('preserves an explicit opt-out of the round cap', () => {
+ expect(
+ buildGoalTaskConfig({ instruction: 'ship it', roundBudget: null }).goal.maxIterations,
+ ).toBeNull();
+ });
+
+ it('clamps a round budget to the supported range', () => {
+ expect(buildGoalTaskConfig({ instruction: 'x', roundBudget: 1 }).goal.maxIterations).toBe(2);
+ expect(buildGoalTaskConfig({ instruction: 'x', roundBudget: 99 }).goal.maxIterations).toBe(10);
+ });
+
+ it('writes a positive cost budget and leaves it independent of the round budget', () => {
+ const config = buildGoalTaskConfig({ instruction: 'x', roundBudget: 5, costBudget: 2.5 });
+
+ expect(config.goal.maxTotalCost).toBe(2.5);
+ expect(config.goal.maxIterations).toBe(5);
+ });
+
+ it('maps a blank or non-positive cost budget to uncapped (null)', () => {
+ // The goal loop reads `null` as "no cap"; an empty or 0 input must not become a
+ // 0-dollar budget that would stop the goal before its first run.
+ expect(buildGoalTaskConfig({ instruction: 'x' }).goal.maxTotalCost).toBeNull();
+ expect(buildGoalTaskConfig({ instruction: 'x', costBudget: 0 }).goal.maxTotalCost).toBeNull();
+ expect(
+ buildGoalTaskConfig({ instruction: 'x', costBudget: null }).goal.maxTotalCost,
+ ).toBeNull();
+ });
+
+ it('uses the acceptance requirement when given', () => {
+ const config = buildGoalTaskConfig({
+ instruction: 'clear the P0 backlog',
+ requirement: 'every P0 has a linked PR with green CI',
+ });
+
+ expect(config.verify.requirement).toBe('every P0 has a linked PR with green CI');
+ expect(config.verify.enabled).toBe(true);
+ });
+
+ it('associates user-reviewed acceptance criteria with the goal', () => {
+ const config = buildGoalTaskConfig({
+ instruction: 'clear the P0 backlog',
+ verifyCriteriaIds: ['criterion-1', 'criterion-2'],
+ });
+
+ expect(config.verify.verifyCriteriaIds).toEqual(['criterion-1', 'criterion-2']);
+ });
+
+ it('falls back to the instruction so the goal stays judgeable', () => {
+ // An empty requirement would leave `planInstantiation` with no source for the
+ // holistic check, i.e. a goal that can never be accepted.
+ const config = buildGoalTaskConfig({
+ instruction: 'clear the P0 backlog',
+ requirement: ' ',
+ });
+
+ expect(config.verify.requirement).toBe('clear the P0 backlog');
+ });
+});
diff --git a/src/features/AgentGoals/CreateGoalModal/goalConfig.ts b/src/features/AgentGoals/CreateGoalModal/goalConfig.ts
new file mode 100644
index 00000000000..10843731696
--- /dev/null
+++ b/src/features/AgentGoals/CreateGoalModal/goalConfig.ts
@@ -0,0 +1,80 @@
+import {
+ DEFAULT_GOAL_MAX_ROUNDS,
+ DEFAULT_MAX_REPAIR_ROUNDS,
+ GOAL_MAX_ROUNDS_RANGE,
+} from '@lobechat/const/verify';
+import type { TaskGoalConfig, TaskVerifyConfig } from '@lobechat/types';
+
+/**
+ * A type alias rather than an interface on purpose: `createTask` takes
+ * `config?: Record<string, unknown>`, and only aliases get the implicit index
+ * signature that makes them assignable to it.
+ */
+export type GoalTaskConfig = {
+ goal: TaskGoalConfig;
+ verify: TaskVerifyConfig;
+};
+
+export interface BuildGoalTaskConfigParams {
+ /**
+ * Total USD budget across all rounds and their verify runs. `null`/`undefined`
+ * = uncapped (the user left it blank); a number is clamped to be non-negative.
+ */
+ costBudget?: number | null;
+ /** What the user typed as the goal itself; the acceptance fallback. */
+ instruction: string;
+ /** "What counts as done" — the source the acceptance criteria are generated from. */
+ requirement?: string;
+ /** Outer-loop budget: how many rounds (task topics) the goal may spawn. */
+ roundBudget?: number | null;
+ /** User-reviewed acceptance criteria generated before the goal is created. */
+ verifyCriteriaIds?: string[];
+}
+
+/**
+ * Build the `tasks.config` payload that marks a task as a goal root.
+ *
+ * The two `maxIterations` under this config look alike and mean different
+ * things, which is exactly how they got conflated before this existed: the
+ * create-goal modal reused the task modal and wrote the *same* number into both,
+ * so a goal created with a 10-round budget also bought 10 auto-repair re-runs
+ * inside every round — up to 100 agent runs for one goal.
+ *
+ * - `goal.maxIterations` — outer loop, rounds. User-facing ("轮次预算").
+ * - `goal.maxTotalCost` — outer loop, total USD across all rounds. User-facing ("成本预算").
+ * - `verify.maxIterations` — inner loop, repair re-runs within one round.
+ * Not user-facing; pinned to the platform default.
+ */
+export const buildGoalTaskConfig = ({
+ costBudget,
+ instruction,
+ requirement,
+ roundBudget,
+ verifyCriteriaIds,
+}: BuildGoalTaskConfigParams): GoalTaskConfig => {
+ const acceptance = requirement?.trim() || instruction.trim();
+
+ return {
+ goal: {
+ // `null` is the user's explicit "no cap" and must survive; `undefined`
+ // means they never chose, which falls back to the documented default.
+ maxIterations:
+ roundBudget === null
+ ? null
+ : typeof roundBudget === 'number'
+ ? Math.min(GOAL_MAX_ROUNDS_RANGE.max, Math.max(GOAL_MAX_ROUNDS_RANGE.min, roundBudget))
+ : DEFAULT_GOAL_MAX_ROUNDS,
+ // No cap unless the user set a positive number; the loop reads `null` as
+ // uncapped, so an empty / non-positive input maps back to `null`.
+ maxTotalCost: typeof costBudget === 'number' && costBudget > 0 ? costBudget : null,
+ },
+ verify: {
+ enabled: true,
+ maxIterations: DEFAULT_MAX_REPAIR_ROUNDS,
+ // Drives criteria generation on the first run (`planInstantiation`'s
+ // holistic fallback), so an empty one would leave the goal unjudgeable.
+ requirement: acceptance,
+ verifyCriteriaIds,
+ },
+ };
+};
diff --git a/src/features/AgentGoals/CreateGoalModal/index.tsx b/src/features/AgentGoals/CreateGoalModal/index.tsx
new file mode 100644
index 00000000000..90fc5a780fb
--- /dev/null
+++ b/src/features/AgentGoals/CreateGoalModal/index.tsx
@@ -0,0 +1,22 @@
+'use client';
+
+import { createModal, type ModalInstance } from '@lobehub/ui/base-ui';
+
+import CreateGoalContent, { type CreateGoalContentProps } from './CreateGoalContent';
+
+export type { CreateGoalContentProps };
+
+export const createGoalModal = (props?: CreateGoalContentProps): ModalInstance =>
+ createModal({
+ content: <CreateGoalContent {...props} />,
+ footer: null,
+ maskClosable: false,
+ styles: {
+ content: {
+ overflow: 'hidden',
+ padding: 0,
+ },
+ },
+ title: null,
+ width: 'min(88vw, 720px)',
+ });
diff --git a/src/features/AgentGoals/GoalEmptyState.tsx b/src/features/AgentGoals/GoalEmptyState.tsx
new file mode 100644
index 00000000000..fee732f86c7
--- /dev/null
+++ b/src/features/AgentGoals/GoalEmptyState.tsx
@@ -0,0 +1,295 @@
+'use client';
+
+import { Block, Flexbox, Icon, Text } from '@lobehub/ui';
+import { Button } from '@lobehub/ui/base-ui';
+import { createStaticStyles, cssVar } from 'antd-style';
+import {
+ CheckIcon,
+ CircleCheckBigIcon,
+ InfinityIcon,
+ PlayIcon,
+ PlusIcon,
+ RotateCcwIcon,
+ TargetIcon,
+ XIcon,
+} from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { GoalExampleSeed } from './goalExamples';
+import { buildGoalExampleSeed, GOAL_EXAMPLE_KEYS } from './goalExamples';
+
+const styles = createStaticStyles(({ css }) => ({
+ example: css`
+ cursor: pointer;
+
+ padding-block: 12px;
+ padding-inline: 14px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadius};
+
+ transition: all 0.15s ${cssVar.motionEaseOut};
+
+ &:hover {
+ border-color: ${cssVar.colorPrimaryBorder};
+ background: ${cssVar.colorFillQuaternary};
+ }
+ `,
+ exampleGrid: css`
+ display: grid;
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ gap: 10px;
+
+ @media (width <= 860px) {
+ grid-template-columns: minmax(0, 1fr);
+ }
+ `,
+ hero: css`
+ padding-block: 40px 32px;
+ padding-inline: 40px;
+ text-align: center;
+ `,
+ heroIcon: css`
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ width: 48px;
+ height: 48px;
+ border-radius: 14px;
+
+ color: ${cssVar.colorTextSecondary};
+
+ background: ${cssVar.colorFillTertiary};
+ `,
+ heroLead: css`
+ max-width: 560px;
+ line-height: 1.7;
+ `,
+ judge: css`
+ padding-block: 10px;
+ padding-inline: 14px;
+ border-radius: ${cssVar.borderRadius};
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ loopBack: css`
+ padding-block: 10px;
+ padding-inline: 12px;
+ border: 1px dashed ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadius};
+ `,
+ loopIcon: css`
+ flex: none;
+ margin-block-start: 1px;
+ color: ${cssVar.colorTextQuaternary};
+ `,
+ section: css`
+ padding-block: 24px;
+ padding-inline: 40px;
+ border-block-start: 1px solid ${cssVar.colorBorderSecondary};
+ `,
+ step: css`
+ min-width: 0;
+ height: 100%;
+ padding-block: 14px;
+ padding-inline: 16px;
+ border-radius: ${cssVar.borderRadius};
+
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ stepHead: css`
+ /* Reserve a stable header height so the descriptions below start on the same
+ line across all three cards, even if one title wraps. */
+ min-height: 20px;
+ `,
+ stepIndex: css`
+ display: flex;
+ flex: none;
+ align-items: center;
+ justify-content: center;
+
+ width: 18px;
+ height: 18px;
+ border-radius: 999px;
+
+ font-size: 11px;
+ font-variant-numeric: tabular-nums;
+ color: ${cssVar.colorTextSecondary};
+
+ background: ${cssVar.colorFillSecondary};
+ `,
+ steps: css`
+ display: grid;
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ gap: 10px;
+ align-items: stretch;
+
+ @media (width <= 860px) {
+ grid-template-columns: minmax(0, 1fr);
+ }
+ `,
+}));
+
+interface StepProps {
+ desc: string;
+ icon: typeof TargetIcon;
+ index: number;
+ title: string;
+}
+
+const Step = memo<StepProps>(({ desc, icon, index, title }) => (
+ <Flexbox className={styles.step} gap={8}>
+ <Flexbox horizontal align={'center'} className={styles.stepHead} gap={8}>
+ <span className={styles.stepIndex}>{index}</span>
+ <Icon icon={icon} size={14} style={{ flexShrink: 0 }} />
+ <Text fontSize={13} weight={600}>
+ {title}
+ </Text>
+ </Flexbox>
+ <Text fontSize={12} style={{ lineHeight: 1.65 }} type={'secondary'}>
+ {desc}
+ </Text>
+ </Flexbox>
+));
+
+Step.displayName = 'GoalEmptyStateStep';
+
+interface GoalEmptyStateProps {
+ onCreate: (seed?: GoalExampleSeed) => void;
+}
+
+/**
+ * First-run empty state for the goal list.
+ *
+ * A goal only pays off if the user understands the bargain before making one:
+ * it runs autonomously, judges itself each round, and spends budget doing it.
+ * "Goals will appear here" taught none of that, so this screen carries the
+ * concept (what a goal is), the mechanism (what happens after you create one),
+ * and three seeded examples that demonstrate what a *judgeable* outcome reads
+ * like.
+ */
+const GoalEmptyState = memo<GoalEmptyStateProps>(({ onCreate }) => {
+ const { t } = useTranslation('chat');
+
+ return (
+ <Block padding={0} variant={'outlined'}>
+ <Flexbox align={'center'} className={styles.hero} gap={16}>
+ <div className={styles.heroIcon}>
+ <Icon icon={InfinityIcon} size={24} />
+ </div>
+ <Flexbox align={'center'} gap={8}>
+ <Text fontSize={20} weight={600}>
+ {t('goalEmpty.title')}
+ </Text>
+ <Text className={styles.heroLead} fontSize={14} type={'secondary'}>
+ {t('goalEmpty.lead')}
+ </Text>
+ </Flexbox>
+ <Button icon={PlusIcon} type={'primary'} onClick={() => onCreate()}>
+ {t('goalEmpty.create')}
+ </Button>
+ </Flexbox>
+
+ <Flexbox className={styles.section} gap={14}>
+ <Text fontSize={13} type={'secondary'} weight={600}>
+ {t('goalEmpty.howTitle')}
+ </Text>
+ <div className={styles.steps}>
+ <Step
+ desc={t('goalEmpty.step1.desc')}
+ icon={TargetIcon}
+ index={1}
+ title={t('goalEmpty.step1.title')}
+ />
+ <Step
+ desc={t('goalEmpty.step2.desc')}
+ icon={PlayIcon}
+ index={2}
+ title={t('goalEmpty.step2.title')}
+ />
+ <Step
+ desc={t('goalEmpty.step3.desc')}
+ icon={CircleCheckBigIcon}
+ index={3}
+ title={t('goalEmpty.step3.title')}
+ />
+ </div>
+ <Flexbox horizontal align={'flex-start'} className={styles.loopBack} gap={8}>
+ <Icon className={styles.loopIcon} icon={RotateCcwIcon} size={13} />
+ <Text fontSize={12} style={{ lineHeight: 1.6 }} type={'secondary'}>
+ {t('goalEmpty.loop')}
+ </Text>
+ </Flexbox>
+ </Flexbox>
+
+ <Flexbox className={styles.section} gap={12}>
+ <Flexbox horizontal align={'center'} justify={'space-between'}>
+ <Text fontSize={13} type={'secondary'} weight={600}>
+ {t('goalEmpty.examplesTitle')}
+ </Text>
+ <Text fontSize={12} type={'secondary'}>
+ {t('goalEmpty.examplesHint')}
+ </Text>
+ </Flexbox>
+ <div className={styles.exampleGrid}>
+ {GOAL_EXAMPLE_KEYS.map((key) => {
+ const seed = buildGoalExampleSeed(key, (localeKey) => t(localeKey as never));
+
+ return (
+ <Flexbox
+ className={styles.example}
+ gap={6}
+ key={key}
+ role={'button'}
+ tabIndex={0}
+ onClick={() => onCreate(seed)}
+ onKeyDown={(event) => {
+ if (event.key !== 'Enter' && event.key !== ' ') return;
+ event.preventDefault();
+ onCreate(seed);
+ }}
+ >
+ <Text fontSize={11} type={'secondary'}>
+ {t(`goalEmpty.examples.${key}.tag` as never)}
+ </Text>
+ <Text fontSize={13} weight={500}>
+ {seed.title}
+ </Text>
+ <Text ellipsis={{ rows: 2 }} fontSize={12} type={'secondary'}>
+ {t('goalEmpty.examples.requirementPrefix', { requirement: seed.requirement })}
+ </Text>
+ </Flexbox>
+ );
+ })}
+ </div>
+
+ <Flexbox className={styles.judge} gap={6}>
+ <Flexbox horizontal align={'flex-start'} gap={8}>
+ <Icon
+ color={cssVar.colorError}
+ icon={XIcon}
+ size={13}
+ style={{ marginBlockStart: 3 }}
+ />
+ <Text fontSize={12} type={'secondary'}>
+ {t('goalEmpty.judge.bad')}
+ </Text>
+ </Flexbox>
+ <Flexbox horizontal align={'flex-start'} gap={8}>
+ <Icon
+ color={cssVar.colorSuccess}
+ icon={CheckIcon}
+ size={13}
+ style={{ marginBlockStart: 3 }}
+ />
+ <Text fontSize={12}>{t('goalEmpty.judge.good')}</Text>
+ </Flexbox>
+ </Flexbox>
+ </Flexbox>
+ </Block>
+ );
+});
+
+GoalEmptyState.displayName = 'GoalEmptyState';
+
+export default GoalEmptyState;
diff --git a/src/features/AgentGoals/goalExamples.test.ts b/src/features/AgentGoals/goalExamples.test.ts
new file mode 100644
index 00000000000..b190bcd61cd
--- /dev/null
+++ b/src/features/AgentGoals/goalExamples.test.ts
@@ -0,0 +1,30 @@
+import { GOAL_MAX_ROUNDS_RANGE } from '@lobechat/const/verify';
+import { describe, expect, it } from 'vitest';
+
+import {
+ buildGoalExampleSeed,
+ GOAL_EXAMPLE_KEYS,
+ GOAL_EXAMPLE_ROUND_BUDGETS,
+} from './goalExamples';
+
+describe('goalExamples', () => {
+ it('seeds every field the create-goal modal prefills from', () => {
+ // A card that opens an empty form teaches nothing, so the seed has to carry
+ // the title, the acceptance bar and the budget together.
+ expect(buildGoalExampleSeed('digest', (key) => key)).toEqual({
+ requirement: 'goalEmpty.examples.digest.requirement',
+ roundBudget: 3,
+ title: 'goalEmpty.examples.digest.title',
+ });
+ });
+
+ it('keeps every example budget inside the supported round range', () => {
+ // Out-of-range seeds would be silently clamped on submit, so the offered
+ // example would not be the goal the user actually got.
+ for (const key of GOAL_EXAMPLE_KEYS) {
+ const budget = GOAL_EXAMPLE_ROUND_BUDGETS[key];
+ expect(budget).toBeGreaterThanOrEqual(GOAL_MAX_ROUNDS_RANGE.min);
+ expect(budget).toBeLessThanOrEqual(GOAL_MAX_ROUNDS_RANGE.max);
+ }
+ });
+});
diff --git a/src/features/AgentGoals/goalExamples.ts b/src/features/AgentGoals/goalExamples.ts
new file mode 100644
index 00000000000..841f486835b
--- /dev/null
+++ b/src/features/AgentGoals/goalExamples.ts
@@ -0,0 +1,38 @@
+import { GOAL_MAX_ROUNDS_RANGE } from '@lobechat/const/verify';
+
+/**
+ * The seeded examples on the goal empty state.
+ *
+ * They are the screen's teaching device as much as a shortcut: each one shows
+ * what a *judgeable* outcome reads like (a deliverable, a boundary, a verdict),
+ * which is the part users get wrong when they write their first goal.
+ */
+export const GOAL_EXAMPLE_KEYS = ['backlog', 'digest', 'metric'] as const;
+
+export type GoalExampleKey = (typeof GOAL_EXAMPLE_KEYS)[number];
+
+/** Round budgets per example. Must stay inside {@link GOAL_MAX_ROUNDS_RANGE}. */
+export const GOAL_EXAMPLE_ROUND_BUDGETS: Record<GoalExampleKey, number> = {
+ backlog: 5,
+ digest: 3,
+ metric: 5,
+};
+
+export interface GoalExampleSeed {
+ requirement: string;
+ roundBudget: number;
+ title: string;
+}
+
+/**
+ * Resolve one example into the seed the create-goal modal is opened with.
+ * `translate` is passed in so this stays a pure function of the locale table.
+ */
+export const buildGoalExampleSeed = (
+ key: GoalExampleKey,
+ translate: (key: string) => string,
+): GoalExampleSeed => ({
+ requirement: translate(`goalEmpty.examples.${key}.requirement`),
+ roundBudget: GOAL_EXAMPLE_ROUND_BUDGETS[key],
+ title: translate(`goalEmpty.examples.${key}.title`),
+});
diff --git a/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx b/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx
index be0476f05f6..9776719cdb7 100644
--- a/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx
+++ b/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx
@@ -28,8 +28,6 @@ import { useAgentVisibility } from '../shared/useAgentVisibility';
export interface CreateTaskContentProps {
agentId?: string;
- /** Create a persistent goal root backed by the existing task + verify config. */
- goal?: boolean;
/**
* Locks the assignee to `agentId` and hides the agent picker. Used on the
* agent-scoped task list where every task belongs to that agent.
@@ -44,7 +42,7 @@ export interface CreateTaskContentProps {
}
const CreateTaskContent = memo<CreateTaskContentProps>(
- ({ agentId, goal = false, lockAssignee, onCreated, showInlineToggle = true }) => {
+ ({ agentId, lockAssignee, onCreated, showInlineToggle = true }) => {
const { t } = useTranslation('chat');
const { close } = useModalContext();
const { allowed: canCreateTask, reason } = usePermission('create_content');
@@ -104,16 +102,6 @@ const CreateTaskContent = memo<CreateTaskContentProps>(
try {
const result = await createTask({
assigneeAgentId,
- config: goal
- ? {
- goal: { maxIterations: 10 },
- verify: {
- enabled: true,
- maxIterations: 10,
- requirement: instruction || title.trim(),
- },
- }
- : undefined,
editorData: editorJson,
instruction: instruction || title.trim(),
name: title.trim() || undefined,
@@ -139,7 +127,6 @@ const CreateTaskContent = memo<CreateTaskContentProps>(
close,
createTask,
editor,
- goal,
onCreated,
priority,
t,