Files
aiagent/backend/scripts/templates/template_customer_service.py
renjianbo 0608161c82 feat: 完善企业场景多线路由与执行稳定性
补齐平台模板与场景 DSL、预算控制、执行看板和企业场景脚本,增强 Windows 启动/迁移与前端代理和聊天会话记忆,修复执行创建阶段 500 与异步链路排障体验。

Made-with: Cursor
2026-04-09 21:58:53 +08:00

58 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
路线图场景模板:客服 — 通过 API 从模板创建 Agent。
用法:
cd backend && .\\venv\\Scripts\\python.exe scripts/templates/template_customer_service.py
环境变量: PLATFORM_BASE_URL, PLATFORM_USERNAME, PLATFORM_PASSWORD,
AGENT_NAME默认 场景模板_客服_时间戳 可不用), TARGET_NAME
"""
from __future__ import annotations
import os
import sys
import time
import requests
BASE = os.getenv("PLATFORM_BASE_URL", "http://127.0.0.1:8037").rstrip("/")
USER = os.getenv("PLATFORM_USERNAME", "admin")
PWD = os.getenv("PLATFORM_PASSWORD", "123456")
TEMPLATE_ID = "template_customer_service"
DEFAULT_NAME = os.getenv("TARGET_NAME") or f"场景模板_客服_{int(time.time())}"
def main() -> int:
r = requests.post(
f"{BASE}/api/v1/auth/login",
data={"username": USER, "password": PWD},
headers={"Content-Type": "application/x-www-form-urlencoded"},
timeout=15,
)
if r.status_code != 200:
print("登录失败:", r.status_code, r.text[:500], file=sys.stderr)
return 1
token = r.json().get("access_token")
if not token:
print("无 access_token", file=sys.stderr)
return 1
h = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
body = {
"template_id": TEMPLATE_ID,
"name": DEFAULT_NAME,
"description": "由 scripts/templates/template_customer_service.py 创建",
"parameters": {"temperature": 0.35},
}
cr = requests.post(f"{BASE}/api/v1/agents/from-scene-template", json=body, headers=h, timeout=60)
if cr.status_code not in (200, 201):
print("创建失败:", cr.status_code, cr.text[:800], file=sys.stderr)
return 1
print(cr.json().get("id"), cr.json().get("name"))
return 0
if __name__ == "__main__":
raise SystemExit(main())