Skip to content

Commit 606afc9

Browse files
committed
feat(agent): 添加强制刷新智能体详情的功能 Fixes #396
修改 fetchAgentDetail 方法支持强制刷新参数 更新上下文配置选项为动态获取 调整工具和MCP服务器列表为实时获取
1 parent 313f386 commit 606afc9

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/agents/chatbot/context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ class Context(BaseContext):
1313
default_factory=list,
1414
metadata={
1515
"name": "工具",
16-
"options": gen_tool_info(get_tools()), # 这里的选择是所有的工具
16+
"options": lambda: gen_tool_info(get_tools()), # 这里的选择是所有的工具
1717
"description": "工具列表",
1818
},
1919
)
2020

2121
mcps: list[str] = field(
2222
default_factory=list,
23-
metadata={"name": "MCP服务器", "options": list(MCP_SERVERS.keys()), "description": "MCP服务器列表"},
23+
metadata={
24+
"name": "MCP服务器",
25+
"options": lambda: list(MCP_SERVERS.keys()),
26+
"description": "MCP服务器列表",
27+
},
2428
)

src/agents/common/context.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ def get_configurable_items(cls):
107107
# 提取 Annotated 的元数据
108108
template_metadata = cls._extract_template_metadata(field_type)
109109

110+
options = f.metadata.get("options", [])
111+
if callable(options):
112+
options = options()
113+
110114
configurable_items[f.name] = {
111115
"type": type_name,
112116
"name": f.metadata.get("name", f.name),
113-
"options": f.metadata.get("options", []),
117+
"options": options,
114118
"default": f.default
115119
if f.default is not MISSING
116120
else f.default_factory()

web/src/components/AgentConfigSidebar.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ const getToolNameById = (toolId) => {
424424
const openToolsModal = async () => {
425425
console.log("availableTools.value", availableTools.value)
426426
try {
427+
// 强制刷新智能体详情以获取最新工具列表
428+
if (selectedAgentId.value) {
429+
await agentStore.fetchAgentDetail(selectedAgentId.value, true);
430+
}
427431
selectedTools.value = [...(agentConfig.value?.tools || [])];
428432
toolsModalOpen.value = true;
429433
} catch (error) {

web/src/stores/agent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ export const useAgentStore = defineStore('agent', () => {
146146
* 获取单个智能体的详细信息(包含配置选项)
147147
* @param {string} agentId - 智能体ID
148148
*/
149-
async function fetchAgentDetail(agentId) {
149+
async function fetchAgentDetail(agentId, forceRefresh = false) {
150150
if (!agentId) return
151151

152-
// 如果已经缓存了详细信息,直接返回
153-
if (agentDetails.value[agentId]) {
152+
// 如果已经缓存了详细信息且不强制刷新,直接返回
153+
if (!forceRefresh && agentDetails.value[agentId]) {
154154
return agentDetails.value[agentId]
155155
}
156156

0 commit comments

Comments
 (0)