Skip to content

Commit b4f9a7b

Browse files
authored
🐛 Fixed where the agent did not select the default large language model
2 parents ebc63e8 + e9ea482 commit b4f9a7b

File tree

11 files changed

+593
-94
lines changed

11 files changed

+593
-94
lines changed

backend/consts/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ class AgentInfoRequest(BaseModel):
211211
constraint_prompt: Optional[str] = None
212212
few_shots_prompt: Optional[str] = None
213213
enabled: Optional[bool] = None
214+
business_logic_model_name: Optional[str] = None
215+
business_logic_model_id: Optional[int] = None
214216

215217

216218
class AgentIDRequest(BaseModel):

backend/database/db_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ class AgentInfo(TableBase):
206206
Boolean, doc="Whether to provide the running summary to the manager agent")
207207
business_description = Column(
208208
Text, doc="Manually entered by the user to describe the entire business process")
209+
business_logic_model_name = Column(String(100), doc="Model name used for business logic prompt generation")
210+
business_logic_model_id = Column(Integer, doc="Model ID used for business logic prompt generation, foreign key reference to model_record_t.model_id")
209211

210212

211213
class ToolInstance(TableBase):

backend/services/agent_service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ async def get_agent_info_impl(agent_id: int, tenant_id: str):
236236
else:
237237
agent_info["model_name"] = None
238238

239+
# Get business logic model display name from model_id
240+
if agent_info.get("business_logic_model_id") is not None:
241+
business_logic_model_info = get_model_by_model_id(agent_info["business_logic_model_id"])
242+
agent_info["business_logic_model_name"] = business_logic_model_info.get("display_name", None) if business_logic_model_info is not None else None
243+
elif "business_logic_model_name" not in agent_info:
244+
agent_info["business_logic_model_name"] = None
245+
239246
return agent_info
240247

241248

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

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export default function AgentSetupOrchestrator({
4242
setMainAgentModelId,
4343
mainAgentMaxStep,
4444
setMainAgentMaxStep,
45+
businessLogicModel,
46+
setBusinessLogicModel,
47+
businessLogicModelId,
48+
setBusinessLogicModelId,
4549
tools,
4650
subAgentList = [],
4751
loadingAgents = false,
@@ -212,8 +216,6 @@ export default function AgentSetupOrchestrator({
212216
if (!isEditingAgent) {
213217
// Only clear and get new Agent configuration in creating mode
214218
setBusinessLogic("");
215-
setMainAgentModel(null); // Clear model selection when creating new agent
216-
setMainAgentModelId(null); // Clear model ID when creating new agent
217219
fetchSubAgentIdAndEnableToolList(t);
218220
} else {
219221
// In edit mode, data is loaded in handleEditAgent, here validate the form
@@ -323,8 +325,31 @@ export default function AgentSetupOrchestrator({
323325
setIsEditingAgent(false);
324326
setEditingAgent(null);
325327
setIsCreatingNewAgent(true);
326-
// Note: Don't clear content here - let the parent component's useEffect handle restoration
327-
// The parent component will restore cached content if available
328+
329+
// Clear all content when creating new agent to avoid showing cached data
330+
setBusinessLogic("");
331+
setDutyContent?.("");
332+
setConstraintContent?.("");
333+
setFewShotsContent?.("");
334+
setAgentName?.("");
335+
setAgentDescription?.("");
336+
setAgentDisplayName?.("");
337+
338+
// Clear tool and agent selections
339+
setSelectedTools([]);
340+
setEnabledToolIds([]);
341+
setEnabledAgentIds([]);
342+
343+
// Clear business logic model to allow default from global settings
344+
// The useEffect in PromptManager will set it to the default from localStorage
345+
setBusinessLogicModel(null);
346+
setBusinessLogicModelId(null);
347+
348+
// Clear main agent model selection to trigger default model selection
349+
// The useEffect in AgentConfigModal will set it to the default from localStorage
350+
setMainAgentModel(null);
351+
setMainAgentModelId(null);
352+
328353
onEditingStateChange?.(false, null);
329354
};
330355

@@ -417,7 +442,9 @@ export default function AgentSetupOrchestrator({
417442
constraintContent,
418443
fewShotsContent,
419444
agentDisplayName,
420-
mainAgentModelId ?? undefined
445+
mainAgentModelId ?? undefined,
446+
businessLogicModel ?? undefined,
447+
businessLogicModelId ?? undefined
421448
);
422449
} else {
423450
result = await updateAgent(
@@ -433,7 +460,9 @@ export default function AgentSetupOrchestrator({
433460
constraintContent,
434461
fewShotsContent,
435462
agentDisplayName,
436-
mainAgentModelId ?? undefined
463+
mainAgentModelId ?? undefined,
464+
businessLogicModel ?? undefined,
465+
businessLogicModelId ?? undefined
437466
);
438467
}
439468

@@ -555,6 +584,8 @@ export default function AgentSetupOrchestrator({
555584
setMainAgentModelId(agentDetail.model_id);
556585
setMainAgentMaxStep(agentDetail.max_step);
557586
setBusinessLogic(agentDetail.business_description || "");
587+
setBusinessLogicModel(agentDetail.business_logic_model_name || null);
588+
setBusinessLogicModelId(agentDetail.business_logic_model_id || null);
558589

559590
// Use backend returned sub_agent_id_list to set enabled agent list
560591
if (
@@ -595,21 +626,30 @@ export default function AgentSetupOrchestrator({
595626
};
596627

597628
// Handle the update of the model
629+
// Handle Business Logic Model change
630+
const handleBusinessLogicModelChange = (value: string, modelId?: number) => {
631+
setBusinessLogicModel(value);
632+
if (modelId !== undefined) {
633+
setBusinessLogicModelId(modelId);
634+
}
635+
};
636+
598637
const handleModelChange = async (value: string, modelId?: number) => {
599638
const targetAgentId =
600639
isEditingAgent && editingAgent ? editingAgent.id : mainAgentId;
601640

602-
if (!targetAgentId) {
603-
message.error(t("businessLogic.config.error.noAgentId"));
604-
return;
605-
}
606-
607641
// Update local state first
608642
setMainAgentModel(value);
609643
if (modelId !== undefined) {
610644
setMainAgentModelId(modelId);
611645
}
612646

647+
// If no agent ID yet (e.g., during initial creation setup), just update local state
648+
// The model will be saved when the agent is fully created
649+
if (!targetAgentId) {
650+
return;
651+
}
652+
613653
// Call updateAgent API to save the model change
614654
try {
615655
const result = await updateAgent(
@@ -961,6 +1001,9 @@ export default function AgentSetupOrchestrator({
9611001
}
9621002
onMaxStepChange={handleMaxStepChange}
9631003
onBusinessLogicChange={(value: string) => setBusinessLogic(value)}
1004+
onBusinessLogicModelChange={handleBusinessLogicModelChange}
1005+
businessLogicModel={businessLogicModel}
1006+
businessLogicModelId={businessLogicModelId}
9641007
onGenerateAgent={onGenerateAgent || (() => {})}
9651008
onSaveAgent={handleSaveAgent}
9661009
isGeneratingAgent={isGeneratingAgent}

0 commit comments

Comments
 (0)