Skip to content

Commit b783b24

Browse files
authored
πŸ› Delete the cache of agent information on the agent configuration page.
2 parents a3efa61 + 6233a6e commit b783b24

File tree

6 files changed

+162
-122
lines changed

6 files changed

+162
-122
lines changed

β€Žbackend/services/agent_service.pyβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ async def get_creating_sub_agent_info_impl(authorization: str = Header(None)):
247247
f"Failed to get sub agent enable tool id list: {str(e)}")
248248

249249
return {"agent_id": sub_agent_id,
250+
"name": agent_info.get("name"),
251+
"display_name": agent_info.get("display_name"),
252+
"description": agent_info.get("description"),
250253
"enable_tool_id_list": enable_tool_id_list,
251254
"model_name": agent_info["model_name"],
252255
"max_steps": agent_info["max_steps"],
@@ -598,7 +601,7 @@ async def list_all_agent_info_impl(tenant_id: str) -> list[dict]:
598601
simple_agent_list = []
599602
for agent in agent_list:
600603
# check agent is available
601-
if not agent["name"]:
604+
if not agent["enabled"]:
602605
continue
603606
tool_info = search_tools_for_sub_agent(
604607
agent_id=agent["agent_id"], tenant_id=tenant_id)

β€Žfrontend/app/[locale]/setup/agentSetup/components/AgentSetupOrchestrator.tsxβ€Ž

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ export default function AgentSetupOrchestrator({
120120
};
121121

122122
const fetchSubAgentIdAndEnableToolList = async (t: TFunction) => {
123-
setIsLoadingTools(true);
124-
// Clear the tool selection status when loading starts
125-
setSelectedTools([]);
126-
setEnabledToolIds([]);
123+
setIsLoadingTools(false);
127124

128125
try {
129126
const result = await getCreatingSubAgentId();
130127
if (result.success && result.data) {
131128
const {
132129
agentId,
130+
name,
131+
displayName,
132+
description,
133133
enabledToolIds,
134134
modelName,
135135
maxSteps,
@@ -142,6 +142,12 @@ export default function AgentSetupOrchestrator({
142142

143143
// Update the main agent ID
144144
setMainAgentId(agentId);
145+
// Update the main agent name
146+
setAgentName?.(name);
147+
// Update the main agent display name
148+
setAgentDisplayName?.(displayName);
149+
// Update the main agent description
150+
setAgentDescription?.(description);
145151
// Update the enabled tool ID list
146152
setEnabledToolIds(enabledToolIds);
147153
// Update the enabled agent ID list from sub_agent_id_list

β€Žfrontend/app/[locale]/setup/agentSetup/config.tsxβ€Ž

Lines changed: 8 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { AGENT_SETUP_LAYOUT_DEFAULT, GENERATE_PROMPT_STREAM_TYPES } from "@/cons
77
import { SETUP_PAGE_CONTAINER, STANDARD_CARD } from "@/const/layoutConstants";
88
import { OpenAIModel } from "@/types/modelConfig";
99
import {
10-
NewAgentCache,
1110
LayoutConfig,
1211
AgentConfigDataResponse,
1312
AgentConfigCustomEvent,
@@ -64,17 +63,6 @@ export default function AgentConfig() {
6463
const [agentDescription, setAgentDescription] = useState("");
6564
const [agentDisplayName, setAgentDisplayName] = useState("");
6665

67-
// Add cache for new agent creation to preserve content when switching controllers
68-
const [newAgentCache, setNewAgentCache] = useState<NewAgentCache>({
69-
businessLogic: "",
70-
dutyContent: "",
71-
constraintContent: "",
72-
fewShotsContent: "",
73-
agentName: "",
74-
agentDescription: "",
75-
agentDisplayName: "",
76-
});
77-
7866
// Add state for business logic and action buttons
7967
const [isGeneratingAgent, setIsGeneratingAgent] = useState(false);
8068

@@ -350,25 +338,6 @@ export default function AgentConfig() {
350338
};
351339
}, [businessLogic, dutyContent, constraintContent, fewShotsContent]);
352340

353-
// Remove frontend caching logic, completely rely on backend returned sub_agent_id_list
354-
// No longer need to set selectedAgents based on enabledAgentIds
355-
356-
// Monitor the status change of creating a new agent, and reset the relevant status
357-
useEffect(() => {
358-
if (isCreatingNewAgent) {
359-
// When starting to create new agent, try to restore cached content
360-
restoreNewAgentContent();
361-
}
362-
363-
// Always reset these states regardless of creation mode
364-
setSelectedTools([]);
365-
366-
// Reset the main agent configuration related status
367-
if (!isCreatingNewAgent) {
368-
setMainAgentModel(OpenAIModel.MainModel);
369-
setMainAgentMaxStep(5);
370-
}
371-
}, [isCreatingNewAgent]);
372341

373342
const handleEditingStateChange = (isEditing: boolean, agent: any) => {
374343
setIsEditingAgent(isEditing);
@@ -378,23 +347,7 @@ export default function AgentConfig() {
378347
if (isEditing && agent) {
379348
setAgentName(agent.name || "");
380349
setAgentDescription(agent.description || "");
381-
// If creating new agent, cache current content first, then clear
382-
if (isCreatingNewAgent) {
383-
setNewAgentCache({
384-
businessLogic,
385-
dutyContent,
386-
constraintContent,
387-
fewShotsContent,
388-
agentName,
389-
agentDescription,
390-
agentDisplayName,
391-
});
392-
// Clear new creation related content
393-
setIsCreatingNewAgent(false);
394-
setDutyContent("");
395-
setConstraintContent("");
396-
setFewShotsContent("");
397-
}
350+
398351
} else if (!isEditing) {
399352
// When stopping editing, clear name description box
400353
setAgentName("");
@@ -410,41 +363,9 @@ export default function AgentConfig() {
410363
return mainAgentId ? parseInt(mainAgentId) : undefined;
411364
};
412365

413-
const restoreNewAgentContent = () => {
414-
if (
415-
newAgentCache.businessLogic ||
416-
newAgentCache.dutyContent ||
417-
newAgentCache.constraintContent ||
418-
newAgentCache.fewShotsContent ||
419-
newAgentCache.agentName ||
420-
newAgentCache.agentDescription
421-
) {
422-
setBusinessLogic(newAgentCache.businessLogic);
423-
setDutyContent(newAgentCache.dutyContent);
424-
setConstraintContent(newAgentCache.constraintContent);
425-
setFewShotsContent(newAgentCache.fewShotsContent);
426-
setAgentName(newAgentCache.agentName);
427-
setAgentDescription(newAgentCache.agentDescription);
428-
setAgentDisplayName(newAgentCache.agentDisplayName);
429-
}
430-
};
431-
432-
const clearNewAgentCache = () => {
433-
setNewAgentCache({
434-
businessLogic: "",
435-
dutyContent: "",
436-
constraintContent: "",
437-
fewShotsContent: "",
438-
agentName: "",
439-
agentDescription: "",
440-
agentDisplayName: "",
441-
});
442-
};
443-
444366
// Handle exit creation mode - should clear cache
445367
const handleExitCreation = () => {
446368
setIsCreatingNewAgent(false);
447-
clearNewAgentCache();
448369
setBusinessLogic("");
449370
setDutyContent("");
450371
setConstraintContent("");
@@ -491,10 +412,7 @@ export default function AgentConfig() {
491412
setBusinessLogic={(value) => {
492413
setBusinessLogic(value);
493414
if (isCreatingNewAgent) {
494-
setNewAgentCache((prev) => ({
495-
...prev,
496-
businessLogic: value,
497-
}));
415+
setBusinessLogic(value);
498416
}
499417
}}
500418
selectedTools={selectedTools}
@@ -519,54 +437,42 @@ export default function AgentConfig() {
519437
setDutyContent={(value) => {
520438
setDutyContent(value);
521439
if (isCreatingNewAgent) {
522-
setNewAgentCache((prev) => ({ ...prev, dutyContent: value }));
440+
setDutyContent(value);
523441
}
524442
}}
525443
constraintContent={constraintContent}
526444
setConstraintContent={(value) => {
527445
setConstraintContent(value);
528446
if (isCreatingNewAgent) {
529-
setNewAgentCache((prev) => ({
530-
...prev,
531-
constraintContent: value,
532-
}));
447+
setConstraintContent(value);
533448
}
534449
}}
535450
fewShotsContent={fewShotsContent}
536451
setFewShotsContent={(value) => {
537452
setFewShotsContent(value);
538453
if (isCreatingNewAgent) {
539-
setNewAgentCache((prev) => ({
540-
...prev,
541-
fewShotsContent: value,
542-
}));
454+
setFewShotsContent(value);
543455
}
544456
}}
545457
agentName={agentName}
546458
setAgentName={(value) => {
547459
setAgentName(value);
548460
if (isCreatingNewAgent) {
549-
setNewAgentCache((prev) => ({ ...prev, agentName: value }));
461+
setAgentName(value);
550462
}
551463
}}
552464
agentDescription={agentDescription}
553465
setAgentDescription={(value) => {
554466
setAgentDescription(value);
555467
if (isCreatingNewAgent) {
556-
setNewAgentCache((prev) => ({
557-
...prev,
558-
agentDescription: value,
559-
}));
468+
setAgentDescription(value);
560469
}
561470
}}
562471
agentDisplayName={agentDisplayName}
563472
setAgentDisplayName={(value) => {
564473
setAgentDisplayName(value);
565474
if (isCreatingNewAgent) {
566-
setNewAgentCache((prev) => ({
567-
...prev,
568-
agentDisplayName: value,
569-
}));
475+
setAgentDisplayName(value);
570476
}
571477
}}
572478
isGeneratingAgent={isGeneratingAgent}

β€Žfrontend/services/agentConfigService.tsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export const getCreatingSubAgentId = async () => {
112112
success: true,
113113
data: {
114114
agentId: data.agent_id,
115+
name: data.name,
116+
displayName: data.display_name,
117+
description: data.description,
115118
enabledToolIds: data.enable_tool_id_list || [],
116119
modelName: data.model_name,
117120
maxSteps: data.max_steps,

β€Žfrontend/types/agentConfig.tsβ€Ž

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ export interface ToolParam {
5050

5151
// ========== Data Interfaces ==========
5252

53-
// Agent creation cache interface
54-
export interface NewAgentCache {
55-
businessLogic: string;
56-
dutyContent: string;
57-
constraintContent: string;
58-
fewShotsContent: string;
59-
agentName: string;
60-
agentDescription: string;
61-
agentDisplayName: string;
62-
}
63-
6453
// Agent configuration data response interface
6554
export interface AgentConfigDataResponse {
6655
businessLogic: string;

0 commit comments

Comments
Β (0)