fix(agent): 调整agent显示样式
This commit is contained in:
1 parent
b2fa2688a3
commit
42de6c02d3
3 files changed
+101
-43
No files matched your search
@@ -86,9 +86,23 @@ def list_directory_member_agents(agent_id: int, *, active_only: bool = False) ->
|
||||
return query.all()
|
||||
|
||||
|
||||
def serialize_directory_member(agent: Agent) -> dict[str, Any]:
|
||||
"""Serialize one member Agent for Admin and Dify runtime metadata."""
|
||||
return {
|
||||
def serialize_directory_member(
|
||||
agent: Agent,
|
||||
*,
|
||||
active_only: bool = False,
|
||||
max_depth: int = 0,
|
||||
visited_ids: set[int] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Serialize one member Agent for Admin, user navigation, and Dify metadata.
|
||||
|
||||
Args:
|
||||
active_only: True 时只展开启用中的子应用。
|
||||
max_depth: 允许向下展开的聚合层级,避免用户列表中聚合子应用丢失展开能力。
|
||||
visited_ids: 已访问 Agent ID,用于防止循环配置导致递归。
|
||||
"""
|
||||
is_aggregate = bool(getattr(agent, 'is_aggregate', False))
|
||||
payload = {
|
||||
'id': agent.id,
|
||||
'name': agent.name,
|
||||
'description': agent.description,
|
||||
@@ -97,12 +111,41 @@ def serialize_directory_member(agent: Agent) -> dict[str, Any]:
|
||||
'dify_app_id': agent.dify_app_id,
|
||||
'category': agent.category,
|
||||
'sub_category': agent.sub_category,
|
||||
'sort_order': int(getattr(agent, 'sort_order', 0) or 0),
|
||||
'is_aggregate': is_aggregate,
|
||||
}
|
||||
if is_aggregate and max_depth > 0:
|
||||
next_visited = set(visited_ids or set())
|
||||
if agent.id not in next_visited:
|
||||
next_visited.add(agent.id)
|
||||
payload['directory_members'] = serialize_directory_members(
|
||||
agent.id,
|
||||
active_only=active_only,
|
||||
max_depth=max_depth - 1,
|
||||
visited_ids=next_visited,
|
||||
)
|
||||
return payload
|
||||
|
||||
|
||||
def serialize_directory_members(agent_id: int, *, active_only: bool = False) -> list[dict[str, Any]]:
|
||||
def serialize_directory_members(
|
||||
agent_id: int,
|
||||
*,
|
||||
active_only: bool = False,
|
||||
max_depth: int = 0,
|
||||
visited_ids: set[int] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Serialize configured member Agents for a directory Agent."""
|
||||
visited = set(visited_ids or set())
|
||||
if agent_id in visited:
|
||||
return []
|
||||
visited.add(agent_id)
|
||||
return [
|
||||
serialize_directory_member(agent)
|
||||
serialize_directory_member(
|
||||
agent,
|
||||
active_only=active_only,
|
||||
max_depth=max_depth,
|
||||
visited_ids=visited,
|
||||
)
|
||||
for agent in list_directory_member_agents(agent_id, active_only=active_only)
|
||||
if agent.id not in visited
|
||||
]
|
||||
Reference in new issue
Block a user