Files
MathModelAgent/backend/app/core/functions.py
T
MuWinds ac57ad0c18 refactor: 重构 LLM Provider 模式、WebSocket 重连、图表字体跨平台兼容 (#70)
LLM 层重构:
- 将 LLM 调用层重构为 Provider 模式,支持多 API 类型
- 新增 Anthropic、OpenAI Chat、OpenAI Responses 三种 Provider
- 新增 LLM 类型定义和工厂类

WebSocket 重连:
- 添加指数退避自动重连机制(初始 1s,最大 30s,最多 10 次)
- 区分手动关闭与意外断开,仅意外断开触发重连
- 在任务页面顶部添加连接状态指示灯(绿/黄/红)

图表字体跨平台兼容:
- 在 backend/fonts/ 存放 SimHei 字体文件
- create_work_dir() 自动复制字体到任务工作目录
- 两个解释器从工作目录动态加载字体
- E2B 移除 apt-get install 依赖,改用上传字体文件
- 统一三处字体优先级配置

其他:
- 重构注释规范、修复类型错误、添加 lint hook
- 更新 CLAUDE.md 项目文档
2026-05-15 10:04:47 +08:00

80 lines
2.8 KiB
Python

"""工具函数定义模块,为各 Agent 提供可用的工具 schema。"""
# ---- OpenAI 格式(Chat Completions + Responses 共用) ----
coder_tools = [
{
"type": "function",
"function": {
"name": "execute_code",
"description": "This function allows you to execute Python code and retrieve the terminal output. If the code "
"generates image output, the function will return the text '[image]'. The code is sent to a "
"Jupyter kernel for execution. The kernel will remain active after execution, retaining all "
"variables in memory."
"You cannot show rich outputs like plots or images, but you can store them in the working directory and point the user to them. ",
"strict": True,
"parameters": {
"type": "object",
"properties": {
"code": {"type": "string", "description": "The code text"}
},
"required": ["code"],
"additionalProperties": False,
},
},
},
]
writer_tools = [
{
"type": "function",
"function": {
"name": "search_papers",
"description": "Search for papers using a query string.",
"strict": True,
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "The query string"}
},
"required": ["query"],
"additionalProperties": False,
},
},
},
]
# ---- Anthropic 格式 ----
coder_tools_anthropic = [
{
"name": "execute_code",
"description": "This function allows you to execute Python code and retrieve the terminal output. If the code "
"generates image output, the function will return the text '[image]'. The code is sent to a "
"Jupyter kernel for execution. The kernel will remain active after execution, retaining all "
"variables in memory."
"You cannot show rich outputs like plots or images, but you can store them in the working directory and point the user to them. ",
"input_schema": {
"type": "object",
"properties": {
"code": {"type": "string", "description": "The code text"}
},
"required": ["code"],
},
},
]
writer_tools_anthropic = [
{
"name": "search_papers",
"description": "Search for papers using a query string.",
"input_schema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "The query string"}
},
"required": ["query"],
},
},
]