Skip to content

Commit f90c6da

Browse files
committed
✨ record model_id in ag_tenant_agent_t, support revise model display_name
1 parent d54f460 commit f90c6da

File tree

8 files changed

+119
-13
lines changed

8 files changed

+119
-13
lines changed

frontend/app/[locale]/setup/agents/components/AgentSetupOrchestrator.tsx

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default function AgentSetupOrchestrator({
3838
setIsCreatingNewAgent,
3939
mainAgentModel,
4040
setMainAgentModel,
41+
mainAgentModelId,
42+
setMainAgentModelId,
4143
mainAgentMaxStep,
4244
setMainAgentMaxStep,
4345
tools,
@@ -167,6 +169,10 @@ export default function AgentSetupOrchestrator({
167169
}
168170
// Update the model
169171
setMainAgentModel(modelName);
172+
// Update the model ID if available
173+
if (result.data.model_id) {
174+
setMainAgentModelId(result.data.model_id);
175+
}
170176
// Update the maximum number of steps
171177
if (maxSteps) {
172178
setMainAgentMaxStep(maxSteps);
@@ -207,6 +213,7 @@ export default function AgentSetupOrchestrator({
207213
// Only clear and get new Agent configuration in creating mode
208214
setBusinessLogic("");
209215
setMainAgentModel(null); // Clear model selection when creating new agent
216+
setMainAgentModelId(null); // Clear model ID when creating new agent
210217
fetchSubAgentIdAndEnableToolList(t);
211218
} else {
212219
// In edit mode, data is loaded in handleEditAgent, here validate the form
@@ -217,6 +224,7 @@ export default function AgentSetupOrchestrator({
217224
if (!isEditingAgent && hasInitialized.current) {
218225
setBusinessLogic("");
219226
setMainAgentModel(null);
227+
setMainAgentModelId(null);
220228
setMainAgentMaxStep(5);
221229
// Delay refreshing agent list to avoid jumping
222230
setTimeout(() => {
@@ -408,7 +416,8 @@ export default function AgentSetupOrchestrator({
408416
dutyContent,
409417
constraintContent,
410418
fewShotsContent,
411-
agentDisplayName
419+
agentDisplayName,
420+
mainAgentModelId ?? undefined
412421
);
413422
} else {
414423
result = await updateAgent(
@@ -423,7 +432,8 @@ export default function AgentSetupOrchestrator({
423432
dutyContent,
424433
constraintContent,
425434
fewShotsContent,
426-
agentDisplayName
435+
agentDisplayName,
436+
mainAgentModelId ?? undefined
427437
);
428438
}
429439

@@ -542,6 +552,7 @@ export default function AgentSetupOrchestrator({
542552

543553
// Load Agent data to interface
544554
setMainAgentModel(agentDetail.model);
555+
setMainAgentModelId(agentDetail.model_id);
545556
setMainAgentMaxStep(agentDetail.max_step);
546557
setBusinessLogic(agentDetail.business_description || "");
547558

@@ -584,15 +595,54 @@ export default function AgentSetupOrchestrator({
584595
};
585596

586597
// Handle the update of the model
587-
const handleModelChange = async (value: string) => {
598+
const handleModelChange = async (value: string, modelId?: number) => {
588599
const targetAgentId =
589600
isEditingAgent && editingAgent ? editingAgent.id : mainAgentId;
590601

591602
if (!targetAgentId) {
592603
message.error(t("businessLogic.config.error.noAgentId"));
593604
return;
594605
}
606+
607+
// Update local state first
595608
setMainAgentModel(value);
609+
if (modelId !== undefined) {
610+
setMainAgentModelId(modelId);
611+
}
612+
613+
// Call updateAgent API to save the model change
614+
try {
615+
const result = await updateAgent(
616+
Number(targetAgentId),
617+
undefined, // name
618+
undefined, // description
619+
value, // modelName
620+
undefined, // maxSteps
621+
undefined, // provideRunSummary
622+
undefined, // enabled
623+
undefined, // businessDescription
624+
undefined, // dutyPrompt
625+
undefined, // constraintPrompt
626+
undefined, // fewShotsPrompt
627+
undefined, // displayName
628+
modelId // modelId
629+
);
630+
631+
if (!result.success) {
632+
message.error(
633+
result.message || t("businessLogic.config.error.modelUpdateFailed")
634+
);
635+
// Revert local state on failure
636+
setMainAgentModel(mainAgentModel);
637+
setMainAgentModelId(mainAgentModelId);
638+
}
639+
} catch (error) {
640+
log.error("Error updating agent model:", error);
641+
message.error(t("businessLogic.config.error.modelUpdateFailed"));
642+
// Revert local state on failure
643+
setMainAgentModel(mainAgentModel);
644+
setMainAgentModelId(mainAgentModelId);
645+
}
596646
};
597647

598648
// Handle the update of the maximum number of steps
@@ -607,7 +657,40 @@ export default function AgentSetupOrchestrator({
607657

608658
const newValue = value ?? 5;
609659

660+
// Update local state first
610661
setMainAgentMaxStep(newValue);
662+
663+
// Call updateAgent API to save the max steps change
664+
try {
665+
const result = await updateAgent(
666+
Number(targetAgentId),
667+
undefined, // name
668+
undefined, // description
669+
undefined, // modelName
670+
newValue, // maxSteps
671+
undefined, // provideRunSummary
672+
undefined, // enabled
673+
undefined, // businessDescription
674+
undefined, // dutyPrompt
675+
undefined, // constraintPrompt
676+
undefined, // fewShotsPrompt
677+
undefined, // displayName
678+
undefined // modelId
679+
);
680+
681+
if (!result.success) {
682+
message.error(
683+
result.message || t("businessLogic.config.error.maxStepsUpdateFailed")
684+
);
685+
// Revert local state on failure
686+
setMainAgentMaxStep(mainAgentMaxStep);
687+
}
688+
} catch (error) {
689+
log.error("Error updating agent max steps:", error);
690+
message.error(t("businessLogic.config.error.maxStepsUpdateFailed"));
691+
// Revert local state on failure
692+
setMainAgentMaxStep(mainAgentMaxStep);
693+
}
611694
};
612695

613696
// Handle importing agent
@@ -871,9 +954,10 @@ export default function AgentSetupOrchestrator({
871954
onAgentDisplayNameChange={setAgentDisplayName}
872955
isEditingMode={isEditingAgent || isCreatingNewAgent}
873956
mainAgentModel={mainAgentModel ?? undefined}
957+
mainAgentModelId={mainAgentModelId}
874958
mainAgentMaxStep={mainAgentMaxStep}
875-
onModelChange={(value: string) =>
876-
handleModelChange(value)
959+
onModelChange={(value: string, modelId?: number) =>
960+
handleModelChange(value, modelId)
877961
}
878962
onMaxStepChange={handleMaxStepChange}
879963
onBusinessLogicChange={(value: string) => setBusinessLogic(value)}

frontend/app/[locale]/setup/agents/components/PromptManager.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export interface PromptManagerProps {
186186
agentDescription?: string;
187187
agentDisplayName?: string;
188188
mainAgentModel?: string;
189+
mainAgentModelId?: number | null;
189190
mainAgentMaxStep?: number;
190191

191192
// Edit state
@@ -202,7 +203,7 @@ export interface PromptManagerProps {
202203
onAgentNameChange?: (name: string) => void;
203204
onAgentDescriptionChange?: (description: string) => void;
204205
onAgentDisplayNameChange?: (displayName: string) => void;
205-
onModelChange?: (value: string) => void;
206+
onModelChange?: (value: string, modelId?: number) => void;
206207
onMaxStepChange?: (value: number | null) => void;
207208
onGenerateAgent?: (model: ModelOption) => void;
208209
onSaveAgent?: () => void;
@@ -230,6 +231,7 @@ export default function PromptManager({
230231
agentDescription = "",
231232
agentDisplayName = "",
232233
mainAgentModel = "",
234+
mainAgentModelId = null,
233235
mainAgentMaxStep = 5,
234236
isEditingMode = false,
235237
isGeneratingAgent = false,
@@ -354,7 +356,8 @@ export default function PromptManager({
354356
dutyContent,
355357
constraintContent,
356358
fewShotsContent,
357-
agentDisplayName
359+
agentDisplayName,
360+
mainAgentModelId ?? undefined
358361
);
359362

360363
if (result.success) {
@@ -506,6 +509,7 @@ export default function PromptManager({
506509
onAgentDisplayNameChange={onAgentDisplayNameChange}
507510
isEditingMode={isEditingMode}
508511
mainAgentModel={mainAgentModel}
512+
mainAgentModelId={mainAgentModelId}
509513
mainAgentMaxStep={mainAgentMaxStep}
510514
onModelChange={onModelChange}
511515
onMaxStepChange={onMaxStepChange}

frontend/app/[locale]/setup/agents/components/agent/AgentConfigModal.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ export interface AgentConfigModalProps {
3939
onAgentDisplayNameChange?: (displayName: string) => void;
4040
isEditingMode?: boolean;
4141
mainAgentModel?: string;
42+
mainAgentModelId?: number | null;
4243
mainAgentMaxStep?: number;
43-
onModelChange?: (value: string) => void;
44+
onModelChange?: (value: string, modelId?: number) => void;
4445
onMaxStepChange?: (value: number | null) => void;
4546
onSavePrompt?: () => void;
4647
onExpandCard?: (index: number) => void;
@@ -73,6 +74,7 @@ export default function AgentConfigModal({
7374
onAgentDisplayNameChange,
7475
isEditingMode = false,
7576
mainAgentModel = "",
77+
mainAgentModelId = null,
7678
mainAgentMaxStep = 5,
7779
onModelChange,
7880
onMaxStepChange,
@@ -454,7 +456,10 @@ export default function AgentConfigModal({
454456
</label>
455457
<Select
456458
value={mainAgentModel || undefined}
457-
onChange={(value) => onModelChange?.(value)}
459+
onChange={(value, option) => {
460+
const modelId = option && 'key' in option ? Number(option.key) : undefined;
461+
onModelChange?.(value, modelId);
462+
}}
458463
size="large"
459464
disabled={!isEditingMode}
460465
style={{ width: "100%" }}
@@ -512,7 +517,6 @@ export default function AgentConfigModal({
512517
maxHeight: "200px",
513518
boxShadow: "none",
514519
}}
515-
bordered={false}
516520
/>
517521
</div>
518522
</div>

frontend/app/[locale]/setup/agents/config.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default function AgentConfig() {
4747
const [isDebugDrawerOpen, setIsDebugDrawerOpen] = useState(false);
4848
const [isCreatingNewAgent, setIsCreatingNewAgent] = useState(false);
4949
const [mainAgentModel, setMainAgentModel] = useState<string | null>(null);
50+
const [mainAgentModelId, setMainAgentModelId] = useState<number | null>(null);
5051
const [mainAgentMaxStep, setMainAgentMaxStep] = useState(5);
5152
const [tools, setTools] = useState<any[]>([]);
5253
const [mainAgentId, setMainAgentId] = useState<string | null>(null);
@@ -434,6 +435,8 @@ export default function AgentConfig() {
434435
setIsCreatingNewAgent={setIsCreatingNewAgent}
435436
mainAgentModel={mainAgentModel}
436437
setMainAgentModel={setMainAgentModel}
438+
mainAgentModelId={mainAgentModelId}
439+
setMainAgentModelId={setMainAgentModelId}
437440
mainAgentMaxStep={mainAgentMaxStep}
438441
setMainAgentMaxStep={setMainAgentMaxStep}
439442
tools={tools}

frontend/public/locales/en/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,5 +928,7 @@
928928
"agentCallRelationship.description": "This flowchart shows the call relationship of {{name}} and all its tools and collaborative agents",
929929
"agentCallRelationship.noData": "No call relationship data available",
930930
"businessLogic.config.error.loadModelsFailed": "Failed to load available models",
931-
"businessLogic.config.error.noAvailableModels": "No available models"
931+
"businessLogic.config.error.noAvailableModels": "No available models",
932+
"businessLogic.config.error.modelUpdateFailed": "Failed to update agent model",
933+
"businessLogic.config.error.maxStepsUpdateFailed": "Failed to update agent max steps"
932934
}

frontend/public/locales/zh/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,5 +929,7 @@
929929
"agentCallRelationship.description": "此流程图显示了 {{name}} 及其所有工具和协作Agent的调用关系",
930930
"agentCallRelationship.noData": "暂无调用关系数据",
931931
"businessLogic.config.error.loadModelsFailed": "加载可用模型失败",
932-
"businessLogic.config.error.noAvailableModels": "暂无可用的模型"
932+
"businessLogic.config.error.noAvailableModels": "暂无可用的模型",
933+
"businessLogic.config.error.modelUpdateFailed": "更新Agent模型失败",
934+
"businessLogic.config.error.maxStepsUpdateFailed": "更新Agent最大步数失败"
933935
}

frontend/services/agentConfigService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export const getCreatingSubAgentId = async () => {
118118
description: data.description,
119119
enabledToolIds: data.enable_tool_id_list || [],
120120
modelName: data.model_name,
121+
model_id: data.model_id,
121122
maxSteps: data.max_steps,
122123
businessDescription: data.business_description,
123124
dutyPrompt: data.duty_prompt,
@@ -277,7 +278,8 @@ export const updateAgent = async (
277278
dutyPrompt?: string,
278279
constraintPrompt?: string,
279280
fewShotsPrompt?: string,
280-
displayName?: string
281+
displayName?: string,
282+
modelId?: number
281283
) => {
282284
try {
283285
const response = await fetch(API_ENDPOINTS.agent.update, {
@@ -289,6 +291,7 @@ export const updateAgent = async (
289291
description: description,
290292
display_name: displayName,
291293
model_name: modelName,
294+
model_id: modelId,
292295
max_steps: maxSteps,
293296
provide_run_summary: provideRunSummary,
294297
enabled: enabled,
@@ -453,6 +456,7 @@ export const searchAgentInfo = async (agentId: number) => {
453456
display_name: data.display_name,
454457
description: data.description,
455458
model: data.model_name,
459+
model_id: data.model_id,
456460
max_step: data.max_steps,
457461
duty_prompt: data.duty_prompt,
458462
constraint_prompt: data.constraint_prompt,

frontend/types/agentConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface Agent {
1111
display_name?: string;
1212
description: string;
1313
model: string;
14+
model_id?: number;
1415
max_step: number;
1516
provide_run_summary: boolean;
1617
tools: Tool[];
@@ -85,6 +86,8 @@ export interface AgentSetupOrchestratorProps {
8586
setIsCreatingNewAgent: (value: boolean) => void;
8687
mainAgentModel: string | null;
8788
setMainAgentModel: (value: string | null) => void;
89+
mainAgentModelId: number | null;
90+
setMainAgentModelId: (value: number | null) => void;
8891
mainAgentMaxStep: number;
8992
setMainAgentMaxStep: (value: number) => void;
9093
tools: Tool[];

0 commit comments

Comments
 (0)