Files
hunjing/backend/app/core/config/runtime_config.py
T
chenxin b419e0afde M7:形仪与语音——真形锚点、候选定相、声音档案与克隆授权、ASR 接入
- 形仪域 domains/xingyi:form_anchors(稳定辨识特征/年龄表现/许可禁忌/可变范围——生成内容不可静默覆盖锚点);forms(主仪/化仪/文字形仪,candidate→adopt 定相治理:未定相不进呈现位、主仪唯一、新主仪自动退役旧主仪);voice_profiles(三来源,授权克隆必填用途与传播范围,revoke-grant 撤回立即生效,assert-usable 合成前置校验拒绝撤回/过期)
- ASR:元炁 SenseVoice /v1/audio/transcriptions 透传(Whisper 兼容 multipart);YUANQI_BASE_URL 未配置时 503 不降级不伪造——多模态关闭纪律
- 前端形仪工坊(人物详情页):真形锚点编辑(特征逐行解析)/候选登记定相废弃/声音档案建立与授权撤回;头像呈现位改走定相主仪(forms/primary);xingyi api 库 + mock + 组件 4 用例
- 退役:旧 avatar 模块(services/endpoints/avatar、avatar_dir 配置、avatar_url 字段、前端直传组件与测试)
- 验收(test_m7_xingyi 三用例):未定相不成为正式形仪(含主仪唯一与旧主仪 retired 断言);克隆授权可撤回(缺用途拒/撤回即拒/过期同理/预设不受约束);关闭全部多模态后文字相伴完整可用(ASR 503 时镜树缘契百工照常——回归)
- 四套件:后端 376、前端 203、BFF 4、神识 5 包全绿(2 个预存环境失败不变);迁移 008 净库+±1 干净
2026-08-27 20:26:52 +08:00

113 lines
7.0 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.
"""运行时与 SSE 配置:事件流、超时、工具运行时开关等。"""
from __future__ import annotations
from pydantic_settings import BaseSettings
class RuntimeConfig(BaseSettings):
"""SSE / 运行时 / 工具运行时配置。"""
# ==================== SSE 配置 ====================
enable_sse: bool = True # 是否启用 SSE
max_text_message_bytes: int = 32768 # 最大文本消息字节数
sse_poll_interval_seconds: float = 0.01 # SSE 轮询间隔(秒,10ms:前端逐段平滑增量)
sse_heartbeat_seconds: float = 15.0 # SSE 心跳间隔(秒)
run_timeout_seconds: int = 120 # 运行超时时间(秒)
# ==================== 神识(模型网关,rewrite/1.0) ====================
shenshi_base_url: str = "" # 神识服务地址;为空时 Kernel 使用进程内回声桩(M0 骨架)
shenshi_service_token: str = "" # 灵台→神识服务令牌(开发档可空)
shenshi_timeout_seconds: float = 120.0 # 神识流式调用超时(秒)
# ==================== 镜生域(rewrite/1.0 M1) ====================
identity_record_secret: str = "dev-identity-secret" # 魂籍签名密钥;正式部署必须改掉默认值
death_calm_period_hours: int = 72 # 死亡冷静期时长(小时),期内可撤销
seat_lease_ttl_seconds: int = 60 # 命台租约 TTL(秒)
# Agent 循环最大轮数:模型每轮仍带工具调用则继续,超限截断返回(见 agent.runtime.DEFAULT_MAX_ITERATIONS)
agent_max_iterations: int = 8
# 单次高风险工具确认挂起超时(秒):须小于 run_timeout_seconds,超时按拒绝处理;
# 若 >= run_timeout_seconds,run 整体超时会先到,导致确认中的 run 直接 failed
confirmation_timeout_seconds: int = 60
# 是否启用数据库持久化的确认存储(用于多 worker 部署);关闭则使用进程内 InMemoryConfirmationStore(默认)
use_db_confirmation_store: bool = False
run_max_events: int = 1000 # 最大事件数
event_payload_max_bytes: int = 65536 # 事件负载最大字节数
memory_injection_limit: int = 5 # 记忆注入条数上限
# ==================== 工具运行时配置 ====================
enable_tool_runtime: bool = True # 是否启用百工工具运行时(司命 + 沙箱)
tool_timeout_seconds: int = 600 # 单个工具调用超时秒数
# ==================== 洛书规划器 ====================
enable_deliberative_planning: bool = False # 是否启用显式多步规划(§10.2 增强能力)
# ==================== 大周天(长期演化循环) ====================
enable_big_cycle: bool = True # 是否启用大周天自动触发
big_cycle_memory_threshold: int = 20 # 触发大周天的记忆数阈值
big_cycle_min_interval_seconds: int = 300 # 两次大周天最小间隔(秒),避免频繁触发
big_cycle_model: str = "deepseek-v4-flash" # 大周天候选生成所用模型(models.yaml name 或 tag)
big_cycle_max_candidates: int = 10 # 单次大周天生成的演化候选上限
big_cycle_token_budget: int = 64000 # 单次大周天的 token 预算上限(超限跳过非关键阶段)
big_cycle_max_drift: float = 2.0 # 最大累积漂移值(超过后暂停自动演化)
big_cycle_drift_threshold: float = 0.6 # 单次演化候选的漂移阈值(>= 此值不自动应用)
# ==================== 内驱力(太一枢)[PLANNED] ====================
enable_intrinsic_drive: bool = False # 是否启用内驱力扫描(curiosity / exploration)
drive_scan_interval_seconds: int = 3600 # 内驱力扫描间隔秒数
drive_max_curiosity_per_scan: int = 5 # 单次扫描最多好奇问题数
drive_allow_interrupt: bool = False # 是否允许内驱力中断当前任务
# ==================== 司命安全策略 ====================
# 工具策略 YAML 路径(相对 backend);未配置时 SafetyGovernor 使用内置默认空策略。
safety_policy_path: str = ""
safety_always_confirm_high_risk: bool = True # 高风险动作是否总是确认
# ==================== MCP / 联网工具网络超时 ====================
mcp_list_timeout_seconds: float = 10.0 # MCP tools/list 请求超时(秒)
mcp_call_timeout_seconds: float = 30.0 # MCP tools/call 请求超时(秒)
tool_web_http_timeout_seconds: float = 15.0 # fetch_url 的 HTTP 超时(秒)
# ==================== MCP stdio 子进程 ====================
mcp_stdio_start_timeout_seconds: float = 15.0 # stdio 子进程启动超时(秒)
mcp_stdio_call_timeout_seconds: float = 30.0 # stdio 单次 tools/call 超时(秒)
mcp_stdio_stop_timeout_seconds: float = 5.0 # SIGTERM → SIGKILL 等待(秒)
# ==================== 向量记忆检索 ====================
vector_db_enabled: bool = False # 是否启用向量数据库(关则纯 SQL 检索)
vector_db_type: str = "chroma" # 向量库类型:chroma / milvus
chromadb_host: str = "" # ChromaDB HTTP 主机(空则内存模式)
chromadb_port: int = 8000 # ChromaDB HTTP 端口
chroma_collection: str = "hunjing_memories" # ChromaDB collection 名
chroma_persist_directory: str = "../db/chroma" # ChromaDB 持久化目录(相对 backend)
embedding_model_hint: str = "bge-m3" # embedding 模型逻辑名
# 元炁本地推理引擎(ASR 语音转写;未配置=多模态关闭,文字链路不受影响)
yuanqi_base_url: str = ""
yuanqi_asr_model: str = "iic/SenseVoiceSmall"
# ==================== 自动记忆候选 [PLANNED] ====================
enable_memory_candidates: bool = False # 是否启用自动记忆候选抽取
memory_candidate_min_importance: float = 0.7 # 候选记忆重要性阈值(0.0~1.0)
# ==================== 审计日志(司命枢·起居注)[PLANNED] ====================
enable_audit_log: bool = True # 是否启用审计日志
# ==================== 感知(烛照枢)[PLANNED] ====================
enable_camera: bool = False # 是否启用摄像头(视觉感知)
enable_microphone: bool = False # 是否启用麦克风(听觉感知)
perception_save_raw_media: bool = False # 是否保存原始感知文件
perception_max_media_mb: int = 20 # 感知文件最大大小(MB)
# ==================== 语音服务 [PLANNED] ====================
enable_asr: bool = False # 是否启用 ASR(语音转文字)
enable_tts: bool = False # 是否启用 TTS(文字转语音)
enable_voice_training: bool = False # 是否启用语音训练(微调 TTS 音色)
enable_voice_chat: bool = False # 是否启用实时语音对话
# ==================== 导入限制 [PLANNED] ====================
import_max_file_mb: int = 20 # 人物资料导入文件最大大小(MB)
import_audio_max_duration_seconds: int = 600 # 语音样本最大时长(秒)
import_allowed_audio_mime_types: str = (
"audio/wav,audio/mpeg,audio/mp4,audio/flac" # 允许上传的语音样本 MIME 类型
)