Merge remote-tracking branch 'origin/master' into ji
# Conflicts: # frontend-web/src/core/page-layout/sidebar-menu.ts # frontend-web/src/core/system-settings/api.ts # frontend-web/src/core/system-settings/hooks.ts # frontend-web/src/strategy-components/Header.tsx # offline-backend-20260512/backend/CLAUDE.md # offline-backend-20260512/backend/app/gateway/routers/system_settings.py # offline-backend-20260512/backend/packages/harness/deerflow/config/system_settings.py # offline-backend-20260512/backend/scripts/sql/column_additions_mysql.sql
This commit is contained in:
commit
b380575f16
103 files changed
+5915
-859
No files matched your search
@@ -176,6 +176,10 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
app.state.article_type_store = make_article_type_store(sf)
|
||||
|
||||
from deerflow.persistence.research_templates import make_research_template_store
|
||||
|
||||
app.state.research_template_store = make_research_template_store(sf)
|
||||
|
||||
from deerflow.persistence.memory_config import make_user_memory_config_store
|
||||
|
||||
app.state.memory_config_store = make_user_memory_config_store(sf)
|
||||
@@ -275,7 +279,14 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
_app = app # 闭包捕获 app,供网关访问 app.state(checkpointer/thread_store)
|
||||
gateway_factory = lambda p: InProcessRoundtableGateway( # noqa: E731
|
||||
_app, user_id=p.user_id, agents=p.agents, model=p.model
|
||||
_app,
|
||||
user_id=p.user_id,
|
||||
agents=p.agents,
|
||||
model=p.model,
|
||||
# 席位执行模式沿用 Step2 选择,后台席位 run 据此覆盖 policy 的 thinking/reasoning + 开子代理。
|
||||
seat_thinking_enabled=p.seat_thinking_enabled,
|
||||
seat_reasoning_effort=p.seat_reasoning_effort,
|
||||
seat_subagent_enabled=p.seat_subagent_enabled,
|
||||
)
|
||||
logger.info("[roundtable-jobs] gateway = inprocess (real models, default)")
|
||||
|
||||
@@ -448,6 +459,11 @@ def get_article_type_store(request: Request):
|
||||
return getattr(request.app.state, "article_type_store", None)
|
||||
|
||||
|
||||
def get_research_template_store(request: Request):
|
||||
"""Return the research template store, or None when not configured."""
|
||||
return getattr(request.app.state, "research_template_store", None)
|
||||
|
||||
|
||||
def get_memory_config_store(request: Request):
|
||||
"""Return the per-user memory config store."""
|
||||
val = getattr(request.app.state, "memory_config_store", None)
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from datetime import UTC, datetime
|
||||
from types import SimpleNamespace
|
||||
@@ -51,6 +53,33 @@ _SUMMARY_FILE = "方案总结报告.md"
|
||||
# 这里漏禁了 web_search,导致后台席位 / 报告能联网搜索而前端不能,现由 policy 统一。
|
||||
|
||||
|
||||
# ── 后台作业「按用户限流」(2026-06-16)─────────────────────────────────────────
|
||||
# 痛点:进 2+ 个后台挂起后,整个网关变慢——建立智能体连接、等待模型响应都慢。
|
||||
# 根因:① checkpointer 用单连接 aiosqlite(AsyncSqliteSaver,内部一把 asyncio.Lock 串
|
||||
# 行全进程的 checkpoint 读写);② 后台作业无并发上限——每个作业进程内驱动真实 leader/
|
||||
# seat/report run,DAG/recommend 的 stage 还用 asyncio.gather 把席位真并行铺开。多个后台
|
||||
# 作业同时把几十个 agent run 压到同一把 SQLite 锁 + 同一个离线模型端点上,前台实时会商
|
||||
# 的 checkpoint 读写 / 模型调用只能排队 → 「干啥都慢」。
|
||||
#
|
||||
# 解法:给**每个用户**一个并发额度(默认 2),后台每个 agent 轮次(leader/seat/report/
|
||||
# summary/dashboard)真正开跑前先取一个额度,跑完释放。同一用户的所有后台作业共享这 2 个
|
||||
# 额度——随便挂多少个作业都能立刻建好,但同一瞬间真正在打模型/写 checkpoint 的后台轮次
|
||||
# 至多 2 个,不会把共享资源打满。**前台实时路径(multi_agent._leader_run/_special_run、
|
||||
# 普通聊天)不经过本文件的 `_run_agent_turn`,永不取这个额度,故前台不受限。**
|
||||
_BACKGROUND_SLOTS_PER_USER = max(1, int(os.getenv("ROUNDTABLE_BACKGROUND_SLOTS_PER_USER", "2") or "2"))
|
||||
# 按 user_id 缓存 Semaphore。网关全程跑在同一个事件循环上,普通 dict 取/建即可(无跨线程)。
|
||||
_user_background_sems: dict[str, asyncio.Semaphore] = {}
|
||||
|
||||
|
||||
def _user_background_semaphore(user_id: str) -> asyncio.Semaphore:
|
||||
"""取该用户的后台并发额度信号量(懒建,每用户一把)。"""
|
||||
sem = _user_background_sems.get(user_id)
|
||||
if sem is None:
|
||||
sem = asyncio.Semaphore(_BACKGROUND_SLOTS_PER_USER)
|
||||
_user_background_sems[user_id] = sem
|
||||
return sem
|
||||
|
||||
|
||||
# ── 进程内底层操作 ───────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -156,6 +185,7 @@ def _tool_calls_since_last_human(messages: list[dict[str, Any]]) -> list[dict[st
|
||||
async def _run_agent_turn(
|
||||
app,
|
||||
*,
|
||||
user_id: str,
|
||||
thread_id: str,
|
||||
agent_name: str,
|
||||
message: str,
|
||||
@@ -164,11 +194,16 @@ async def _run_agent_turn(
|
||||
skill_stop_names: list[str],
|
||||
thinking_enabled: bool,
|
||||
reasoning_effort: str,
|
||||
subagent_enabled: bool = False,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""进程内驱动 agent_name 在 thread_id 上跑一轮(发 message),阻塞到完成,返回最终 messages。
|
||||
|
||||
镜像 multi_agent ``_run_payload`` 的 body 形状:agent 通过 ``context.agent_name`` 选,
|
||||
assistant_id 固定 lead_agent;关闭 memory recall / subagent / plan mode(临时研讨任务)。
|
||||
|
||||
并发受**该用户的后台额度**约束(``_user_background_semaphore``):真正开跑(start_run +
|
||||
await run task)前先取额度,跑完释放。同一用户的所有后台作业共享这几个额度,避免 2+
|
||||
后台挂起把单连接 SQLite checkpointer / 离线模型打满、拖垮前台实时会商。
|
||||
"""
|
||||
from app.gateway.routers.thread_runs import RunCreateRequest
|
||||
from app.gateway.services import start_run
|
||||
@@ -184,7 +219,8 @@ async def _run_agent_turn(
|
||||
"reasoning_effort": reasoning_effort,
|
||||
"thinking_enabled": thinking_enabled,
|
||||
"is_plan_mode": False,
|
||||
"subagent_enabled": False,
|
||||
# ultra 席位才置真 → 解锁 task 子代理工具(席位 policy 未禁 task)。leader 恒 False。
|
||||
"subagent_enabled": subagent_enabled,
|
||||
"thread_id": thread_id,
|
||||
"memory_recall_disabled": True,
|
||||
# 与 multi_agent._run_payload 对齐:关 builtin 记忆注入,避免单例总控/席位
|
||||
@@ -199,9 +235,12 @@ async def _run_agent_turn(
|
||||
# 虚拟 request:带上空 ``state``(auth 中间件在真请求上会写 state.user / state.auth;
|
||||
# 进程内没有这层,下游凡是读 request.state.X 的代码必须能拿到 None 而不是 AttributeError)。
|
||||
request = SimpleNamespace(app=app, state=SimpleNamespace(user=None, auth=None))
|
||||
record = await start_run(body, thread_id, request) # type: ignore[arg-type]
|
||||
if getattr(record, "task", None) is not None:
|
||||
await record.task # 阻塞到这轮 agent 跑完,checkpoint 已落盘
|
||||
# 取该用户的后台额度后再开跑:start_run + await task 是最重的部分(建 agent、调模型、
|
||||
# 落 checkpoint)。额度满时本轮在此 await 排队,等同用户某个在跑轮次释放额度后再开。
|
||||
async with _user_background_semaphore(user_id):
|
||||
record = await start_run(body, thread_id, request) # type: ignore[arg-type]
|
||||
if getattr(record, "task", None) is not None:
|
||||
await record.task # 阻塞到这轮 agent 跑完,checkpoint 已落盘
|
||||
return await _read_thread_messages(app, thread_id)
|
||||
|
||||
|
||||
@@ -262,7 +301,13 @@ def _read_summary_md(app, thread_id: str, user_id: str) -> str | None:
|
||||
# it all at once」后发出超长 write_file,单次输出被 max_tokens 截断 → 工具调用从未执行、
|
||||
# run 以 success 收尾但 outputs 下没有 .html → step3.html 回退成开场白文字。
|
||||
# 自愈:检测产物缺失/截断后,同线程追加纠偏消息(要求 write_file 分段 + append 续写)重试。
|
||||
_ARTIFACT_RETRY_LIMIT = 2
|
||||
#
|
||||
# 取值依据(2026-06-15 修复「后台 HTML 看板只生成一半、概率渲染失败」):模型单轮输出受
|
||||
# ``config.yaml`` 的 ``max_tokens``(deepseek-chat = 4096)硬截。一份完整看板 HTML 几十 KB
|
||||
# ≈ 上万 token,单轮写不完;旧值 2(最多 3 轮 ≈ 12k token)对长报告不够 → 落库半截 HTML →
|
||||
# 渲染失败。调到 5(最多 6 轮 append ≈ 24k token,足够绝大多数看板)显著降低截断概率。
|
||||
# 循环命中完整产物(``</html>`` / 非空 md / 合法 json)即 break,短报告不会白跑额外轮次。
|
||||
_ARTIFACT_RETRY_LIMIT = 5
|
||||
|
||||
_REPORT_RETRY_MISSING = (
|
||||
f"检测到 /mnt/user-data/outputs/{_REPORT_FILE} 还没有生成——你上一轮的 write_file 没有执行成功"
|
||||
@@ -332,11 +377,26 @@ def _build_seat_intro(agents: list[SeatRef]) -> str:
|
||||
class InProcessRoundtableGateway:
|
||||
"""进程内真网关。executor 先调 ``init_threads`` 建好线程,再跑编排引擎。"""
|
||||
|
||||
def __init__(self, app, *, user_id: str, agents: list[SeatRef], model: str | None = None) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
app,
|
||||
*,
|
||||
user_id: str,
|
||||
agents: list[SeatRef],
|
||||
model: str | None = None,
|
||||
seat_thinking_enabled: bool | None = None,
|
||||
seat_reasoning_effort: str | None = None,
|
||||
seat_subagent_enabled: bool = False,
|
||||
) -> None:
|
||||
self._app = app
|
||||
self._user_id = user_id
|
||||
self._agents = list(agents)
|
||||
self._model = model
|
||||
# 席位执行模式(沿用 Step2 选择):覆盖 seat policy 的 thinking/reasoning(None → policy 默认),
|
||||
# subagent 仅 ultra 档为真。只作用 special 席位;leader 派活不受影响。
|
||||
self._seat_thinking_enabled = seat_thinking_enabled
|
||||
self._seat_reasoning_effort = seat_reasoning_effort
|
||||
self._seat_subagent_enabled = seat_subagent_enabled
|
||||
self._seat_intro = ""
|
||||
self._first_leader = True
|
||||
|
||||
@@ -362,6 +422,7 @@ class InProcessRoundtableGateway:
|
||||
policy = roundtable_run_policy("leader")
|
||||
messages = await _run_agent_turn(
|
||||
self._app,
|
||||
user_id=self._user_id,
|
||||
thread_id=thread_ids[coordinator_name],
|
||||
agent_name=coordinator_name,
|
||||
message=msg,
|
||||
@@ -400,16 +461,27 @@ class InProcessRoundtableGateway:
|
||||
|
||||
async def run_seat(self, *, thread_ids, agent_id, task, model) -> SeatTurn:
|
||||
policy = roundtable_run_policy("seat")
|
||||
# 席位模式覆盖 policy 的 thinking/reasoning(None → policy 默认),与前端 _special_run 一致。
|
||||
messages = await _run_agent_turn(
|
||||
self._app,
|
||||
user_id=self._user_id,
|
||||
thread_id=thread_ids[agent_id],
|
||||
agent_name=agent_id,
|
||||
message=task,
|
||||
model=model or self._model,
|
||||
excluded_tools=policy.excluded_tools,
|
||||
skill_stop_names=policy.skill_stop_names,
|
||||
thinking_enabled=policy.thinking_enabled,
|
||||
reasoning_effort=policy.reasoning_effort,
|
||||
thinking_enabled=(
|
||||
policy.thinking_enabled
|
||||
if self._seat_thinking_enabled is None
|
||||
else self._seat_thinking_enabled
|
||||
),
|
||||
reasoning_effort=(
|
||||
policy.reasoning_effort
|
||||
if self._seat_reasoning_effort is None
|
||||
else self._seat_reasoning_effort
|
||||
),
|
||||
subagent_enabled=self._seat_subagent_enabled,
|
||||
)
|
||||
return SeatTurn(final_text=_latest_ai_text(messages), tool_calls=_tool_calls_since_last_human(messages))
|
||||
|
||||
@@ -427,6 +499,7 @@ class InProcessRoundtableGateway:
|
||||
for attempt in range(1 + _ARTIFACT_RETRY_LIMIT):
|
||||
messages = await _run_agent_turn(
|
||||
self._app,
|
||||
user_id=self._user_id,
|
||||
thread_id=report_thread_id,
|
||||
agent_name=REPORT_AGENT_ID,
|
||||
message=message,
|
||||
@@ -470,6 +543,7 @@ class InProcessRoundtableGateway:
|
||||
for attempt in range(1 + _ARTIFACT_RETRY_LIMIT):
|
||||
messages = await _run_agent_turn(
|
||||
self._app,
|
||||
user_id=self._user_id,
|
||||
thread_id=summary_thread_id,
|
||||
agent_name=SUMMARY_AGENT_ID,
|
||||
message=message,
|
||||
@@ -505,6 +579,7 @@ class InProcessRoundtableGateway:
|
||||
for attempt in range(1 + _ARTIFACT_RETRY_LIMIT):
|
||||
messages = await _run_agent_turn(
|
||||
self._app,
|
||||
user_id=self._user_id,
|
||||
thread_id=thread_id,
|
||||
agent_name=REPORT_AGENT_ID,
|
||||
message=message,
|
||||
|
||||
@@ -179,6 +179,12 @@ class StartParams:
|
||||
# 是否自动产出 Step3(方案总结报告 + 结果绘制)。默认沿用全局开关(现已恢复 True,
|
||||
# 见 ROUNDTABLE_BACKGROUND_REPORT_ENABLED)。测试可显式覆盖。
|
||||
enable_report: bool = ROUNDTABLE_BACKGROUND_REPORT_ENABLED
|
||||
# 席位执行模式(快速/思考/专业问答/多智能体)派生参数,沿用 Step2 选择。仅 special 席位用:
|
||||
# 覆盖 roundtable_run_policy("seat") 的 thinking/reasoning(None → policy 默认);
|
||||
# subagent 仅 ultra 档为真。透传给进程内网关(InProcessRoundtableGateway)的席位 run。
|
||||
seat_thinking_enabled: bool | None = None
|
||||
seat_reasoning_effort: str | None = None
|
||||
seat_subagent_enabled: bool = False
|
||||
|
||||
|
||||
# 网关工厂:给定一次启动参数,返回一个 RoundtableGateway 实例。
|
||||
|
||||
@@ -90,6 +90,48 @@ class ArticleTypeResponse(BaseModel):
|
||||
updated_at: str
|
||||
|
||||
|
||||
class ResearchTemplateRequest(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
article_type_key: Optional[str] = None
|
||||
outline: Optional[str] = None
|
||||
material_source: str = "general"
|
||||
word_count: int = 800
|
||||
audience: Optional[str] = None
|
||||
strict_mode: bool = False
|
||||
topic: Optional[str] = None
|
||||
sort_order: int = 0
|
||||
|
||||
|
||||
class UpdateResearchTemplateRequest(BaseModel):
|
||||
name: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
article_type_key: Optional[str] = None
|
||||
outline: Optional[str] = None
|
||||
material_source: Optional[str] = None
|
||||
word_count: Optional[int] = None
|
||||
audience: Optional[str] = None
|
||||
strict_mode: Optional[bool] = None
|
||||
topic: Optional[str] = None
|
||||
sort_order: Optional[int] = None
|
||||
|
||||
|
||||
class ResearchTemplateResponse(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
article_type_key: Optional[str] = None
|
||||
outline: Optional[str] = None
|
||||
material_source: str
|
||||
word_count: int
|
||||
audience: Optional[str] = None
|
||||
strict_mode: bool
|
||||
topic: Optional[str] = None
|
||||
sort_order: int
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
class SessionResponse(BaseModel):
|
||||
id: str
|
||||
user_id: Optional[str] = None
|
||||
@@ -268,6 +310,94 @@ async def delete_article_type(article_type_id: str, request: Request):
|
||||
return {"success": True}
|
||||
|
||||
|
||||
# ── 研究模板(课题研究左栏一键预填表单,需求 0616 #5)────────────────────────────
|
||||
|
||||
|
||||
@router.get("/research-templates", response_model=list[ResearchTemplateResponse])
|
||||
async def list_research_templates(request: Request):
|
||||
"""列出所有研究模板,按 sort_order 升序。
|
||||
|
||||
新机器/空表时自动写入内置范例模板(网摘/周报/要讯),幂等仅在表为空时执行。
|
||||
"""
|
||||
from app.gateway.deps import get_research_template_store
|
||||
|
||||
store = get_research_template_store(request)
|
||||
if store is None:
|
||||
return []
|
||||
try:
|
||||
await store.seed_defaults()
|
||||
except Exception:
|
||||
logger.exception("ai_writing: failed to seed default research templates")
|
||||
return await store.list()
|
||||
|
||||
|
||||
@router.post("/research-templates", response_model=ResearchTemplateResponse, status_code=201)
|
||||
async def create_research_template(body: ResearchTemplateRequest, request: Request):
|
||||
"""新增研究模板。"""
|
||||
from app.gateway.deps import get_research_template_store
|
||||
|
||||
store = get_research_template_store(request)
|
||||
if store is None:
|
||||
raise HTTPException(status_code=503, detail="Research template store not available")
|
||||
return await store.create(
|
||||
name=body.name,
|
||||
description=body.description,
|
||||
article_type_key=body.article_type_key,
|
||||
outline=body.outline,
|
||||
material_source=body.material_source,
|
||||
word_count=body.word_count,
|
||||
audience=body.audience,
|
||||
strict_mode=body.strict_mode,
|
||||
topic=body.topic,
|
||||
sort_order=body.sort_order,
|
||||
)
|
||||
|
||||
|
||||
@router.patch("/research-templates/{template_id}", response_model=ResearchTemplateResponse)
|
||||
async def update_research_template(template_id: str, body: UpdateResearchTemplateRequest, request: Request):
|
||||
"""更新研究模板字段(只传需要修改的字段)。"""
|
||||
from app.gateway.deps import get_research_template_store
|
||||
|
||||
store = get_research_template_store(request)
|
||||
if store is None:
|
||||
raise HTTPException(status_code=503, detail="Research template store not available")
|
||||
|
||||
kwargs = {}
|
||||
for field in (
|
||||
"name",
|
||||
"description",
|
||||
"article_type_key",
|
||||
"outline",
|
||||
"material_source",
|
||||
"word_count",
|
||||
"audience",
|
||||
"strict_mode",
|
||||
"topic",
|
||||
"sort_order",
|
||||
):
|
||||
val = getattr(body, field)
|
||||
if val is not None:
|
||||
kwargs[field] = val
|
||||
|
||||
updated = await store.update(template_id, **kwargs)
|
||||
if updated is None:
|
||||
raise HTTPException(status_code=404, detail="Research template not found")
|
||||
return updated
|
||||
|
||||
|
||||
@router.delete("/research-templates/{template_id}")
|
||||
async def delete_research_template(template_id: str, request: Request):
|
||||
"""删除研究模板。"""
|
||||
from app.gateway.deps import get_research_template_store
|
||||
|
||||
store = get_research_template_store(request)
|
||||
if store is None:
|
||||
raise HTTPException(status_code=503, detail="Research template store not available")
|
||||
deleted = await store.delete(template_id)
|
||||
if not deleted:
|
||||
raise HTTPException(status_code=404, detail="Research template not found")
|
||||
return {"success": True}
|
||||
|
||||
|
||||
# ── 管理接口 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -637,6 +637,8 @@ def _run_payload(
|
||||
skill_stop_names: list[str],
|
||||
thinking_enabled: bool = True,
|
||||
reasoning_effort: str = "medium",
|
||||
subagent_enabled: bool = False,
|
||||
stream_custom: bool = False,
|
||||
multitask_strategy: str = "reject",
|
||||
extra_context: dict[str, Any] | None = None,
|
||||
files: list[dict[str, Any]] | None = None,
|
||||
@@ -676,7 +678,9 @@ def _run_payload(
|
||||
"reasoning_effort": reasoning_effort,
|
||||
"thinking_enabled": thinking_enabled,
|
||||
"is_plan_mode": False,
|
||||
"subagent_enabled": False,
|
||||
# 默认 False;圆桌「多智能体问答(ultra)」档会让席位 _special_run 传 True,
|
||||
# 给席位解锁 task 子代理工具(席位 policy 未禁 task,故可用)。
|
||||
"subagent_enabled": subagent_enabled,
|
||||
"thread_id": thread_id,
|
||||
# 圆桌四个 router(intent / recommend / leader / special)都是临时任务,
|
||||
# 用户个人记忆与本次研讨无关。MemoryMiddleware 的 Hindsight recall 是
|
||||
@@ -691,7 +695,12 @@ def _run_payload(
|
||||
# 圆桌是一次性研讨,本就不该吃历史会话记忆,这里统一关注入根治该污染。
|
||||
"memory_injection_enabled": False,
|
||||
},
|
||||
"stream_mode": ["messages-tuple", "values"],
|
||||
# ultra 席位会派子智能体(task 工具),其 task_started/running/completed 进度走
|
||||
# **custom** 流(StreamWriter)。仅这种场景加 "custom",让前端任务卡片能显示子智能体
|
||||
# 实时进度;其余角色不加,避免无谓帧。
|
||||
"stream_mode": (
|
||||
["messages-tuple", "values", "custom"] if stream_custom else ["messages-tuple", "values"]
|
||||
),
|
||||
"stream_subgraphs": True,
|
||||
"stream_resumable": True,
|
||||
"assistant_id": "lead_agent",
|
||||
@@ -1570,6 +1579,9 @@ async def _special_run(
|
||||
no_file: bool = False,
|
||||
peer_deliveries: list[dict[str, Any]] | None = None,
|
||||
files: list[dict[str, Any]] | None = None,
|
||||
thinking_enabled: bool | None = None,
|
||||
reasoning_effort: str | None = None,
|
||||
subagent_enabled: bool = False,
|
||||
) -> AsyncIterator[str | dict[str, Any]]:
|
||||
"""子智能体(special)单轮:执行总控下发的 task 文本,交付 content。
|
||||
|
||||
@@ -1584,6 +1596,12 @@ async def _special_run(
|
||||
``peer_deliveries``:前序席位的**完整交付** ``[{name, content}, ...]``。注入到
|
||||
run context 的 ``roundtable_peer_deliveries``,供席位用 ``read_peer_delivery`` 工具
|
||||
**按需**取全文(平时只看广播摘要,§12.9 传摘要按需传全文)。不进 prompt,不耗 token。
|
||||
|
||||
``thinking_enabled`` / ``reasoning_effort`` / ``subagent_enabled``:圆桌第二步「席位
|
||||
执行模式」(快速/思考/专业问答/多智能体问答)派生的覆盖值。**仅 special 席位**接收:
|
||||
前两者为 None 时回退到 policy 默认(向后兼容,旧前端不传 → 维持 thinking + medium);
|
||||
``subagent_enabled`` 仅 ultra 档为 True,给席位解锁 ``task`` 子代理工具。**总控
|
||||
(leader)不受影响**,始终用其快速派活策略。
|
||||
"""
|
||||
t0 = time.perf_counter()
|
||||
thread_id = agent_threads[agent_name]
|
||||
@@ -1613,8 +1631,13 @@ async def _special_run(
|
||||
new_message=new_message,
|
||||
excluded_tools=seat_excluded,
|
||||
skill_stop_names=merge_skill_stop_names(policy.skill_stop_names, skill_stop_names),
|
||||
thinking_enabled=policy.thinking_enabled,
|
||||
reasoning_effort=policy.reasoning_effort,
|
||||
# 席位执行模式覆盖 policy 的 thinking/reasoning(None → 回退 policy 默认);
|
||||
# subagent 仅 ultra 档置真。工具裁剪(excluded_tools)仍完全由 policy 决定。
|
||||
thinking_enabled=(policy.thinking_enabled if thinking_enabled is None else thinking_enabled),
|
||||
reasoning_effort=(policy.reasoning_effort if reasoning_effort is None else reasoning_effort),
|
||||
subagent_enabled=subagent_enabled,
|
||||
# ultra 席位才会派子智能体 → 才需要 custom 流回传子任务实时进度(task_running 等)。
|
||||
stream_custom=subagent_enabled,
|
||||
# 干预/重新派活会把同一席位 thread 再跑一次;抢占掉没结束的旧 run,避免 409。
|
||||
multitask_strategy="rollback",
|
||||
# 前序席位完整交付 → run context,供 read_peer_delivery 工具按需取全文(§12.9)。
|
||||
@@ -1756,6 +1779,15 @@ async def run_multi_agent_stream(request: Request, payload: dict = Body(...)) ->
|
||||
# 不写死任何默认模型;空串会让 lead_agent._resolve_model_name() 回退到
|
||||
# config.yaml 的 models[0],与 /api/ai-writing 等其它路由一致。
|
||||
model_name: str = str(payload.get("model") or "")
|
||||
# 圆桌第二步「席位执行模式」(快速/思考/专业问答/多智能体问答)派生参数。**仅 special
|
||||
# 席位消费**:覆盖 seat policy 的 thinking/reasoning。thinking_enabled/reasoning_effort
|
||||
# 缺省(None/空)→ 后端按 policy 默认执行(向后兼容,旧前端不传维持 thinking + medium);
|
||||
# subagent_enabled 仅 ultra 档为真,给席位解锁 task 子代理工具。leader 不消费这些字段。
|
||||
_te_raw = payload.get("thinking_enabled")
|
||||
seat_thinking_enabled: bool | None = bool(_te_raw) if _te_raw is not None else None
|
||||
_re_raw = payload.get("reasoning_effort")
|
||||
seat_reasoning_effort: str | None = _re_raw if isinstance(_re_raw, str) and _re_raw else None
|
||||
seat_subagent_enabled: bool = bool(payload.get("subagent_enabled") or False)
|
||||
|
||||
if not agent_name or agent_name not in agent_threads:
|
||||
raise HTTPException(
|
||||
@@ -1803,6 +1835,9 @@ async def run_multi_agent_stream(request: Request, payload: dict = Body(...)) ->
|
||||
no_file=no_file,
|
||||
peer_deliveries=peer_deliveries,
|
||||
files=files,
|
||||
thinking_enabled=seat_thinking_enabled,
|
||||
reasoning_effort=seat_reasoning_effort,
|
||||
subagent_enabled=seat_subagent_enabled,
|
||||
)
|
||||
async for chunk in gen:
|
||||
if isinstance(chunk, dict):
|
||||
|
||||
@@ -57,6 +57,8 @@ class ChainResponse(BaseModel):
|
||||
stage_goals: list[str | None] | None = None
|
||||
# 写给总控的「编排提示」(dag-only):告诉总控怎么派活、做什么。None/空 = 不注入。
|
||||
coordinator_prompt: str | None = None
|
||||
# 默认席位执行模式(flash/thinking/pro/ultra);None = 未设,选入研讨时回退默认(pro)。
|
||||
seat_mode: str | None = None
|
||||
# 发布状态:True = 公共(所有账号可在「公共」筛选查看 / 选用)。
|
||||
is_public: bool = False
|
||||
# 是否当前用户所有(仅本人可编辑 / 删除 / 发布;公共筛选里别人的链条 is_mine=False)。
|
||||
@@ -83,6 +85,7 @@ class ChainCreateRequest(BaseModel):
|
||||
stages: list[list[str]] | None = None
|
||||
stage_goals: list[str | None] | None = None
|
||||
coordinator_prompt: str | None = Field(default=None, max_length=4000)
|
||||
seat_mode: str | None = Field(default=None, max_length=16)
|
||||
|
||||
|
||||
class ChainUpdateRequest(BaseModel):
|
||||
@@ -93,6 +96,7 @@ class ChainUpdateRequest(BaseModel):
|
||||
stages: list[list[str]] | None = None
|
||||
stage_goals: list[str | None] | None = None
|
||||
coordinator_prompt: str | None = Field(default=None, max_length=4000)
|
||||
seat_mode: str | None = Field(default=None, max_length=16)
|
||||
# 发布开关(True 发布为公共 / False 取消发布);仅 owner 可改(update 本就 owner 限定)。
|
||||
is_public: bool | None = None
|
||||
|
||||
@@ -224,6 +228,18 @@ def _validate_stage_goals(
|
||||
)
|
||||
|
||||
|
||||
_VALID_SEAT_MODES = {"flash", "thinking", "pro", "ultra"}
|
||||
|
||||
|
||||
def _validate_seat_mode(seat_mode: str | None) -> None:
|
||||
"""席位执行模式只能是 flash/thinking/pro/ultra 或 None(未设)。"""
|
||||
if seat_mode is not None and seat_mode not in _VALID_SEAT_MODES:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"非法席位执行模式: {seat_mode}(应为 {'/'.join(sorted(_VALID_SEAT_MODES))} 之一)",
|
||||
)
|
||||
|
||||
|
||||
# ── routes ───────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -249,6 +265,7 @@ async def create_chain(request: Request, body: ChainCreateRequest) -> ChainRespo
|
||||
_validate_seats(body.seats)
|
||||
_validate_stages(body.seats, body.stages)
|
||||
_validate_stage_goals(body.stages, body.stage_goals)
|
||||
_validate_seat_mode(body.seat_mode)
|
||||
store = _get_store(request)
|
||||
user_id = _current_user_id(request)
|
||||
row = await store.create_chain(
|
||||
@@ -261,6 +278,7 @@ async def create_chain(request: Request, body: ChainCreateRequest) -> ChainRespo
|
||||
"stages": body.stages,
|
||||
"stage_goals": body.stage_goals,
|
||||
"coordinator_prompt": body.coordinator_prompt,
|
||||
"seat_mode": body.seat_mode,
|
||||
},
|
||||
)
|
||||
await _enrich_owner_names([row])
|
||||
@@ -290,6 +308,7 @@ async def update_chain(request: Request, chain_id: str, body: ChainUpdateRequest
|
||||
_validate_stages(body.seats, body.stages)
|
||||
# Goals align to stages; reject goals sent without a layering, enforce length/size.
|
||||
_validate_stage_goals(body.stages, body.stage_goals)
|
||||
_validate_seat_mode(body.seat_mode)
|
||||
store = _get_store(request)
|
||||
user_id = _current_user_id(request)
|
||||
# Distinguish "omitted" from "explicitly sent"; only forward provided fields.
|
||||
|
||||
@@ -68,6 +68,12 @@ class StartJobRequest(BaseModel):
|
||||
# 预建好的 thread 映射(Phase 3b 真网关用;模拟网关忽略)。
|
||||
threadIds: dict[str, str] | None = None
|
||||
coordinatorName: str = "roundtable-coordinator"
|
||||
# 席位执行模式(快速/思考/专业问答/多智能体)派生参数,由前端 toStartBody 下发。
|
||||
# 仅 special 席位用:覆盖 roundtable_run_policy("seat") 的 thinking/reasoning;
|
||||
# None/缺省 → 后端按 policy 默认(≈pro),向后兼容旧前端。subagent 仅 ultra 档为真。
|
||||
thinking_enabled: bool | None = None
|
||||
reasoning_effort: str | None = None
|
||||
subagent_enabled: bool = False
|
||||
|
||||
|
||||
class ResumeJobRequest(BaseModel):
|
||||
@@ -219,6 +225,9 @@ async def start_job(request: Request, body: StartJobRequest) -> RoundtableJobRes
|
||||
draft_id=body.draftId,
|
||||
chain=body.chain,
|
||||
orchestration_plan=body.orchestrationPlan,
|
||||
seat_thinking_enabled=body.thinking_enabled,
|
||||
seat_reasoning_effort=body.reasoning_effort,
|
||||
seat_subagent_enabled=body.subagent_enabled,
|
||||
)
|
||||
)
|
||||
return _to_response(row)
|
||||
|
||||
@@ -18,10 +18,12 @@ from deerflow.config.system_settings import (
|
||||
PublishSquaresSettings,
|
||||
SkillCompressionSettings,
|
||||
SystemSettings,
|
||||
get_module_tag_ids,
|
||||
list_publish_squares,
|
||||
load_system_settings,
|
||||
resolve_default_square_id,
|
||||
save_system_settings,
|
||||
set_module_tag_ids,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -436,3 +438,35 @@ async def get_log_system(request: Request) -> LogSystemResponse:
|
||||
await _require_admin(request)
|
||||
cfg = get_app_config().log_system
|
||||
return LogSystemResponse(enabled=cfg.enabled, url=cfg.url, label=cfg.label)
|
||||
|
||||
|
||||
class AgentModuleConfigResponse(BaseModel):
|
||||
"""Selected agent-tag ids for a「按类型聚合」module (zzJC / zzXD)."""
|
||||
|
||||
key: str = Field(..., description="Module key, e.g. zzjc / zzxd")
|
||||
tag_ids: list[str] = Field(default_factory=list, description="Selected agent tag ids")
|
||||
|
||||
|
||||
class AgentModuleConfigUpdateRequest(BaseModel):
|
||||
tag_ids: list[str] = Field(default_factory=list, description="Full replacement list of selected agent tag ids")
|
||||
|
||||
|
||||
@router.get("/agent-modules/{key}", response_model=AgentModuleConfigResponse)
|
||||
async def get_agent_module_config(key: str) -> AgentModuleConfigResponse:
|
||||
"""Return the agent tag ids configured for ``key`` (readable by any user —
|
||||
the module's left sidebar needs it to filter the agent list)."""
|
||||
settings = load_system_settings().agent_modules
|
||||
return AgentModuleConfigResponse(key=key, tag_ids=get_module_tag_ids(settings, key))
|
||||
|
||||
|
||||
@router.put("/agent-modules/{key}", response_model=AgentModuleConfigResponse)
|
||||
async def update_agent_module_config(
|
||||
key: str, body: AgentModuleConfigUpdateRequest, request: Request
|
||||
) -> AgentModuleConfigResponse:
|
||||
"""Replace the agent tag ids configured for ``key``. Admin only."""
|
||||
await _require_admin(request)
|
||||
|
||||
current = load_system_settings()
|
||||
updated = set_module_tag_ids(current.agent_modules, key, body.tag_ids)
|
||||
saved = save_system_settings(current.model_copy(update={"agent_modules": updated}))
|
||||
return AgentModuleConfigResponse(key=key, tag_ids=get_module_tag_ids(saved.agent_modules, key))
|
||||
Reference in new issue
Block a user