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 01325b0b
authored
May 22, 2026
by
sunqi02
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
放弃修改ReAct循环的重写,采用框架的ReAct循环
1 parent
c9ad5e1e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
245 additions
and
14 deletions
workspace/agent-admin/backend/app/TEST_MODIFICATIONS.md
workspace/agent-admin/backend/app/api/v1/endpoints/agent_hub.py
workspace/agent-admin/backend/app/main.py
workspace/agent-admin/backend/config/models.json
workspace/agent-admin/backend/config/skills.json
workspace/agent-admin/backend/docs/superpowers/sunqi/plans/2026-05-22-agentscope-reactagent-refactor-plan.md
workspace/agent-admin/backend/scripts/seed_position_routing.py
workspace/agent-admin/backend/skills/README.md
workspace/agent-admin/backend/test_request.json
workspace/agent-admin/backend/app/TEST_MODIFICATIONS.md
View file @
01325b0
...
...
@@ -12,7 +12,21 @@ Base.metadata.create_all(bind=engine)
**还原:**
删除该行,后续数据库表由 migrations 管理。
## 2. main.py — ConsoleIMService(默认)
## 2. main.py — 导入所有模型表
**位置:**
`app/main.py:14-17`
```
python
from
app.model.agent
import
Agent
,
AgentPosition
,
AgentSkill
# noqa: F401
from
app.model.position_tag
import
PositionTag
,
OfficialTab
# noqa: F401
from
app.model.skill
import
Skill
# noqa: F401
```
**原因:**
`Base.metadata.create_all()`
只会创建已导入的模型对应的表。原代码只导入了
`app.model.session`
,导致
`ai_agents`
、
`ai_agent_positions`
、
`ai_agent_skills`
、
`position_tags`
、
`skills`
等表无法自动创建。
**还原:**
删除这些导入行,改由 migrations 管理建表。
## 3. main.py — ConsoleIMService(默认)
**位置:**
`app/main.py:27-34`
...
...
@@ -24,7 +38,7 @@ Base.metadata.create_all(bind=engine)
USE_CONSOLE_IM
=
false
IM_BASE_URL
=
http://your-im:8080
IM_API_KEY
=
xxx python -m app.main
```
##
3
. database.py — SQLite 默认
##
4
. database.py — SQLite 默认
**位置:**
`app/infrastructure/database.py:6-8`
...
...
@@ -36,6 +50,48 @@ USE_CONSOLE_IM=false IM_BASE_URL=http://your-im:8080 IM_API_KEY=xxx python -m ap
DATABASE_URL
=
mysql+pymysql://root:123456@localhost:3306/agent_admin?charset
=
utf8mb4 python -m app.main
```
## 4. 测试脚本
## 5. agent_hub endpoint — position_code 字段 + DB 查询
**位置:**
`app/api/v1/endpoints/agent_hub.py`
-
`ChatRequest`
新增
`position_code: Optional[str]`
字段
-
`chat`
端点新增
`db: Session = Depends(get_db)`
,查询
`PositionTag → AgentPosition → Agent`
链,解析出
`allowed_agent_codes`
**还原:**
删除
`position_code`
字段和 DB 查询逻辑,改由正式的业务层处理。
## 6. agent_hub service — 岗位过滤逻辑
**位置:**
`app/service/agent_hub.py`
-
`process_message()`
新增
`allowed_agent_codes: Optional[list]`
参数
-
路由判断:不在允许列表中的 agent 回退到 main(
`routing_reason: "position_restricted"`
)
-
`_build_main_prompt()`
新增过滤参数,只展示岗位允许的子 Agent
**还原:**
删除
`allowed_agent_codes`
参数及相关过滤逻辑。
## 7. 种子脚本
**位置:**
`scripts/seed_position_routing.py`
幂等种子脚本,创建测试数据:
-
`PositionTag(code="conference_assistant")`
-
`Skill(skill_code="meeting_minutes")`
-
`Agent(main, meeting)`
+
`AgentPosition`
+
`AgentSkill`
**还原:**
可删除,测试数据由正式 seed 流程管理。
## 8. test_request.json — 添加 position_code 字段
**位置:**
`test_request.json`
```
json
"position_code"
:
"conference_assistant"
```
**还原:**
将值改回
`null`
或删除该字段。
---
## 测试脚本
`send_test.sh`
+
`test_request.json`
— 开发验证用,可保留。
workspace/agent-admin/backend/app/api/v1/endpoints/agent_hub.py
View file @
01325b0
...
...
@@ -17,6 +17,7 @@ class ChatRequest(BaseModel):
query
:
str
=
Field
(
...
,
description
=
"用户问题"
)
mentioned_agent_code
:
Optional
[
str
]
=
Field
(
None
,
description
=
"@提及的Agent编码"
)
file_url
:
Optional
[
str
]
=
Field
(
None
,
description
=
"文件URL"
)
position_code
:
Optional
[
str
]
=
Field
(
None
,
description
=
"岗位编码"
)
class
ChatResponse
(
BaseModel
):
...
...
@@ -33,8 +34,36 @@ def get_agent_hub(db: Session = Depends(get_db)):
@router.post
(
"/completions"
,
response_model
=
ChatResponse
)
async
def
chat
(
request
:
ChatRequest
,
agent_hub
:
AgentHub
=
Depends
(
get_agent_hub
)):
async
def
chat
(
request
:
ChatRequest
,
agent_hub
:
AgentHub
=
Depends
(
get_agent_hub
),
db
:
Session
=
Depends
(
get_db
),
):
try
:
# Resolve position_code -> allowed agent codes
allowed_agent_codes
:
Optional
[
list
]
=
None
if
request
.
position_code
:
from
app.model.position_tag
import
PositionTag
from
app.model.agent
import
Agent
,
AgentPosition
pos_tag
=
db
.
query
(
PositionTag
)
.
filter
(
PositionTag
.
code
==
request
.
position_code
)
.
first
()
if
pos_tag
:
agent_ids
=
[
row
.
agent_id
for
row
in
db
.
query
(
AgentPosition
.
agent_id
)
.
filter
(
AgentPosition
.
position_id
==
pos_tag
.
id
)
.
all
()
]
if
agent_ids
:
agents
=
db
.
query
(
Agent
.
code
)
.
filter
(
Agent
.
id
.
in_
(
agent_ids
),
Agent
.
is_deleted
==
False
,
)
.
all
()
allowed_agent_codes
=
[
a
.
code
for
a
in
agents
]
result
=
await
agent_hub
.
process_message
(
session_id
=
request
.
session_id
,
room_id
=
request
.
room_id
,
...
...
@@ -42,7 +71,8 @@ async def chat(request: ChatRequest, agent_hub: AgentHub = Depends(get_agent_hub
user_query
=
request
.
query
,
mentioned_agent_code
=
request
.
mentioned_agent_code
,
channel
=
request
.
channel
,
file_url
=
request
.
file_url
file_url
=
request
.
file_url
,
allowed_agent_codes
=
allowed_agent_codes
,
)
return
ChatResponse
(
**
result
)
except
AgentHubError
as
e
:
...
...
workspace/agent-admin/backend/app/main.py
View file @
01325b0
...
...
@@ -9,6 +9,11 @@ from app.api.v1.router import api_router
from
app.config.loader
import
ConfigLoader
from
app.infrastructure.database
import
SessionLocal
,
engine
from
app.model.session
import
Base
# Register all model tables with Base.metadata so create_all works
from
app.model.agent
import
Agent
,
AgentPosition
,
AgentSkill
# noqa: F401
from
app.model.position_tag
import
PositionTag
,
OfficialTab
# noqa: F401
from
app.model.skill
import
Skill
# noqa: F401
from
app.schema.common
import
error_response_payload
,
is_wrapped_payload
,
success_response_payload
from
app.service.agent_hub
import
AgentHub
from
app.service.console_im_service
import
ConsoleIMService
...
...
workspace/agent-admin/backend/config/models.json
View file @
01325b0
...
...
@@ -2,14 +2,14 @@
"models"
:
{
"main"
:
{
"type"
:
"openai_compatible"
,
"api_base"
:
"https://
api.minimaxi.com
/v1"
,
"model_name"
:
"
MiniMax-M2.7
"
,
"api_base"
:
"https://
dashscope.aliyuncs.com/compatible-mode
/v1"
,
"model_name"
:
"
qwen3.6-plus
"
,
"api_key"
:
"sk-cp-22oeMKkLNyEJZY05vB9Bto-vjO45S_2mLVDzf4Q6hoI65k4Dc93Xz6MSgd1pzZDnWshXU4xEEBjs_cWjCLo1vfrcE9QpOUu287fnnYIPUt3sDp3uetzf5Z8"
},
"summary"
:
{
"type"
:
"openai_compatible"
,
"api_base"
:
"https://
api.minimaxi.com
/v1"
,
"model_name"
:
"
MiniMax-M2.7
"
,
"api_base"
:
"https://
dashscope.aliyuncs.com/compatible-mode
/v1"
,
"model_name"
:
"
qwen3.6-plus
"
,
"api_key"
:
"sk-cp-22oeMKkLNyEJZY05vB9Bto-vjO45S_2mLVDzf4Q6hoI65k4Dc93Xz6MSgd1pzZDnWshXU4xEEBjs_cWjCLo1vfrcE9QpOUu287fnnYIPUt3sDp3uetzf5Z8"
}
},
...
...
workspace/agent-admin/backend/config/skills.json
deleted
100644 → 0
View file @
c9ad5e1
{
"skills"
:
{}
}
\ No newline at end of file
workspace/agent-admin/backend/docs/superpowers/sunqi/plans/2026-05-22-agentscope-reactagent-refactor-plan.md
0 → 100644
View file @
01325b0
This diff is collapsed.
Click to expand it.
workspace/agent-admin/backend/scripts/seed_position_routing.py
0 → 100644
View file @
01325b0
"""
Seed script for position-based routing test data.
Idempotent: skips inserts when records already exist by unique key.
Creates:
- PositionTag: conference_assistant
- Skill: meeting_minutes
- Agent: main + meeting (if not exist)
- AgentPosition: link both agents to position
- AgentSkill: link meeting -> meeting_minutes
"""
import
sys
from
pathlib
import
Path
sys
.
path
.
insert
(
0
,
str
(
Path
(
__file__
)
.
resolve
()
.
parent
.
parent
))
from
app.infrastructure.database
import
SessionLocal
,
engine
,
Base
# Import all models so tables are created
from
app.model.agent
import
Agent
,
AgentPosition
,
AgentSkill
,
AgentStatus
# noqa: F401
from
app.model.position_tag
import
PositionTag
# noqa: F401
from
app.model.skill
import
Skill
# noqa: F401
Base
.
metadata
.
create_all
(
bind
=
engine
)
db
=
SessionLocal
()
try
:
# 1. PositionTag: conference_assistant
pos
=
db
.
query
(
PositionTag
)
.
filter
(
PositionTag
.
code
==
"conference_assistant"
)
.
first
()
if
not
pos
:
pos
=
PositionTag
(
name
=
"会议助手"
,
code
=
"conference_assistant"
,
description
=
"会议相关职能岗位"
,
)
db
.
add
(
pos
)
db
.
flush
()
print
(
"[OK] Created PositionTag: conference_assistant"
)
else
:
print
(
"[SKIP] PositionTag already exists: conference_assistant"
)
# 2. Skill: meeting_minutes
skill
=
db
.
query
(
Skill
)
.
filter
(
Skill
.
skill_code
==
"meeting_minutes"
)
.
first
()
if
not
skill
:
skill
=
Skill
(
skill_code
=
"meeting_minutes"
,
skill_name
=
"会议纪要"
,
description
=
"会议录音转写、纪要生成与文件导出"
,
priority
=
1
,
)
db
.
add
(
skill
)
db
.
flush
()
print
(
"[OK] Created Skill: meeting_minutes"
)
else
:
print
(
"[SKIP] Skill already exists: meeting_minutes"
)
# 3. Agent: main
main_agent
=
db
.
query
(
Agent
)
.
filter
(
Agent
.
code
==
"main"
,
Agent
.
is_deleted
==
False
,
)
.
first
()
if
not
main_agent
:
main_agent
=
Agent
(
name
=
"主 Agent"
,
code
=
"main"
,
description
=
"中央调度 Agent"
,
status
=
AgentStatus
.
enable
,
)
db
.
add
(
main_agent
)
db
.
flush
()
print
(
"[OK] Created Agent: main"
)
else
:
print
(
"[SKIP] Agent already exists: main"
)
# 4. Agent: meeting
meeting_agent
=
db
.
query
(
Agent
)
.
filter
(
Agent
.
code
==
"meeting"
,
Agent
.
is_deleted
==
False
,
)
.
first
()
if
not
meeting_agent
:
meeting_agent
=
Agent
(
name
=
"会议纪要 Agent"
,
code
=
"meeting"
,
description
=
"会议纪要助手"
,
status
=
AgentStatus
.
enable
,
)
db
.
add
(
meeting_agent
)
db
.
flush
()
print
(
"[OK] Created Agent: meeting"
)
else
:
print
(
"[SKIP] Agent already exists: meeting"
)
# 5. AgentPosition: main -> conference_assistant
main_pos
=
db
.
query
(
AgentPosition
)
.
filter
(
AgentPosition
.
agent_id
==
main_agent
.
id
,
AgentPosition
.
position_id
==
pos
.
id
,
)
.
first
()
if
not
main_pos
:
db
.
add
(
AgentPosition
(
agent_id
=
main_agent
.
id
,
position_id
=
pos
.
id
))
print
(
"[OK] Linked Agent 'main' to position 'conference_assistant'"
)
else
:
print
(
"[SKIP] AgentPosition main->conference_assistant already exists"
)
# 6. AgentPosition: meeting -> conference_assistant
meeting_pos
=
db
.
query
(
AgentPosition
)
.
filter
(
AgentPosition
.
agent_id
==
meeting_agent
.
id
,
AgentPosition
.
position_id
==
pos
.
id
,
)
.
first
()
if
not
meeting_pos
:
db
.
add
(
AgentPosition
(
agent_id
=
meeting_agent
.
id
,
position_id
=
pos
.
id
))
print
(
"[OK] Linked Agent 'meeting' to position 'conference_assistant'"
)
else
:
print
(
"[SKIP] AgentPosition meeting->conference_assistant already exists"
)
# 7. AgentSkill: meeting -> meeting_minutes
meeting_skill
=
db
.
query
(
AgentSkill
)
.
filter
(
AgentSkill
.
agent_id
==
meeting_agent
.
id
,
AgentSkill
.
skill_code
==
"meeting_minutes"
,
)
.
first
()
if
not
meeting_skill
:
db
.
add
(
AgentSkill
(
agent_id
=
meeting_agent
.
id
,
skill_code
=
"meeting_minutes"
))
print
(
"[OK] Linked Agent 'meeting' to skill 'meeting_minutes'"
)
else
:
print
(
"[SKIP] AgentSkill meeting->meeting_minutes already exists"
)
db
.
commit
()
print
(
"
\n
[DONE] Seed data ready for position-based routing test."
)
except
Exception
as
e
:
db
.
rollback
()
print
(
f
"[ERROR] {e}"
)
raise
finally
:
db
.
close
()
workspace/agent-admin/backend/skills/README.md
View file @
01325b0
skills 将会存放在这里
\ No newline at end of file
skills 将会存放在这里
-
meeting_minutes 会议录音转写、纪要生成与文件导出
\ No newline at end of file
workspace/agent-admin/backend/test_request.json
View file @
01325b0
...
...
@@ -5,5 +5,6 @@
"channel"
:
"wechat_group"
,
"query"
:
"{{QUERY}}"
,
"mentioned_agent_code"
:
null
,
"file_url"
:
null
"file_url"
:
null
,
"position_code"
:
"conference_assistant"
}
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