Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ai
/
ai-workflow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 09368a15
authored
May 28, 2026
by
sunqi02
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix(agent): 更新从数据库同步 agent.code 的逻辑,调整关键字匹配方式
1 parent
aa87ab71
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
26 deletions
workspace/agent-admin/backend/app/config/loader.py
workspace/agent-admin/backend/app/config/settings.py
workspace/agent-admin/backend/app/config/loader.py
View file @
09368a1
...
...
@@ -41,41 +41,33 @@ class ConfigLoader:
def
sync_agent_codes_from_db
(
self
,
agents
:
Dict
[
str
,
AgentConfig
],
db_session
)
->
None
:
"""从
official_site_agent_display
表同步 agent.code,失败时保留 JSON 默认值。
"""从
ai_agents
表同步 agent.code,失败时保留 JSON 默认值。
根据 AGENT_CODE_SYNC_MAP 中的
映射,查询 DB 中 agent_name 对应的 agent_id
,
然后更新 AgentConfig.code = str(agent_id)
。
根据 AGENT_CODE_SYNC_MAP 中的
关键字,模糊匹配 ai_agents.name
,
将匹配到的 Agent.id 更新到 AgentConfig.code
。
"""
try
:
from
app.model.
official_site_agent_display
import
OfficialSiteAgentDisplay
from
app.model.
agent
import
Agent
target_names
=
list
(
AGENT_CODE_SYNC_MAP
.
keys
())
rows
=
(
db_session
.
query
(
OfficialSiteAgentDisplay
.
agent_name
,
OfficialSiteAgentDisplay
.
agent_id
,
)
.
filter
(
OfficialSiteAgentDisplay
.
agent_name
.
in_
(
target_names
))
.
all
()
)
name_to_id
=
{
row
.
agent_name
:
row
.
agent_id
for
row
in
rows
}
for
db_name
,
internal_key
in
AGENT_CODE_SYNC_MAP
.
items
():
for
keyword
,
internal_key
in
AGENT_CODE_SYNC_MAP
.
items
():
if
internal_key
not
in
agents
:
continue
agent_id
=
name_to_id
.
get
(
db_name
)
if
agent_id
is
not
None
:
row
=
(
db_session
.
query
(
Agent
.
id
)
.
filter
(
Agent
.
name
.
like
(
f
"
%
{keyword}
%
"
))
.
first
()
)
if
row
is
not
None
:
old_code
=
agents
[
internal_key
]
.
code
agents
[
internal_key
]
.
code
=
str
(
agent_
id
)
agents
[
internal_key
]
.
code
=
str
(
row
.
id
)
logger
.
info
(
"Agent code 已从 DB 同步:
%
s.code
%
s →
%
s"
,
internal_key
,
old_code
,
agent_
id
,
internal_key
,
old_code
,
row
.
id
,
)
else
:
logger
.
warning
(
"DB 中未找到
agent_name='
%
s'
,保留 JSON 默认值 code='
%
s'"
,
db_name
,
agents
[
internal_key
]
.
code
,
"DB 中未找到
name 包含'
%
s'的记录
,保留 JSON 默认值 code='
%
s'"
,
keyword
,
agents
[
internal_key
]
.
code
,
)
except
Exception
:
...
...
workspace/agent-admin/backend/app/config/settings.py
View file @
09368a1
...
...
@@ -2,11 +2,11 @@ from pydantic import BaseModel
from
typing
import
Dict
,
List
#
official_site_agent_display.agent_name
→ 内部 agent dict key
#
ai_agents.name 关键字
→ 内部 agent dict key
# 用于从 DB 同步 agent.code 值
AGENT_CODE_SYNC_MAP
:
Dict
[
str
,
str
]
=
{
"管家
Agent
"
:
"main"
,
"会议
agent
"
:
"meeting"
,
"管家"
:
"main"
,
"会议"
:
"meeting"
,
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment