Skip to content

Commit ebd2099

Browse files
authored
πŸ› fix Status inconsistent in Agent Space
2 parents 084587a + 2b68225 commit ebd2099

File tree

6 files changed

+389
-37
lines changed

6 files changed

+389
-37
lines changed

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

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,15 @@ async def get_agent_info_impl(agent_id: int, tenant_id: str):
573573
elif "business_logic_model_name" not in agent_info:
574574
agent_info["business_logic_model_name"] = None
575575

576+
# Check agent availability
577+
is_available, unavailable_reasons = check_agent_availability(
578+
agent_id=agent_id,
579+
tenant_id=tenant_id,
580+
agent_info=agent_info
581+
)
582+
agent_info["is_available"] = is_available
583+
agent_info["unavailable_reasons"] = unavailable_reasons
584+
576585
return agent_info
577586

578587

@@ -1168,23 +1177,13 @@ async def list_all_agent_info_impl(tenant_id: str) -> list[dict]:
11681177
if not agent["enabled"]:
11691178
continue
11701179

1171-
unavailable_reasons: list[str] = []
1172-
1173-
tool_info = search_tools_for_sub_agent(
1174-
agent_id=agent["agent_id"], tenant_id=tenant_id)
1175-
tool_id_list = [tool["tool_id"]
1176-
for tool in tool_info if tool.get("tool_id") is not None]
1177-
if tool_id_list:
1178-
tool_statuses = check_tool_is_available(tool_id_list)
1179-
if not all(tool_statuses):
1180-
unavailable_reasons.append("tool_unavailable")
1181-
1182-
model_reasons = _collect_model_availability_reasons(
1183-
agent=agent,
1180+
# Use shared availability check function
1181+
_, unavailable_reasons = check_agent_availability(
1182+
agent_id=agent["agent_id"],
11841183
tenant_id=tenant_id,
1184+
agent_info=agent,
11851185
model_cache=model_cache
11861186
)
1187-
unavailable_reasons.extend(model_reasons)
11881187

11891188
# Preserve the raw data so we can adjust availability for duplicates
11901189
enriched_agents.append({
@@ -1295,6 +1294,56 @@ def _check_single_model_availability(
12951294
return []
12961295

12971296

1297+
def check_agent_availability(
1298+
agent_id: int,
1299+
tenant_id: str,
1300+
agent_info: dict | None = None,
1301+
model_cache: Dict[int, Optional[dict]] | None = None
1302+
) -> tuple[bool, list[str]]:
1303+
"""
1304+
Check if an agent is available based on its tools and model configuration.
1305+
1306+
Args:
1307+
agent_id: The agent ID to check
1308+
tenant_id: The tenant ID
1309+
agent_info: Optional pre-fetched agent info (to avoid duplicate DB queries)
1310+
model_cache: Optional model cache for performance optimization
1311+
1312+
Returns:
1313+
tuple: (is_available: bool, unavailable_reasons: list[str])
1314+
"""
1315+
unavailable_reasons: list[str] = []
1316+
1317+
if model_cache is None:
1318+
model_cache = {}
1319+
1320+
# Fetch agent info if not provided
1321+
if agent_info is None:
1322+
agent_info = search_agent_info_by_agent_id(agent_id, tenant_id)
1323+
1324+
if not agent_info:
1325+
return False, ["agent_not_found"]
1326+
1327+
# Check tool availability
1328+
tool_info = search_tools_for_sub_agent(agent_id=agent_id, tenant_id=tenant_id)
1329+
tool_id_list = [tool["tool_id"] for tool in tool_info if tool.get("tool_id") is not None]
1330+
if tool_id_list:
1331+
tool_statuses = check_tool_is_available(tool_id_list)
1332+
if not all(tool_statuses):
1333+
unavailable_reasons.append("tool_unavailable")
1334+
1335+
# Check model availability
1336+
model_reasons = _collect_model_availability_reasons(
1337+
agent=agent_info,
1338+
tenant_id=tenant_id,
1339+
model_cache=model_cache
1340+
)
1341+
unavailable_reasons.extend(model_reasons)
1342+
1343+
is_available = len(unavailable_reasons) == 0
1344+
return is_available, unavailable_reasons
1345+
1346+
12981347
def insert_related_agent_impl(parent_agent_id, child_agent_id, tenant_id):
12991348
# search the agent by bfs, check if there is a circular call
13001349
search_list = deque([child_agent_id])

β€Žfrontend/app/[locale]/page.tsxβ€Ž

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,11 @@ export default function Home() {
366366
onLoadAgents={loadAgents}
367367
onImportAgent={handleImportAgent}
368368
onChatNavigate={(agentId) => {
369-
// TODO: Store the selected agentId and pass it to ChatContent
370-
// For now, just navigate to chat view
369+
// Update URL with agent_id parameter for auto-selection in ChatAgentSelector
370+
const url = new URL(window.location.href);
371+
url.searchParams.set("agent_id", agentId);
372+
window.history.replaceState({}, "", url.toString());
373+
371374
setCurrentView("chat");
372375
saveView("chat");
373376
}}

β€Žfrontend/app/[locale]/space/components/AgentCard.tsxβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,13 @@ export default function AgentCard({ agent, onRefresh, onChat, onEdit }: AgentCar
265265
e.stopPropagation();
266266
handleChat();
267267
}}
268-
className="p-2 rounded-md hover:bg-green-50 dark:hover:bg-green-900/20 text-slate-400 hover:text-green-600 dark:hover:text-green-400 transition-colors"
269-
title={t("space.actions.chat", "Chat")}
268+
disabled={!agent.is_available}
269+
className={`p-2 rounded-md transition-colors ${
270+
agent.is_available
271+
? "hover:bg-green-50 dark:hover:bg-green-900/20 text-slate-400 hover:text-green-600 dark:hover:text-green-400"
272+
: "text-slate-300 dark:text-slate-600 cursor-not-allowed"
273+
}`}
274+
title={agent.is_available ? t("space.actions.chat", "Chat") : t("space.status.unavailable", "Unavailable")}
270275
>
271276
<MessageSquare className="h-4 w-4" />
272277
</button>

β€Žfrontend/app/[locale]/space/components/AgentDetailModal.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function AgentDetailModal({
6666
{agentDetails?.description || "-"}
6767
</Descriptions.Item>
6868
<Descriptions.Item label={t("space.detail.status", "Status")}>
69-
{agentDetails?.enabled ? (
69+
{agentDetails?.is_available ? (
7070
<Tag icon={<CheckCircle className="h-3 w-3" />} color="success" className="inline-flex items-center gap-1">
7171
<span className="whitespace-nowrap">{t("space.status.available", "Available")}</span>
7272
</Tag>

β€Žfrontend/app/[locale]/space/components/SpaceContent.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function SpaceContent({
6666
onChatNavigate(agentId);
6767
} else {
6868
// Fallback to URL navigation if callback not provided
69-
router.push(`/chat?agent=${agentId}`);
69+
router.push(`/chat?agent_id=${agentId}`);
7070
}
7171
};
7272

0 commit comments

Comments
Β (0)