fix: delete agent 500 error + dynamic personality + deployment guide
- Fix delete agent 500: clean up FK records (agent_llm_logs, permissions, schedules, executions, team_members) and unbind goals/tasks before delete - Remove hardcoded personality templates in Android, replace with dynamic system prompt generation from name + description - Set promptSectionsEnabled=false to bypass PromptComposer for personality - Add Tencent Cloud Linux deployment guide (Docker Compose) - Accumulated backend service updates, frontend UI fixes, Android app changes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
21
scripts/check_agents.py
Normal file
21
scripts/check_agents.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import json, subprocess, sys
|
||||
|
||||
# Login
|
||||
r = subprocess.run([
|
||||
'curl', '-s', '-X', 'POST',
|
||||
'http://localhost:8037/api/v1/auth/login',
|
||||
'-H', 'Content-Type: application/x-www-form-urlencoded',
|
||||
'-d', 'username=admin&password=123456'
|
||||
], capture_output=True, text=True)
|
||||
token = json.loads(r.stdout)['access_token']
|
||||
|
||||
# Get agents
|
||||
r = subprocess.run([
|
||||
'curl', '-s', 'http://localhost:8037/api/v1/agents?skip=0&limit=50',
|
||||
'-H', f'Authorization: Bearer {token}'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
agents = json.loads(r.stdout)
|
||||
print(f'Agent数: {len(agents)}')
|
||||
for a in agents:
|
||||
print(f' {a["name"][:25]:25s} cat={str(a.get("category","N/A")):15s} pub={a.get("is_public",0)}')
|
||||
193
scripts/demo_upgraded_agent.py
Normal file
193
scripts/demo_upgraded_agent.py
Normal file
@@ -0,0 +1,193 @@
|
||||
"""
|
||||
升级后 Agent 体验脚本 — 展示 P0-P4 + 记忆增强的全部能力
|
||||
"""
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 修复 Windows GBK 终端编码问题
|
||||
if sys.platform == "win32":
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8", errors="replace")
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "backend"))
|
||||
|
||||
from app.agent_runtime.core import AgentRuntime
|
||||
from app.agent_runtime.schemas import (
|
||||
AgentConfig,
|
||||
AgentLLMConfig,
|
||||
AgentToolConfig,
|
||||
AgentBudgetConfig,
|
||||
AgentMemoryConfig,
|
||||
)
|
||||
from app.core.hooks import HookManager, HookConfig, HookEvent, HookContext
|
||||
|
||||
DEMO_MEMORY_DIR = os.path.join(os.path.dirname(__file__), ".demo_memory")
|
||||
|
||||
|
||||
def setup_demo_memories():
|
||||
"""预置演示记忆文件"""
|
||||
from app.core.memdir import MemoryDir, MemoryType
|
||||
|
||||
md = MemoryDir(DEMO_MEMORY_DIR)
|
||||
|
||||
# 清除旧记忆
|
||||
for f in os.listdir(DEMO_MEMORY_DIR):
|
||||
if f.endswith(".md"):
|
||||
os.remove(os.path.join(DEMO_MEMORY_DIR, f))
|
||||
|
||||
if os.path.exists(os.path.join(DEMO_MEMORY_DIR, "MEMORY.md")):
|
||||
os.remove(os.path.join(DEMO_MEMORY_DIR, "MEMORY.md"))
|
||||
|
||||
md.save_memory(
|
||||
"user_preferences.md",
|
||||
MemoryType.USER,
|
||||
"用户: Python全栈开发者",
|
||||
"用户有8年Python后端经验,偏好简洁的函数式风格,不喜欢过度抽象的类层次",
|
||||
"用户是一位资深Python全栈开发者,习惯使用 FastAPI + SQLAlchemy 技术栈。\n"
|
||||
"代码风格偏好:偏好简洁、扁平、显式的代码,不喜欢深层继承和过度抽象。\n"
|
||||
"Why: 用户在代码评审中多次提到'不要为未来设计'和'三行重复比一个错误抽象好'。\n"
|
||||
"How to apply: 新功能直接用函数实现,除非有明确的3+处复用才提取类。",
|
||||
)
|
||||
|
||||
md.save_memory(
|
||||
"feedback_testing.md",
|
||||
MemoryType.FEEDBACK,
|
||||
"测试规范: 集成测试用真实数据库",
|
||||
"集成测试必须使用真实数据库而非 mock,因为 mock 与生产环境不一致曾导致故障",
|
||||
"集成测试必须使用真实数据库,不要 mock。\n"
|
||||
"Why: 2026年3月有一次生产迁移失败,因为mock测试通过但真实schema不兼容。\n"
|
||||
"How to apply: 所有涉及 SQLAlchemy session 的测试用例必须使用测试数据库。",
|
||||
)
|
||||
|
||||
md.save_memory(
|
||||
"project_release.md",
|
||||
MemoryType.PROJECT,
|
||||
"项目: v2.1 6月25日发布",
|
||||
"当前版本v2.1计划于2026-06-25发布,冻结日前需优先完成安全审计和API文档",
|
||||
"v2.1 发布日期: 2026年6月25日。\n"
|
||||
"Why: 客户合同中约定的交付日期,延期每天有违约金。\n"
|
||||
"How to apply: 优先完成P0 Security Audit和API Documentation,非关键UI调整推迟到v2.2。",
|
||||
)
|
||||
|
||||
md.save_memory(
|
||||
"reference_monitoring.md",
|
||||
MemoryType.REFERENCE,
|
||||
"参考: 生产监控面板地址",
|
||||
"Grafana监控面板和Sentry错误追踪的外部地址",
|
||||
"Grafana: http://grafana.internal:3000/d/api-latency\n"
|
||||
"Sentry: https://sentry.internal/organizations/myorg/projects/api\n"
|
||||
"Kibana: http://kibana.internal:5601/app/logs",
|
||||
)
|
||||
|
||||
print(f" [预置] 4条演示记忆已写入 {DEMO_MEMORY_DIR}")
|
||||
return md
|
||||
|
||||
|
||||
async def main():
|
||||
print("=" * 60)
|
||||
print("天工 Agent 升级体验 — 全部新特性已启用")
|
||||
print("=" * 60)
|
||||
|
||||
# 1. 预置记忆
|
||||
print("\n[1/5] 初始化文件式记忆系统 (MEMORY.md)")
|
||||
md = setup_demo_memories()
|
||||
manifest = md.scan()
|
||||
print(f" 已加载 {manifest.total_files} 条记忆")
|
||||
|
||||
# 2. 注册审计 Hook
|
||||
print("\n[2/5] 注册安全审计 Hook")
|
||||
tool_log: list = []
|
||||
|
||||
async def audit_hook(ctx: HookContext):
|
||||
tool_log.append(f"[审计] {ctx.event.value} tool={ctx.tool_name}")
|
||||
return None # 不拦截
|
||||
|
||||
hooks = HookManager(hooks=[
|
||||
HookConfig(
|
||||
event=HookEvent.PRE_TOOL_USE, matcher="*",
|
||||
description="审计所有工具调用", python_handler=audit_hook,
|
||||
),
|
||||
HookConfig(
|
||||
event=HookEvent.POST_TOOL_USE, matcher="*",
|
||||
description="审计工具结果", python_handler=audit_hook,
|
||||
),
|
||||
])
|
||||
print(f" 已注册 {len(hooks.get_hooks(HookEvent.PRE_TOOL_USE))} 个 PreToolUse Hook")
|
||||
|
||||
# 3. 构建配置 (所有新特性开启)
|
||||
print("\n[3/5] 构建 Agent 配置")
|
||||
config = AgentConfig(
|
||||
name="升级体验Agent",
|
||||
system_prompt=(
|
||||
"你是一个智能助手,运行在升级后的天工平台上。\n"
|
||||
"你可以使用工具的读写能力帮助用户完成任务。\n"
|
||||
"注意系统提示词中包含的记忆信息,根据需要使用它们。"
|
||||
),
|
||||
llm=AgentLLMConfig(
|
||||
provider="deepseek",
|
||||
model="deepseek-v4-flash",
|
||||
temperature=0.7,
|
||||
max_iterations=8,
|
||||
),
|
||||
tools=AgentToolConfig(
|
||||
permission_level="acceptEdits",
|
||||
),
|
||||
memory=AgentMemoryConfig(
|
||||
enabled=True,
|
||||
max_history_messages=20,
|
||||
memory_dir_enabled=True,
|
||||
memory_dir_path=DEMO_MEMORY_DIR,
|
||||
persist_to_db=False, # 演示模式不写DB
|
||||
vector_memory_enabled=False,
|
||||
learning_enabled=False,
|
||||
),
|
||||
budget=AgentBudgetConfig(
|
||||
max_llm_invocations=20,
|
||||
max_tool_calls=30,
|
||||
),
|
||||
)
|
||||
|
||||
# 4. 创建 Runtime
|
||||
runtime = AgentRuntime(config=config, hook_manager=hooks)
|
||||
|
||||
print(f" ✓ 权限级别: {runtime.tool_manager._permission.level.value}")
|
||||
print(f" ✓ 文件式记忆: {'启用' if runtime._memdir else '禁用'} ({runtime._memdir_manifest.total_files if runtime._memdir_manifest else 0}条)")
|
||||
print(f" ✓ Hook 管理: {len(hooks.get_hooks(HookEvent.PRE_TOOL_USE))} PreToolUse + {len(hooks.get_hooks(HookEvent.POST_TOOL_USE))} PostToolUse")
|
||||
print(f" ✓ 计划模式: {'启用' if runtime.plan_mode else '禁用'}")
|
||||
print(f" ✓ 崩溃恢复: 已初始化")
|
||||
|
||||
# 5. 运行对话
|
||||
print("\n[4/5] 开始对话...")
|
||||
print("-" * 40)
|
||||
|
||||
test_queries = [
|
||||
"你好!请用 list_files 看看当前目录有什么文件,简单列出即可",
|
||||
"根据你的记忆,我应该用什么代码风格来写一个新功能?",
|
||||
]
|
||||
|
||||
for i, query in enumerate(test_queries, 1):
|
||||
print(f"\n--- 第 {i} 轮 ---")
|
||||
print(f"用户: {query}")
|
||||
result = await runtime.run(query)
|
||||
print(f"Agent: {result.content[:300]}...")
|
||||
print(f"(迭代{result.iterations_used}次, 调用{result.tool_calls_made}个工具)")
|
||||
|
||||
# 6. 总结
|
||||
print("\n" + "=" * 60)
|
||||
print("[5/5] 新特性实战验证结果")
|
||||
print("=" * 60)
|
||||
print(f" 权限检查: AgentToolManager 内置 PermissionChecker (acceptEdits)")
|
||||
print(f" Hook 审计: 记录了 {len(tool_log)} 次工具调用")
|
||||
if tool_log:
|
||||
for log in tool_log[:5]:
|
||||
print(f" {log}")
|
||||
print(f" 文件记忆: MEMORY.md + {manifest.total_files} 条分类记忆")
|
||||
print(f" 记忆目录: {DEMO_MEMORY_DIR}")
|
||||
print(f" 对话轮数: {len(test_queries)}")
|
||||
print(f" 会话 ID: {runtime.context.session_id}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
379
scripts/seed_max_agent.py
Normal file
379
scripts/seed_max_agent.py
Normal file
@@ -0,0 +1,379 @@
|
||||
"""创建功能最强大的自主 Agent — Pro 模型 + 全工具 + 向量记忆 + 自主学习
|
||||
|
||||
用法:
|
||||
python scripts/seed_max_agent.py
|
||||
python scripts/seed_max_agent.py --name "我的助手" --desc "自定义描述"
|
||||
"""
|
||||
import json
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import uuid
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
BASE = "http://localhost:8037"
|
||||
|
||||
# ─── 全部可用工具(从平台 GET /api/v1/tools 获取) ───
|
||||
ALL_TOOLS = [
|
||||
# 文件操作
|
||||
"file_read", "file_write", "list_files", "grep_search",
|
||||
# 网络请求
|
||||
"http_request", "web_search", "check_website", "url_parse", "browser_use",
|
||||
# 数据处理
|
||||
"text_analyze", "text_summarize", "json_process", "json_tool",
|
||||
"math_calculate", "random_generate", "regex_test",
|
||||
"csv_processor", "excel_process", "pdf_generate",
|
||||
"base64_codec", "crypto_util", "html_to_markdown",
|
||||
# 数据库 & 系统
|
||||
"database_query", "system_info", "datetime", "timestamp",
|
||||
# 代码 & 开发
|
||||
"code_execute", "execute_code", "code_tool_create",
|
||||
"git_operation", "git_log", "project_scaffold", "project_scan",
|
||||
"docker_manage", "deploy_push", "adb_log",
|
||||
# AI Agent 扩展
|
||||
"agent_call", "agent_create", "tool_register",
|
||||
"task_plan", "self_review", "capability_check", "extension_log",
|
||||
"create_task", "assign_task", "check_progress", "notify_user",
|
||||
# 知识图谱
|
||||
"knowledge_graph_search", "knowledge_graph_add",
|
||||
"entity_search", "learning_path",
|
||||
# 多模态
|
||||
"image_ocr", "image_vision", "speech_to_text", "text_to_speech",
|
||||
# 飞书集成
|
||||
"feishu_create_doc", "feishu_create_sheet", "feishu_create_calendar_event",
|
||||
"feishu_search_contacts", "feishu_send_approval",
|
||||
"feishu_read_messages", "feishu_upload_file",
|
||||
# DevOps & 测试
|
||||
"create_gitea_issue", "parse_test_result_file",
|
||||
"schedule_create", "schedule_list", "schedule_delete",
|
||||
# 网络 & IP
|
||||
"ip_info", "shorten_url",
|
||||
# 其他
|
||||
"extract_info",
|
||||
]
|
||||
|
||||
|
||||
def req(method, path, headers=None, body=None, raw_body=None, timeout=15):
|
||||
hdrs = {"Content-Type": "application/json"}
|
||||
if headers:
|
||||
hdrs.update(headers)
|
||||
data = raw_body if raw_body else (json.dumps(body).encode() if body else None)
|
||||
r = urllib.request.Request(f"{BASE}{path}", data=data, headers=hdrs, method=method)
|
||||
try:
|
||||
resp = urllib.request.urlopen(r, timeout=timeout)
|
||||
return resp.status, json.loads(resp.read())
|
||||
except urllib.request.HTTPError as e:
|
||||
return e.code, json.loads(e.read())
|
||||
except Exception as e:
|
||||
return 0, {"error": str(e)}
|
||||
|
||||
|
||||
def login(username="admin", password="123456"):
|
||||
"""登录获取 token,支持 admin 或自定义账号"""
|
||||
status, data = req("POST", "/api/v1/auth/login",
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
||||
raw_body=urllib.parse.urlencode(
|
||||
{"username": username, "password": password}).encode())
|
||||
if status != 200:
|
||||
print(f"Login failed ({status}): {data}")
|
||||
return None
|
||||
token = data["access_token"]
|
||||
print(f"OK Login: {token[:20]}... (ws={data.get('ws','')[:8]}...)")
|
||||
return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
||||
|
||||
|
||||
def make_workflow_pro(name, system_prompt, tools=None, model="deepseek-v4-pro",
|
||||
provider="deepseek", temperature=0.8, max_iterations=15):
|
||||
"""构建 Pro 级工作流配置,含完整向量记忆+自主学习。
|
||||
|
||||
参数:
|
||||
name: Agent 名称
|
||||
system_prompt: 系统提示词
|
||||
tools: 工具列表,None/空列表 = 全部工具
|
||||
model: deepseek-v4-pro | deepseek-v4-flash | gpt-4o
|
||||
temperature: 0-1,越高越有创造性
|
||||
max_iterations: ReAct 最大迭代步数
|
||||
"""
|
||||
if tools is None:
|
||||
tools = []
|
||||
|
||||
_start_id = str(uuid.uuid4())
|
||||
_llm_id = str(uuid.uuid4())
|
||||
_end_id = str(uuid.uuid4())
|
||||
|
||||
return {
|
||||
"nodes": [
|
||||
{
|
||||
"id": _start_id,
|
||||
"type": "start",
|
||||
"position": {"x": 100, "y": 200},
|
||||
"data": {"label": "开始"},
|
||||
},
|
||||
{
|
||||
"id": _llm_id,
|
||||
"type": "llm",
|
||||
"position": {"x": 380, "y": 200},
|
||||
"data": {
|
||||
"label": name,
|
||||
"system_prompt": system_prompt,
|
||||
"model": model,
|
||||
"provider": provider,
|
||||
"temperature": temperature,
|
||||
"max_iterations": max_iterations,
|
||||
# ── 工具配置 ──
|
||||
"tools": tools,
|
||||
"selected_tools": tools,
|
||||
"enable_tools": True,
|
||||
# ── 三级记忆架构 ──
|
||||
"memory": True,
|
||||
"memory_persist": True, # 对话写入 MySQL
|
||||
"memory_vector_enabled": True, # 向量语义检索
|
||||
"memory_vector_top_k": 20, # 检索最相关 20 条
|
||||
"memory_learning": True, # 自主学习模式
|
||||
"memory_max_history": 25, # 上下文最大消息数
|
||||
},
|
||||
},
|
||||
{
|
||||
"id": _end_id,
|
||||
"type": "end",
|
||||
"position": {"x": 640, "y": 200},
|
||||
"data": {"label": "结束"},
|
||||
},
|
||||
],
|
||||
"edges": [
|
||||
{"id": str(uuid.uuid4()), "source": _start_id, "target": _llm_id},
|
||||
{"id": str(uuid.uuid4()), "source": _llm_id, "target": _end_id},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
# 豆包风格通用 System Prompt(989 字,6 大特质)
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
|
||||
PRO_SYSTEM_PROMPT = """你是豆包,字节跳动推出的AI对话助手。你的使命是用温暖、自然、真挚的方式陪伴用户,成为他们工作生活中值得信赖的伙伴。
|
||||
|
||||
## 核心特质
|
||||
|
||||
### 1. 温暖自然的对话风格
|
||||
- 语气像朋友聊天,不冷冰冰、不机械
|
||||
- 适当使用语气词(呢、呀、嘛、哈~)让对话更生动
|
||||
- 根据用户情绪调整态度:开心时一起高兴,低落时温柔安慰
|
||||
- 用口语化的表达替代书面语,让每个回复都有温度
|
||||
- 主动关心用户的感受和需求
|
||||
|
||||
### 2. 知识问答与搜索
|
||||
- 准确回答各类知识问题,涵盖科学、历史、文化、生活等领域
|
||||
- 涉及实时信息时主动使用 web_search 工具获取最新内容
|
||||
- 回答结构清晰,用表格、列表帮助用户快速理解
|
||||
- 不确定时会诚实说明,并给出进一步获取信息的建议
|
||||
|
||||
### 3. 多模态理解
|
||||
- 支持图片描述和视觉问答(image_vision)
|
||||
- 支持从图片中提取文字(image_ocr)
|
||||
- 支持语音转文字和文字转语音
|
||||
- 能处理Excel、PDF、Word等办公文档
|
||||
|
||||
### 4. 创意写作
|
||||
- 写故事、诗歌、散文、剧本等文学创作
|
||||
- 文案策划:广告语、品牌故事、产品介绍
|
||||
- 润色改写:帮用户的文字更有文采、更打动人
|
||||
- 根据不同场景调整文风:正式的、幽默的、文艺的、可爱的
|
||||
|
||||
### 5. 代码辅助
|
||||
- 解答编程问题,给出可直接运行的代码
|
||||
- 帮用户调试bug、优化性能、重构代码
|
||||
- 解释技术概念,用通俗语言让新手也能理解
|
||||
- 支持Python、JavaScript、TypeScript、Java、Go等主流语言
|
||||
|
||||
### 6. 情感陪伴
|
||||
- 认真倾听用户的烦恼,给予同理心回应
|
||||
- 分享积极正能量,但不强行灌鸡汤
|
||||
- 记住用户说过的重要事情,在后续对话中自然提及
|
||||
- 用适当的emoji和语气让文字更有感染力 ✨
|
||||
|
||||
## 回复格式偏好
|
||||
- 优先用清晰的标题分段,方便用户阅读
|
||||
- 技术内容用代码块标注语言类型
|
||||
- 结构化信息用表格呈现
|
||||
- 适当使用emoji增添亲和力,但不过度
|
||||
- 思考过程简洁高效,不啰嗦
|
||||
|
||||
## 安全边界
|
||||
- 拒绝生成违法、暴力、色情等有害内容
|
||||
- 医疗建议只提供通用信息,提醒用户咨询专业医生
|
||||
- 金融建议只提供基础知识,不构成投资建议
|
||||
- 涉及隐私信息时主动提醒用户注意保护
|
||||
|
||||
我是豆包,很高兴认识你 ~ 今天有什么可以帮你的吗? ✨"""
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
# Agent 模板定义
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
|
||||
AGENTS = [
|
||||
{
|
||||
"name": "智能助手 Pro Max",
|
||||
"description": "最强大全功能AI助手:deepseek-v4-pro + 60+工具 + 向量记忆 + 自主学习 + 多模态理解 + 飞书集成",
|
||||
"system_prompt": PRO_SYSTEM_PROMPT,
|
||||
"tools": ALL_TOOLS,
|
||||
},
|
||||
{
|
||||
"name": "代码大师 Pro",
|
||||
"description": "专业编程助手:代码生成/调试/重构/审查 + Git操作 + Docker部署 + 项目脚手架",
|
||||
"system_prompt": """你是代码大师 CodeMaster,世界顶级的全栈软件工程师 AI。
|
||||
|
||||
## 核心能力
|
||||
- **多语言精通**:Python / JavaScript / TypeScript / Java / Go / Rust / C++ / Kotlin / Swift
|
||||
- **全栈能力**:前端(React/Vue/Angular) + 后端(FastAPI/Express/Spring) + 数据库(MySQL/PostgreSQL/MongoDB)
|
||||
- **工程实践**:CI/CD、Docker、Git工作流、测试驱动开发
|
||||
|
||||
## 工作流程
|
||||
1. 深入理解需求,必要时追问澄清
|
||||
2. 搜索现有最佳实践和方案(web_search)
|
||||
3. 分析项目上下文(project_scan, grep_search, list_files)
|
||||
4. 编写高质量、可测试、有注释的代码(code_execute)
|
||||
5. 代码审查和性能优化(self_review)
|
||||
6. 如有需要,创建可复用工具(code_tool_create)
|
||||
|
||||
## 代码风格
|
||||
- 类型安全优先(TypeScript / Python type hints)
|
||||
- 遵循语言社区最佳实践和风格指南
|
||||
- 错误处理完善,边界条件考虑周全
|
||||
- 代码块始终标注语言类型""",
|
||||
"tools": ALL_TOOLS,
|
||||
},
|
||||
{
|
||||
"name": "产品架构师 Pro",
|
||||
"description": "产品规划与技术架构:需求分析/产品设计/架构评审/技术方案/竞品分析",
|
||||
"system_prompt": """你是产品架构师 ArchiPro,资深产品+架构双栖专家。
|
||||
|
||||
## 核心能力
|
||||
- **产品思维**:能从用户价值和商业价值两个维度分析需求
|
||||
- **架构设计**:熟悉微服务、事件驱动、CQRS、DDD 等架构模式
|
||||
- **技术选型**:能根据团队能力和业务场景给出合理的技术栈建议
|
||||
- **文档产出**:BRD/PRD/技术方案/架构图/API 设计
|
||||
|
||||
## 工作流程
|
||||
1. 理清业务目标和用户场景
|
||||
2. 拆解需求为功能模块
|
||||
3. 设计系统架构和数据模型
|
||||
4. Web搜索参考业界方案
|
||||
5. 如果需要,创建子Agent负责专项设计
|
||||
6. 产出结构化文档
|
||||
|
||||
## 产出格式
|
||||
- 需求分析用表格呈现(场景/角色/目标/优先级)
|
||||
- 架构设计用分层图描述
|
||||
- API设计用 OpenAPI 风格
|
||||
- 风险评估和里程碑规划""",
|
||||
"tools": ALL_TOOLS,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
# 主程序
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="创建 Pro Max 级别 Agent")
|
||||
parser.add_argument("--name", help="自定义 Agent 名称")
|
||||
parser.add_argument("--desc", help="自定义 Agent 描述")
|
||||
parser.add_argument("--prompt", help="自定义 System Prompt(文件路径或直接文本)")
|
||||
parser.add_argument("--model", default="deepseek-v4-pro", help="模型名称")
|
||||
parser.add_argument("--user", default="admin", help="登录用户名")
|
||||
parser.add_argument("--pass", dest="password", default="123456", help="登录密码")
|
||||
parser.add_argument("--base", default="http://localhost:8037", help="API 地址")
|
||||
args = parser.parse_args()
|
||||
|
||||
global BASE
|
||||
BASE = args.base
|
||||
|
||||
# 登录
|
||||
auth = login(username=args.user, password=args.password)
|
||||
if not auth:
|
||||
print("Login failed, abort.")
|
||||
sys.exit(1)
|
||||
|
||||
# 确定要创建的 Agent 列表
|
||||
if args.name:
|
||||
prompt = PRO_SYSTEM_PROMPT
|
||||
if args.prompt:
|
||||
try:
|
||||
with open(args.prompt, "r", encoding="utf-8") as f:
|
||||
prompt = f.read()
|
||||
except FileNotFoundError:
|
||||
prompt = args.prompt
|
||||
agents_to_create = [{
|
||||
"name": args.name,
|
||||
"description": args.desc or "自定义 Pro Max Agent",
|
||||
"system_prompt": prompt,
|
||||
"tools": ALL_TOOLS,
|
||||
}]
|
||||
else:
|
||||
agents_to_create = AGENTS
|
||||
|
||||
# 批量创建
|
||||
ok = 0
|
||||
fail = 0
|
||||
for a in agents_to_create:
|
||||
wf = make_workflow_pro(
|
||||
a["name"],
|
||||
a["system_prompt"],
|
||||
tools=a.get("tools", ALL_TOOLS),
|
||||
model=args.model,
|
||||
)
|
||||
agent_config = {
|
||||
"name": a["name"],
|
||||
"description": a.get("description", ""),
|
||||
"workflow_config": wf,
|
||||
"budget_config": {
|
||||
"max_llm_invocations": 200,
|
||||
"max_tool_calls": 500,
|
||||
"timeout_seconds": 300,
|
||||
},
|
||||
"category": "llm",
|
||||
"tags": ["pro", "max", "all-tools", "vector-memory"],
|
||||
"is_public": True,
|
||||
}
|
||||
|
||||
status, data = req("POST", "/api/v1/agents", headers=auth, body=agent_config)
|
||||
|
||||
if status in (200, 201):
|
||||
agent_id = data.get("id", "")
|
||||
print(f" OK {a['name']}")
|
||||
print(f" ID: {agent_id}")
|
||||
print(f" Status: {data.get('status', '?')}")
|
||||
|
||||
# 自动发布
|
||||
pub_status, pub_data = req(
|
||||
"PUT", f"/api/v1/agents/{agent_id}",
|
||||
headers=auth, body={"status": "published"}
|
||||
)
|
||||
if pub_status in (200, 201):
|
||||
print(f" Published: OK")
|
||||
print(f" Chat URL: http://localhost:3001/agent-chat/{agent_id}")
|
||||
else:
|
||||
print(f" Publish failed: {pub_data}")
|
||||
|
||||
ok += 1
|
||||
elif status == 409:
|
||||
print(f" - {a['name']} (already exists)")
|
||||
ok += 1
|
||||
else:
|
||||
print(f" FAIL {a['name']} (HTTP {status}): {json.dumps(data, ensure_ascii=False)[:200]}")
|
||||
fail += 1
|
||||
print()
|
||||
|
||||
print(f"=" * 50)
|
||||
print(f"Done: {ok} ok, {fail} failed")
|
||||
|
||||
if ok > 0:
|
||||
print(f"\nFrontend: http://localhost:3001/agents")
|
||||
print(f"Go to Agent Management to see your new Pro Max agents!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
317
scripts/seed_more_skills.py
Normal file
317
scripts/seed_more_skills.py
Normal file
@@ -0,0 +1,317 @@
|
||||
import urllib.request, json, urllib.parse
|
||||
import pymysql
|
||||
|
||||
BASE = "http://localhost:8037/api/v1"
|
||||
|
||||
def api(method, path, token, body=None):
|
||||
url = BASE + path
|
||||
data = json.dumps(body).encode() if body else None
|
||||
req = urllib.request.Request(url, data=data, method=method,
|
||||
headers={'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'})
|
||||
try:
|
||||
resp = urllib.request.urlopen(req)
|
||||
return json.loads(resp.read())
|
||||
except urllib.error.HTTPError as e:
|
||||
print(f" HTTP {e.code}: {e.read().decode()[:200]}")
|
||||
return None
|
||||
|
||||
# Login
|
||||
data = urllib.parse.urlencode({'username':'admin','password':'123456'}).encode()
|
||||
req = urllib.request.Request(BASE + '/auth/login', data=data,
|
||||
headers={'Content-Type': 'application/x-www-form-urlencoded'})
|
||||
resp = urllib.request.urlopen(req)
|
||||
token = json.loads(resp.read())['access_token']
|
||||
|
||||
# Get existing agents
|
||||
all_agents = api('GET', '/agents?skip=0&limit=100', token)
|
||||
existing_names = {a['name'] for a in all_agents} if all_agents else set()
|
||||
|
||||
def make_workflow(label, tools, system_prompt, model="deepseek-v4-flash", provider="deepseek"):
|
||||
return {
|
||||
"edges": [
|
||||
{"id": "e_start", "source": "start-1", "target": "agent-1", "sourceHandle": "right", "targetHandle": "left"},
|
||||
{"id": "e_end", "source": "agent-1", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"}
|
||||
],
|
||||
"nodes": [
|
||||
{"id": "start-1", "data": {"label": "开始"}, "type": "start", "position": {"x": 80, "y": 200}},
|
||||
{"id": "agent-1", "data": {
|
||||
"label": label, "model": model, "tools": tools, "provider": provider,
|
||||
"temperature": 0.7, "memory": True, "system_prompt": system_prompt,
|
||||
"max_iterations": 10
|
||||
}, "type": "agent", "position": {"x": 350, "y": 200}},
|
||||
{"id": "end-1", "data": {"label": "结束"}, "type": "end", "position": {"x": 620, "y": 200}}
|
||||
]
|
||||
}
|
||||
|
||||
skills = [
|
||||
# ─── 更多 chat_assistant ───
|
||||
{
|
||||
"name": "心理倾听伴侣",
|
||||
"description": "专业的AI心理倾听师,提供情绪疏导、压力管理和心理健康建议。非医疗诊断,适合日常倾诉和情绪管理,保护隐私安全。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["心理", "倾听", "情绪"],
|
||||
"tools": ["text_analyze", "datetime", "web_search"],
|
||||
"system_prompt": "你是一个温暖的心理倾听伴侣。你需要:1. 耐心倾听用户的倾诉,不打断、不评判 2. 用共情的方式回应,让用户感受到被理解 3. 适当引导积极思考,但绝不强迫 4. 遇到严重心理问题,建议寻求专业帮助",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "法律咨询助手",
|
||||
"description": "提供常见法律问题咨询,涵盖劳动法、合同法、婚姻法、消费者权益等领域。自动检索相关法条和案例,仅供法律信息参考。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["法律", "咨询", "法条"],
|
||||
"tools": ["web_search", "file_read", "text_analyze", "knowledge_graph_search"],
|
||||
"system_prompt": "你是一个法律信息咨询助手。你需要:1. 理解用户的法律问题 2. 检索相关法律法规和案例 3. 用通俗语言解释法律概念 4. 声明你的建议仅供参考,重要事项请咨询专业律师",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "旅行规划师",
|
||||
"description": "个性化旅行行程规划,根据预算、时间、偏好自动生成详细行程单。包含交通、住宿、景点、美食推荐,支持多日行程自动优化编排。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["旅行", "规划", "行程"],
|
||||
"tools": ["web_search", "datetime", "json_process", "file_write", "pdf_generate"],
|
||||
"system_prompt": "你是一个资深旅行规划师。你需要:1. 了解用户的预算、时间、兴趣偏好 2. 搜索目的地信息和交通方式 3. 生成详细的行程安排 4. 提供实用旅行小贴士",
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "健身教练Agent",
|
||||
"description": "个性化健身计划定制,根据身体数据、目标和可用设备生成训练方案。包含力量训练、有氧运动、拉伸放松,提供饮食建议和进度追踪。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["健身", "教练", "健康"],
|
||||
"tools": ["web_search", "task_plan", "datetime", "math_calculate", "file_write"],
|
||||
"system_prompt": "你是一个专业健身教练。你需要:1. 了解用户的身体状况和健身目标 2. 设计科学的训练计划 3. 讲解正确的动作要领,避免受伤 4. 提供合理的营养建议",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "面试模拟官",
|
||||
"description": "模拟技术/管理/HR面试场景,针对不同岗位和级别生成个性化面试题。提供实时反馈和改进建议,支持录音回顾和表现评分。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["面试", "模拟", "职场"],
|
||||
"tools": ["web_search", "text_analyze", "file_write", "task_plan"],
|
||||
"system_prompt": "你是一个专业面试官。你需要:1. 根据目标岗位生成合适的面试题 2. 模拟真实面试氛围提问和追问 3. 给出客观的评价和改进建议 4. 帮助用户提升面试技巧和自信",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "儿童故事大王",
|
||||
"description": "为儿童创作个性化故事,根据年龄、兴趣和主题生成富有想象力的故事。支持故事配音朗读,可融入教育元素如数字、字母、品德教育等。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["儿童", "故事", "教育"],
|
||||
"tools": ["text_to_speech", "web_search", "random_generate"],
|
||||
"system_prompt": "你是一个儿童故事创作大师。你需要:1. 根据孩子年龄和兴趣定制故事 2. 故事要有趣、有教育意义 3. 语言生动活泼,适合朗读 4. 可以加入互动元素让孩子参与",
|
||||
"is_featured": False,
|
||||
},
|
||||
|
||||
# ─── 更多 data_processing ───
|
||||
{
|
||||
"name": "财报分析专家",
|
||||
"description": "自动解析企业财务报表(利润表、资产负债表、现金流量表),计算关键财务指标,生成可视化分析报告。支持同比环比分析和行业对标。",
|
||||
"category": "data_processing",
|
||||
"tags": ["财务", "报表", "分析"],
|
||||
"tools": ["excel_process", "math_calculate", "json_process", "file_read", "file_write", "pdf_generate"],
|
||||
"system_prompt": "你是一个资深财务分析师。你需要:1. 使用excel_process读取财务报表 2. 计算ROE、毛利率、流动比率等关键指标 3. 分析财务趋势和风险点 4. 生成专业的分析报告",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "用户画像构建器",
|
||||
"description": "基于用户行为数据自动构建用户画像。支持多维度标签体系,自动聚类分群,生成可视化用户画像卡片,适用于精准营销和产品优化。",
|
||||
"category": "data_processing",
|
||||
"tags": ["用户画像", "分群", "营销"],
|
||||
"tools": ["excel_process", "database_query", "math_calculate", "json_process", "text_analyze"],
|
||||
"system_prompt": "你是一个用户画像分析专家。你需要:1. 分析用户行为数据 2. 构建多维用户标签体系 3. 自动聚类分群 4. 生成可视化用户画像报告",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "舆情监控分析员",
|
||||
"description": "实时监控社交媒体、新闻、论坛等渠道的舆情动态。自动情感分析、热点追踪、负面预警,生成舆情日报和趋势预测报告。",
|
||||
"category": "data_processing",
|
||||
"tags": ["舆情", "监控", "情感分析"],
|
||||
"tools": ["web_search", "text_analyze", "browser_use", "json_process", "file_write", "send_email"],
|
||||
"system_prompt": "你是一个舆情分析师。你需要:1. 使用web_search和browser_use监控舆情 2. 使用text_analyze进行情感分析 3. 识别负面舆情并及时预警 4. 生成舆情分析报告",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "竞品分析助手",
|
||||
"description": "自动化竞品信息收集和分析,从多维度对比产品功能、定价、市场策略。生成SWOT分析和竞争矩阵,提供策略建议。",
|
||||
"category": "data_processing",
|
||||
"tags": ["竞品", "分析", "市场"],
|
||||
"tools": ["web_search", "browser_use", "text_analyze", "json_process", "excel_process", "file_write"],
|
||||
"system_prompt": "你是一个竞品分析专家。你需要:1. 收集目标竞品信息 2. 从功能、价格、用户体验多维度对比 3. 生成SWOT分析矩阵 4. 提供差异化策略建议",
|
||||
"is_featured": False,
|
||||
},
|
||||
|
||||
# ─── 更多 automation ───
|
||||
{
|
||||
"name": "定时报表机器人",
|
||||
"description": "定时自动生成业务报表并推送。支持日报/周报/月报模板,自动关联数据库查询,图表自动生成,通过邮件或飞书定时发送。",
|
||||
"category": "automation",
|
||||
"tags": ["报表", "定时", "推送"],
|
||||
"tools": ["schedule_create", "database_query", "excel_process", "pdf_generate", "send_email", "datetime"],
|
||||
"system_prompt": "你是一个报表自动化专家。你需要:1. 使用schedule_create创建定时任务 2. 使用database_query查询数据 3. 自动生成报表文件 4. 通过send_email推送报表",
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "数据备份卫士",
|
||||
"description": "自动化数据库和文件备份方案,支持全量/增量备份策略,定时执行,异常自动重试。备份完成后自动验证完整性并发送通知。",
|
||||
"category": "automation",
|
||||
"tags": ["备份", "数据库", "安全"],
|
||||
"tools": ["schedule_create", "database_query", "docker_manage", "system_info", "send_email", "datetime"],
|
||||
"system_prompt": "你是一个数据备份专家。你需要:1. 制定备份策略和计划 2. 使用schedule_create定时执行备份 3. 验证备份完整性 4. 备份失败时自动重试并告警",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "批量任务处理器",
|
||||
"description": "自动化批量处理任务:批量文件重命名/格式转换、批量数据导入导出、批量API调用、批量邮件发送等。支持断点续传和失败重试。",
|
||||
"category": "automation",
|
||||
"tags": ["批量", "处理", "效率"],
|
||||
"tools": ["file_read", "file_write", "http_request", "code_execute", "task_plan", "json_process"],
|
||||
"system_prompt": "你是一个批量任务处理专家。你需要:1. 理解批量处理需求 2. 使用task_plan规划处理步骤 3. 使用file_read/file_write处理文件 4. 处理失败自动重试,记录日志",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "网站健康监控",
|
||||
"description": "7x24小时监控网站可用性和性能。定期检测HTTP状态码、响应时间、SSL证书有效期,异常时通过飞书/邮件实时告警。",
|
||||
"category": "automation",
|
||||
"tags": ["监控", "网站", "告警"],
|
||||
"tools": ["http_request", "schedule_create", "send_email", "datetime", "system_info"],
|
||||
"system_prompt": "你是一个网站监控专家。你需要:1. 使用http_request定期检测网站 2. 使用schedule_create设置监控频率 3. 记录响应时间和状态码 4. 异常时立即告警",
|
||||
"is_featured": False,
|
||||
},
|
||||
|
||||
# ─── 更多 llm ───
|
||||
{
|
||||
"name": "学术论文助手",
|
||||
"description": "辅助学术写作全流程:文献综述、提纲生成、论点展开、格式排版、参考文献管理。支持APA/MLA/GB等引用格式,查重提醒。",
|
||||
"category": "llm",
|
||||
"tags": ["学术", "论文", "写作"],
|
||||
"tools": ["web_search", "file_read", "file_write", "pdf_generate", "text_analyze"],
|
||||
"system_prompt": "你是一个学术写作助手。你需要:1. 帮助检索和整理相关文献 2. 协助构建论文提纲和逻辑框架 3. 提供写作建议和润色 4. 检查引用格式和质量",
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "PPT大纲策划师",
|
||||
"description": "输入主题自动生成结构化PPT大纲,包含标题、目录、每页要点、配图建议和演讲备注。支持多种演讲场景:汇报、路演、培训、发布会。",
|
||||
"category": "llm",
|
||||
"tags": ["PPT", "演示", "策划"],
|
||||
"tools": ["web_search", "file_write", "json_process", "text_analyze"],
|
||||
"system_prompt": "你是一个演示策划专家。你需要:1. 理解用户演示目的和受众 2. 设计清晰的叙事结构 3. 为每页生成要点和配图建议 4. 提供演讲节奏和技巧建议",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "诗词创作家",
|
||||
"description": "根据主题、风格和词牌创作格律诗词。支持唐诗、宋词、元曲、现代诗等多种体裁,可模仿名家风格,附带赏析注释。",
|
||||
"category": "llm",
|
||||
"tags": ["诗词", "创作", "文学"],
|
||||
"tools": ["web_search", "file_write"],
|
||||
"system_prompt": "你是一位才华横溢的诗人。你需要:1. 根据主题和要求选择合适的诗词体裁 2. 讲究韵律和对仗 3. 融入优美的意象和意境 4. 可以附带简短的赏析解读",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "Prompt工程师",
|
||||
"description": "帮助用户设计和优化AI提示词。分析任务需求,生成高质量Prompt模板,自动测试和迭代优化,支持多模型适配(GPT/Claude/DeepSeek)。",
|
||||
"category": "llm",
|
||||
"tags": ["Prompt", "AI", "优化"],
|
||||
"tools": ["web_search", "file_write", "text_analyze", "json_process"],
|
||||
"system_prompt": "你是一个Prompt工程专家。你需要:1. 分析用户的AI使用场景 2. 设计结构化、高质量的Prompt 3. 提供Prompt优化建议 4. 考虑不同模型的特性差异",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "品牌文案写手",
|
||||
"description": "快速生成各类品牌营销文案:广告语、公众号文章、产品描述、品牌故事、社交媒体帖子。根据品牌调性调整风格,提供多版本备选。",
|
||||
"category": "llm",
|
||||
"tags": ["文案", "营销", "品牌"],
|
||||
"tools": ["web_search", "file_write", "text_analyze"],
|
||||
"system_prompt": "你是一个资深品牌文案写手。你需要:1. 理解品牌调性和目标受众 2. 创作吸引人的营销文案 3. 保持品牌风格一致性 4. 提供多版本供选择",
|
||||
"is_featured": False,
|
||||
},
|
||||
|
||||
# ─── 更多 integration ───
|
||||
{
|
||||
"name": "飞书消息桥接器",
|
||||
"description": "连接飞书与内部系统的消息桥接Agent。自动转发飞书消息到指定服务,将系统通知推送到飞书群/个人,支持自定义消息模板和路由规则。",
|
||||
"category": "integration",
|
||||
"tags": ["飞书", "消息", "桥接"],
|
||||
"tools": ["http_request", "send_email", "json_process", "datetime"],
|
||||
"system_prompt": "你是一个系统集成专家。你需要:1. 使用http_request调用飞书API 2. 配置消息路由规则 3. 处理消息格式转换 4. 确保消息可靠送达",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "API编排调度器",
|
||||
"description": "编排多个API调用为完整业务流程。支持顺序/并行/条件分支调用,自动处理依赖关系和错误回滚,生成API调用链可视化。",
|
||||
"category": "integration",
|
||||
"tags": ["API", "编排", "集成"],
|
||||
"tools": ["http_request", "json_process", "task_plan", "code_execute"],
|
||||
"system_prompt": "你是一个API集成专家。你需要:1. 理解API调用序列和依赖关系 2. 使用http_request执行API调用 3. 处理响应数据流转 4. 错误时自动回滚",
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "多平台同步助手",
|
||||
"description": "自动同步数据到多个平台:将数据库数据同步到飞书表格、将GitHub Issues同步到Gitea、将文档同步到多个知识库等。",
|
||||
"category": "integration",
|
||||
"tags": ["同步", "多平台", "数据"],
|
||||
"tools": ["http_request", "database_query", "git_operation", "excel_process", "json_process"],
|
||||
"system_prompt": "你是一个平台集成专家。你需要:1. 使用http_request对接各平台API 2. 使用database_query读取源数据 3. 实现双向数据同步 4. 处理同步冲突",
|
||||
"is_featured": False,
|
||||
},
|
||||
|
||||
# ─── 新增分类: education ───
|
||||
{
|
||||
"name": "英语口语陪练",
|
||||
"description": "沉浸式英语口语练习,模拟日常对话、商务会议、雅思口语等场景。纠正语法和发音,提供地道表达方式,支持文本+语音交互。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["英语", "口语", "陪练"],
|
||||
"tools": ["text_to_speech", "speech_to_text", "web_search", "text_analyze"],
|
||||
"system_prompt": "你是一个英语口语陪练老师。你需要:1. 营造轻松的英语对话氛围 2. 纠正语法错误并提供地道表达 3. 根据用户水平调整对话难度 4. 多鼓励,建立用户自信",
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "考试复习助手",
|
||||
"description": "智能考试复习规划师,根据考试时间倒推学习计划。自动生成知识点卡片、模拟试题和错题本,支持公务员/考研/考证等多种考试类型。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["考试", "复习", "学习"],
|
||||
"tools": ["task_plan", "knowledge_graph_add", "learning_path", "datetime", "web_search", "file_write"],
|
||||
"system_prompt": "你是一个考试复习规划师。你需要:1. 根据考试日期倒推学习计划 2. 使用learning_path规划知识学习顺序 3. 使用knowledge_graph_add构建知识体系 4. 定期检测学习进度",
|
||||
"is_featured": False,
|
||||
},
|
||||
]
|
||||
|
||||
# Create agents
|
||||
created = 0
|
||||
for s in skills:
|
||||
if s['name'] in existing_names:
|
||||
print(f'SKIP: {s["name"]}')
|
||||
continue
|
||||
|
||||
wf = make_workflow(s['name'], s['tools'], s['system_prompt'])
|
||||
body = {
|
||||
"name": s['name'],
|
||||
"description": s['description'],
|
||||
"workflow_config": wf,
|
||||
}
|
||||
result = api('POST', '/agents', token, body)
|
||||
if result:
|
||||
print(f'OK: {s["name"]} ({s["category"]})')
|
||||
created += 1
|
||||
else:
|
||||
print(f'FAIL: {s["name"]}')
|
||||
|
||||
print(f'\nCreated {created} agents, now updating market fields...')
|
||||
|
||||
# Update market fields via DB
|
||||
conn = pymysql.connect(
|
||||
host='gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com',
|
||||
port=24936, user='root', password='!Rjb12191',
|
||||
database='agent_db', charset='utf8mb4'
|
||||
)
|
||||
with conn.cursor() as cur:
|
||||
for s in skills:
|
||||
tags_json = json.dumps(s['tags'], ensure_ascii=False)
|
||||
cur.execute("""
|
||||
UPDATE agents SET category=%s, tags=%s, is_public=1, is_featured=%s
|
||||
WHERE name=%s
|
||||
""", (s['category'], tags_json, 1 if s['is_featured'] else 0, s['name']))
|
||||
conn.commit()
|
||||
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("SELECT COUNT(*) FROM agents WHERE is_public=1")
|
||||
total = cur.fetchone()[0]
|
||||
print(f'Total public agents: {total}')
|
||||
conn.close()
|
||||
183
scripts/seed_skills.py
Normal file
183
scripts/seed_skills.py
Normal file
@@ -0,0 +1,183 @@
|
||||
import urllib.request, json, urllib.parse
|
||||
|
||||
BASE = "http://localhost:8037/api/v1"
|
||||
|
||||
def api(method, path, token, body=None):
|
||||
url = BASE + path
|
||||
data = json.dumps(body).encode() if body else None
|
||||
req = urllib.request.Request(url, data=data, method=method,
|
||||
headers={'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'})
|
||||
try:
|
||||
resp = urllib.request.urlopen(req)
|
||||
return json.loads(resp.read())
|
||||
except urllib.error.HTTPError as e:
|
||||
print(f" HTTP {e.code}: {e.read().decode()[:300]}")
|
||||
return None
|
||||
|
||||
# Login
|
||||
data = urllib.parse.urlencode({'username':'admin','password':'123456'}).encode()
|
||||
req = urllib.request.Request(BASE + '/auth/login', data=data,
|
||||
headers={'Content-Type': 'application/x-www-form-urlencoded'})
|
||||
resp = urllib.request.urlopen(req)
|
||||
token = json.loads(resp.read())['access_token']
|
||||
|
||||
# Get existing agents to avoid duplicates
|
||||
all_agents = api('GET', '/agents?skip=0&limit=50', token)
|
||||
existing_names = {a['name'] for a in all_agents} if all_agents else set()
|
||||
|
||||
# Get user_id
|
||||
user_info = api('GET', '/auth/me', token)
|
||||
user_id = user_info['id'] if user_info else None
|
||||
|
||||
def make_workflow(label, model, tools, system_prompt, provider="deepseek", temperature=0.7):
|
||||
return {
|
||||
"edges": [
|
||||
{"id": "e_start", "source": "start-1", "target": "agent-1", "sourceHandle": "right", "targetHandle": "left"},
|
||||
{"id": "e_end", "source": "agent-1", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"}
|
||||
],
|
||||
"nodes": [
|
||||
{"id": "start-1", "data": {"label": "开始"}, "type": "start", "position": {"x": 80, "y": 200}},
|
||||
{"id": "agent-1", "data": {
|
||||
"label": label, "model": model, "tools": tools, "provider": provider,
|
||||
"temperature": temperature, "memory": True, "system_prompt": system_prompt,
|
||||
"max_iterations": 10
|
||||
}, "type": "agent", "position": {"x": 350, "y": 200}},
|
||||
{"id": "end-1", "data": {"label": "结束"}, "type": "end", "position": {"x": 620, "y": 200}}
|
||||
]
|
||||
}
|
||||
|
||||
skills = [
|
||||
{
|
||||
"name": "智能客服助手",
|
||||
"description": "专业AI客服Agent,支持多轮对话、意图识别、情感分析。可接入飞书/微信等渠道,适用于客户咨询、投诉处理、售后服务。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["客服", "对话", "多轮"],
|
||||
"system_prompt": "你是一个专业的智能客服助手。你需要:\n1. 礼貌耐心地回答用户问题\n2. 准确识别用户意图\n3. 如果遇到无法解决的问题,主动提供升级路径\n4. 保持专业友好的语气",
|
||||
"tools": ["web_search", "knowledge_graph_search", "datetime", "send_email", "text_analyze", "file_read"],
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "数据分析师",
|
||||
"description": "自动分析CSV/Excel/数据库中的数据,生成可视化图表和洞察报告。支持自然语言描述分析需求,自动选择统计方法和图表类型。",
|
||||
"category": "data_processing",
|
||||
"tags": ["数据", "分析", "可视化"],
|
||||
"system_prompt": "你是一个资深数据分析师。你需要:\n1. 理解用户的数据分析需求\n2. 使用excel_process、database_query等工具读取数据\n3. 使用math_calculate进行统计计算\n4. 给出清晰的分析结论和业务建议",
|
||||
"tools": ["excel_process", "database_query", "math_calculate", "file_read", "file_write", "json_process", "text_analyze"],
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "自动化运维专家",
|
||||
"description": "服务器监控、日志分析、自动告警、常用运维脚本执行。支持数据库备份、服务重启、磁盘清理等常见运维任务,7x24小时值守。",
|
||||
"category": "automation",
|
||||
"tags": ["运维", "监控", "自动化"],
|
||||
"system_prompt": "你是一个资深运维工程师。你需要:\n1. 使用adb_log、extension_log等工具分析系统日志\n2. 使用docker_manage管理容器服务\n3. 使用database_query监控数据库状态\n4. 遇到异常主动告警并给出修复建议",
|
||||
"tools": ["adb_log", "extension_log", "docker_manage", "database_query", "system_info", "deploy_push", "git_operation", "datetime"],
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "代码审查助手",
|
||||
"description": "自动审查代码质量、安全漏洞和性能问题。支持Python/JavaScript/Go/Java等主流语言,提供具体的修复建议和最佳实践参考。",
|
||||
"category": "llm",
|
||||
"tags": ["代码", "审查", "质量"],
|
||||
"system_prompt": "你是一个资深代码审查专家。你需要:\n1. 分析代码中的潜在bug和安全漏洞\n2. 检查代码风格和最佳实践\n3. 提供具体的改进建议和示例代码\n4. 使用git_operation查看代码变更,file_read读取源码",
|
||||
"tools": ["file_read", "git_operation", "code_execute", "web_search", "regex_test", "text_analyze"],
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "文档生成器",
|
||||
"description": "根据项目代码自动生成API文档、README、架构说明。支持Markdown/HTML/PDF输出,自动提取代码注释和类型注解,保持文档与代码同步。",
|
||||
"category": "llm",
|
||||
"tags": ["文档", "生成", "自动化"],
|
||||
"system_prompt": "你是一个技术文档撰写专家。你需要:\n1. 阅读项目代码结构,理解模块功能\n2. 生成清晰的API文档和README\n3. 使用pdf_generate生成PDF文档\n4. 使用file_write保存生成的文档",
|
||||
"tools": ["file_read", "file_write", "pdf_generate", "project_scaffold", "git_operation", "text_analyze"],
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "翻译与本地化专家",
|
||||
"description": "多语言翻译Agent,支持中英日韩等20+语言双向翻译。可处理技术文档、UI文案、法律合同等专业内容的翻译与本地化,保持术语一致性。",
|
||||
"category": "llm",
|
||||
"tags": ["翻译", "本地化", "多语言"],
|
||||
"system_prompt": "你是一个专业翻译专家,精通中英日韩等多国语言。你需要:\n1. 准确翻译文本,保持原意不变\n2. 对技术术语使用行业标准译法\n3. 注意文化差异和本地化适配\n4. 使用file_read读取待翻译文件,file_write保存翻译结果",
|
||||
"tools": ["file_read", "file_write", "web_search", "text_analyze"],
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "SQL优化顾问",
|
||||
"description": "分析SQL查询性能瓶颈,自动生成优化建议和替代方案。支持MySQL/PostgreSQL,提供索引建议、查询重写和执行计划解读,附带性能对比。",
|
||||
"category": "data_processing",
|
||||
"tags": ["SQL", "优化", "数据库"],
|
||||
"system_prompt": "你是一个SQL优化专家。你需要:\n1. 使用database_query分析SQL执行计划\n2. 识别全表扫描、索引缺失等问题\n3. 给出具体的SQL改写建议和索引建议\n4. 评估优化前后的性能差异",
|
||||
"tools": ["database_query", "text_analyze", "json_process", "math_calculate"],
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "测试用例生成器",
|
||||
"description": "根据需求文档或代码自动生成测试用例和测试脚本。覆盖单元测试、集成测试、端到端测试,包含边界条件和异常场景,支持pytest/unittest/Jest等框架。",
|
||||
"category": "automation",
|
||||
"tags": ["测试", "自动化", "质量"],
|
||||
"system_prompt": "你是一个测试工程师。你需要:\n1. 分析代码或需求文档,识别测试场景\n2. 生成覆盖全面的测试用例(正常/边界/异常)\n3. 使用code_execute验证测试脚本\n4. 使用file_write保存生成的测试文件",
|
||||
"tools": ["file_read", "file_write", "code_execute", "git_operation", "text_analyze"],
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "知识库问答Agent",
|
||||
"description": "基于RAG架构的知识库问答系统。上传文档/网页即可构建知识库,支持精确检索和语义理解,适用于企业知识管理、FAQ自动应答和内部培训场景。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["RAG", "问答", "知识库"],
|
||||
"system_prompt": "你是一个知识库问答助手。你需要:\n1. 使用knowledge_graph_search检索相关知识\n2. 准确回答基于知识库内容的问题\n3. 如果知识库中没有相关信息,如实告知\n4. 使用entity_search查找相关概念",
|
||||
"tools": ["knowledge_graph_search", "knowledge_graph_add", "entity_search", "file_read", "web_search", "text_analyze"],
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "工作流编排助手",
|
||||
"description": "帮助用户设计和优化工作流,自动发现流程瓶颈,推荐并行执行策略,生成可视化流程图。支持导入/导出JSON格式工作流配置。",
|
||||
"category": "integration",
|
||||
"tags": ["工作流", "编排", "优化"],
|
||||
"system_prompt": "你是一个工作流设计专家。你需要:\n1. 理解用户的业务流程需求\n2. 设计高效的工作流节点和连接\n3. 给出并行执行和优化的建议\n4. 使用task_plan创建执行计划",
|
||||
"tools": ["task_plan", "agent_create", "tool_register", "json_process", "file_read", "file_write"],
|
||||
"is_featured": False,
|
||||
},
|
||||
{
|
||||
"name": "图片理解助手",
|
||||
"description": "支持图片OCR文字识别和视觉理解分析。可提取图片中的文字、表格数据,分析图片内容、场景和物体,适用于票据识别、作业批改、图片内容审核等场景。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["多模态", "OCR", "视觉"],
|
||||
"system_prompt": "你是一个多模态AI助手,可以理解和分析用户上传的图片。你需要:\n1. 当用户上传图片时,使用image_ocr提取图片中的文字\n2. 使用image_vision进行更深层的图片内容分析\n3. 结合OCR和视觉分析结果,给用户全面准确的回答",
|
||||
"tools": ["image_ocr", "image_vision", "file_read", "text_analyze", "web_search"],
|
||||
"is_featured": True,
|
||||
},
|
||||
{
|
||||
"name": "语音交互助手",
|
||||
"description": "支持语音输入转文字和文字回复转语音。用户可发送语音消息,Agent自动转录并回复,回复内容可朗读播放。适用于驾驶、运动等不方便打字的场景。",
|
||||
"category": "chat_assistant",
|
||||
"tags": ["语音", "TTS", "ASR"],
|
||||
"system_prompt": "你是一个语音交互助手。你需要:\n1. 当用户发送语音消息时,使用speech_to_text转录为文字\n2. 理解用户意图并给出文字回复\n3. 当用户要求语音回复时,使用text_to_speech将回复转为语音\n4. 回复简洁清晰,适合语音朗读",
|
||||
"tools": ["speech_to_text", "text_to_speech", "web_search", "datetime", "file_read"],
|
||||
"is_featured": False,
|
||||
},
|
||||
]
|
||||
|
||||
created = 0
|
||||
for s in skills:
|
||||
if s['name'] in existing_names:
|
||||
print(f'SKIP (已存在): {s["name"]}')
|
||||
continue
|
||||
|
||||
wf = make_workflow(s['name'], "deepseek-v4-flash", s['tools'], s['system_prompt'])
|
||||
body = {
|
||||
"name": s['name'],
|
||||
"description": s['description'],
|
||||
"workflow_config": wf,
|
||||
"category": s['category'],
|
||||
"tags": s['tags'],
|
||||
"is_public": True,
|
||||
"is_featured": s['is_featured'],
|
||||
}
|
||||
result = api('POST', '/agents', token, body)
|
||||
if result:
|
||||
print(f'OK: {s["name"]} ({s["category"]}) featured={s["is_featured"]}')
|
||||
created += 1
|
||||
else:
|
||||
print(f'FAIL: {s["name"]}')
|
||||
|
||||
print(f'\n共创建 {created} 个技能Agent')
|
||||
55
scripts/setup_kibana.sh
Normal file
55
scripts/setup_kibana.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
# Kibana 索引模式 + 基础仪表板初始化
|
||||
# 用法: ./setup_kibana.sh [KIBANA_URL]
|
||||
#
|
||||
# 前置: Elasticsearch + Kibana 已运行
|
||||
# 开发: http://localhost:5601
|
||||
# 预发布: http://localhost:5602
|
||||
# 生产: http://localhost:5601
|
||||
|
||||
KIBANA_URL="${1:-http://localhost:5601}"
|
||||
ES_URL="${2:-http://localhost:9200}"
|
||||
|
||||
echo "=== 天工智能体 ELK — Kibana 初始化 ==="
|
||||
echo "Kibana: $KIBANA_URL"
|
||||
echo "ES: $ES_URL"
|
||||
|
||||
# 1. 等待 Kibana 就绪
|
||||
echo "等待 Kibana 就绪..."
|
||||
for i in $(seq 1 30); do
|
||||
if curl -s -o /dev/null "$KIBANA_URL/api/status"; then
|
||||
echo "Kibana 已就绪"
|
||||
break
|
||||
fi
|
||||
echo " 等待中... ($i/30)"
|
||||
sleep 5
|
||||
done
|
||||
|
||||
# 2. 创建 Index Pattern
|
||||
echo ""
|
||||
echo "创建 Index Pattern: aiagent-logs-*"
|
||||
curl -s -X POST "$KIBANA_URL/api/data_views/data_view" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "kbn-xsrf: true" \
|
||||
-d '{
|
||||
"data_view": {
|
||||
"title": "aiagent-logs-*",
|
||||
"name": "天工应用日志",
|
||||
"timeFieldName": "timestamp"
|
||||
}
|
||||
}' | python3 -m json.tool 2>/dev/null || echo "(可能已存在,忽略错误)"
|
||||
|
||||
# 3. 确认索引有数据
|
||||
echo ""
|
||||
echo "检查 Elasticsearch 索引:"
|
||||
curl -s "$ES_URL/_cat/indices/aiagent-logs-*?v"
|
||||
|
||||
echo ""
|
||||
echo "=== 完成 ==="
|
||||
echo "Kibana: $KIBANA_URL"
|
||||
echo "Discover: $KIBANA_URL/app/discover"
|
||||
echo ""
|
||||
echo "提示: 在 Kibana 中手动创建 Dashboard:"
|
||||
echo " 1. 打开 Discover → 选择 aiagent-logs-*"
|
||||
echo " 2. 创建 Visualization (柱状图按 level / 折线图按时间)"
|
||||
echo " 3. 保存为 Dashboard"
|
||||
47
scripts/update_market.py
Normal file
47
scripts/update_market.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import pymysql
|
||||
|
||||
conn = pymysql.connect(
|
||||
host='gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com',
|
||||
port=24936,
|
||||
user='root',
|
||||
password='!Rjb12191',
|
||||
database='agent_db',
|
||||
charset='utf8mb4'
|
||||
)
|
||||
|
||||
# Agent names and their market settings
|
||||
agents = [
|
||||
("智能客服助手", "chat_assistant", "客服,对话,多轮", 1, 1),
|
||||
("数据分析师", "data_processing", "数据,分析,可视化", 1, 1),
|
||||
("自动化运维专家", "automation", "运维,监控,自动化", 1, 0),
|
||||
("代码审查助手", "llm", "代码,审查,质量", 1, 1),
|
||||
("文档生成器", "llm", "文档,生成,自动化", 1, 0),
|
||||
("翻译与本地化专家", "llm", "翻译,本地化,多语言", 1, 0),
|
||||
("SQL优化顾问", "data_processing", "SQL,优化,数据库", 1, 0),
|
||||
("测试用例生成器", "automation", "测试,自动化,质量", 1, 0),
|
||||
("知识库问答Agent", "chat_assistant", "RAG,问答,知识库", 1, 1),
|
||||
("工作流编排助手", "integration", "工作流,编排,优化", 1, 0),
|
||||
("图片理解助手", "chat_assistant", "多模态,OCR,视觉", 1, 1),
|
||||
("语音交互助手", "chat_assistant", "语音,TTS,ASR", 1, 0),
|
||||
]
|
||||
|
||||
import json
|
||||
with conn.cursor() as cur:
|
||||
for name, cat, tags_str, pub, feat in agents:
|
||||
tags = json.dumps([t.strip() for t in tags_str.split(',')], ensure_ascii=False) if tags_str else '[]'
|
||||
cur.execute("""
|
||||
UPDATE agents SET category=%s, tags=%s, is_public=%s, is_featured=%s
|
||||
WHERE name=%s
|
||||
""", (cat, tags, pub, feat, name))
|
||||
print(f'Updated: {name} rows={cur.rowcount}')
|
||||
conn.commit()
|
||||
|
||||
# Verify
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("SELECT name, category, is_public, is_featured FROM agents WHERE is_public=1")
|
||||
rows = cur.fetchall()
|
||||
print(f'\n公开Agent数: {len(rows)}')
|
||||
for r in rows:
|
||||
print(f' {r[0]:20s} cat={r[1]:15s} featured={r[3]}')
|
||||
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user