feat(agents): add option to inherit main agent workspace when creating new agent (#639)

This commit is contained in:
paisley
2026-03-23 18:00:35 +08:00
committed by GitHub
Unverified
parent 6b82c6ccb4
commit c6021cedf4
7 changed files with 53 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
{
"title": "Agents",
"subtitle": "When adding a new Agent, ClawX will copy the main Agent's workspace files and runtime auth setup. The configuration can be modified through a dialog.",
"subtitle": "Create a new Agent to route specific channels to a separate personality or workspace.",
"refresh": "Refresh",
"addAgent": "Add Agent",
"gatewayWarning": "Gateway service is not running. Agent/channel changes may take a moment to apply.",
@@ -14,9 +14,11 @@
"creating": "Creating...",
"createDialog": {
"title": "Add Agent",
"description": "Create a new agent by name. ClawX will copy the main agent's workspace bootstrap files and runtime auth setup.",
"description": "Create a new agent by name. You can optionally inherit the main agent's workspace bootstrap files.",
"nameLabel": "Agent Name",
"namePlaceholder": "Coding Helper"
"namePlaceholder": "Coding Helper",
"inheritWorkspaceLabel": "Inherit main agent workspace",
"inheritWorkspaceDescription": "Copy SOUL.md, AGENTS.md, etc. from the main agent"
},
"deleteDialog": {
"title": "Delete Agent",

View File

@@ -1,6 +1,6 @@
{
"title": "Agents",
"subtitle": "新しい Agent を追加すると、ClawX はメイン Agent のワークスペース初期ファイルと実行時認証設定をコピーします。これらの設定は対話形式で編集できます",
"subtitle": "新しい Agent を作成し、特定のチャンネルを異なるパーソナリティやワークスペースにルーティングできます",
"refresh": "更新",
"addAgent": "Agent を追加",
"gatewayWarning": "Gateway サービスが停止しています。Agent または Channel の変更が反映されるまで少し時間がかかる場合があります。",
@@ -14,9 +14,11 @@
"creating": "作成中...",
"createDialog": {
"title": "Agent を追加",
"description": "名前だけで新しい Agent を作成できます。ClawX はメイン Agent のワークスペース初期ファイルと認証設定をコピーします。",
"description": "名前だけで新しい Agent を作成できます。メイン Agent のワークスペース初期ファイルを引き継ぐかどうかも選択できます。",
"nameLabel": "Agent 名",
"namePlaceholder": "Coding Helper"
"namePlaceholder": "Coding Helper",
"inheritWorkspaceLabel": "メイン Agent のワークスペースを引き継ぐ",
"inheritWorkspaceDescription": "SOUL.md、AGENTS.md などの初期ファイルをコピーします"
},
"deleteDialog": {
"title": "Agent を削除",

View File

@@ -1,6 +1,6 @@
{
"title": "Agents",
"subtitle": "添加新的 AgentClawX 会复制主 Agent 的工作区引导文件和运行时认证配置, 配置可以通过以对话的形式进行修改",
"subtitle": "创建新的 Agent,可以将特定频道路由到不同的人格配置或工作区。",
"refresh": "刷新",
"addAgent": "添加 Agent",
"gatewayWarning": "Gateway 服务未运行。Agent 或频道变更可能需要一点时间生效。",
@@ -14,9 +14,11 @@
"creating": "创建中...",
"createDialog": {
"title": "添加 Agent",
"description": "只需输入名称即可创建新 Agent。ClawX 会复制主 Agent 的工作区引导文件和运行时认证配置。",
"description": "输入名称即可创建新 Agent,可选择是否继承主 Agent 的工作区引导文件。",
"nameLabel": "Agent 名称",
"namePlaceholder": "Coding Helper"
"namePlaceholder": "Coding Helper",
"inheritWorkspaceLabel": "继承主 Agent 工作区",
"inheritWorkspaceDescription": "从主 Agent 复制 SOUL.md、AGENTS.md 等引导文件"
},
"deleteDialog": {
"title": "删除 Agent",

View File

@@ -6,6 +6,7 @@ import { Label } from '@/components/ui/label';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
import { Switch } from '@/components/ui/switch';
import { LoadingSpinner } from '@/components/common/LoadingSpinner';
import { useAgentsStore } from '@/stores/agents';
import { useGatewayStore } from '@/stores/gateway';
@@ -179,8 +180,8 @@ export function Agents() {
{showAddDialog && (
<AddAgentDialog
onClose={() => setShowAddDialog(false)}
onCreate={async (name) => {
await createAgent(name);
onCreate={async (name, options) => {
await createAgent(name, options);
setShowAddDialog(false);
toast.success(t('toast.agentCreated'));
}}
@@ -345,17 +346,18 @@ function AddAgentDialog({
onCreate,
}: {
onClose: () => void;
onCreate: (name: string) => Promise<void>;
onCreate: (name: string, options: { inheritWorkspace: boolean }) => Promise<void>;
}) {
const { t } = useTranslation('agents');
const [name, setName] = useState('');
const [inheritWorkspace, setInheritWorkspace] = useState(false);
const [saving, setSaving] = useState(false);
const handleSubmit = async () => {
if (!name.trim()) return;
setSaving(true);
try {
await onCreate(name.trim());
await onCreate(name.trim(), { inheritWorkspace });
} catch (error) {
toast.error(t('toast.agentCreateFailed', { error: String(error) }));
setSaving(false);
@@ -386,6 +388,17 @@ function AddAgentDialog({
className={inputClasses}
/>
</div>
<div className="flex items-center justify-between">
<div className="space-y-0.5">
<Label htmlFor="inherit-workspace" className={labelClasses}>{t('createDialog.inheritWorkspaceLabel')}</Label>
<p className="text-[13px] text-foreground/60">{t('createDialog.inheritWorkspaceDescription')}</p>
</div>
<Switch
id="inherit-workspace"
checked={inheritWorkspace}
onCheckedChange={setInheritWorkspace}
/>
</div>
<div className="flex justify-end gap-2">
<Button
variant="outline"

View File

@@ -12,7 +12,7 @@ interface AgentsState {
loading: boolean;
error: string | null;
fetchAgents: () => Promise<void>;
createAgent: (name: string) => Promise<void>;
createAgent: (name: string, options?: { inheritWorkspace?: boolean }) => Promise<void>;
updateAgent: (agentId: string, name: string) => Promise<void>;
deleteAgent: (agentId: string) => Promise<void>;
assignChannel: (agentId: string, channelType: ChannelType) => Promise<void>;
@@ -52,12 +52,12 @@ export const useAgentsStore = create<AgentsState>((set) => ({
}
},
createAgent: async (name: string) => {
createAgent: async (name: string, options?: { inheritWorkspace?: boolean }) => {
set({ error: null });
try {
const snapshot = await hostApiFetch<AgentsSnapshot & { success?: boolean }>('/api/agents', {
method: 'POST',
body: JSON.stringify({ name }),
body: JSON.stringify({ name, inheritWorkspace: options?.inheritWorkspace }),
});
set(applySnapshot(snapshot));
} catch (error) {