Files
aiagent/backend/app/core/config.py
renjianbo cadeb2dc32 fix: 修复热点摘要超长上下文并统一 Windows 启动文档
为 http_request 增加响应体截断与头部精简,避免门户首页触发 LLM 上下文超限;同时新增政务/媒体及教育批量 Agent 脚本,并将 Windows 启停说明合并为唯一指南,补充本次超时故障复盘与标准重启流程。

Made-with: Cursor
2026-04-30 00:10:19 +08:00

86 lines
3.4 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.
"""
应用配置
"""
from pathlib import Path
from pydantic_settings import BaseSettings
from typing import List
# 无论从项目根还是 backend 目录启动,始终加载 backend/.env
_BACKEND_DIR = Path(__file__).resolve().parent.parent.parent
_ENV_PATH = _BACKEND_DIR / ".env"
class Settings(BaseSettings):
"""应用设置"""
# 应用基本信息
APP_NAME: str = "低代码智能体平台"
APP_VERSION: str = "1.0.0"
DEBUG: bool = True
SECRET_KEY: str = "dev-secret-key-change-in-production"
# 数据库配置MySQL
DATABASE_URL: str = "mysql+pymysql://root:!Rjb12191@gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936/agent_db?charset=utf8mb4"
# Redis配置
REDIS_URL: str = "redis://localhost:6379/0"
# 会话记忆:除 Redis 外是否写入 MySQLpersistent_user_memories实现跨重启、跨 TTL 的永久记忆
MEMORY_PERSIST_DB_ENABLED: bool = True
# 本地文件工具file_read / file_write允许读写的根目录。空字符串表示使用「backend 的上一级目录」作为仓库根。
LOCAL_FILE_TOOLS_ROOT: str = ""
LOCAL_FILE_READ_MAX_BYTES: int = 2_097_152 # 单次读取上限(默认 2MB
LOCAL_FILE_WRITE_MAX_BYTES: int = 2_097_152 # 单次写入内容上限UTF-8 字节)
# http_request 工具:写入 LLM 上下文的响应体最大字符数HTML/JSON 过大时截断,避免超过模型 context
HTTP_REQUEST_MAX_BODY_CHARS: int = 32_000
# 图片 OCRfile_read 对 png/jpg 等Tesseract 可执行文件路径Windows 示例 C:/Program Files/Tesseract-OCR/tesseract.exe
TESSERACT_CMD: str = ""
# 自定义 tessdata 目录(内含 chi_sim.traineddata 等)。留空时若 LOCAL_FILE_TOOLS_ROOT/tessdata 下存在 .traineddata 则自动使用
TESSERACT_TESSDATA_DIR: str = ""
# 智能体对话落盘:在工作区根下 agent_workspaces/<agent_id>/dialogue.md 追加 Markdown与 LOCAL_FILE_TOOLS_ROOT 一致)
AGENT_WORKSPACE_CHAT_LOG_ENABLED: bool = True
AGENT_WORKSPACE_CHAT_SUBDIR: str = "agent_workspaces"
# CORS配置支持字符串或列表
CORS_ORIGINS: str = "http://localhost:3000,http://127.0.0.1:3000,http://localhost:8038,http://101.43.95.130:8038"
# OpenAI配置
OPENAI_API_KEY: str = ""
OPENAI_BASE_URL: str = "https://api.openai.com/v1"
# DeepSeek配置
DEEPSEEK_API_KEY: str = ""
DEEPSEEK_BASE_URL: str = "https://api.deepseek.com"
# Anthropic配置
ANTHROPIC_API_KEY: str = ""
# JWT配置
JWT_SECRET_KEY: str = "dev-jwt-secret-key-change-in-production"
JWT_ALGORITHM: str = "HS256"
JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
# Celery 工作流任务:对**非业务节点失败**(非 WorkflowExecutionError的退避重试次数0 表示不重试
WORKFLOW_TASK_MAX_RETRIES: int = 0
# 单执行预算:主循环每执行一个节点计 1 步,超过则熔断(防止死循环/失控)
WORKFLOW_MAX_STEPS_PER_RUN: int = 2000
# 单执行 LLM 节点调用上限llm / template 节点每执行一次计 1
WORKFLOW_MAX_LLM_INVOCATIONS_PER_RUN: int = 200
# 单执行工具实际执行次数上限LLM function calling 每执行一个工具计 1
WORKFLOW_MAX_TOOL_CALLS_PER_RUN: int = 500
class Config:
env_file = str(_ENV_PATH)
case_sensitive = True
settings = Settings()