F2: delegate prompt tasks to native Reasoner or OpenCode backends

This commit is contained in:
Xin Wang
2026-10-23 23:46:29 +08:00
parent 529250173d
commit 16ebfe358c
14 changed files with 784 additions and 110 deletions
+8 -6
View File
@@ -12,7 +12,6 @@ router = APIRouter(prefix="/api/background-tasks", tags=["background-tasks"], de
class SubmitTask(CamelModel):
assistant_id: str
tool_id: str
instruction: str = Field(min_length=1, max_length=12000)
request_id: str = Field(min_length=1, max_length=80)
@@ -32,12 +31,15 @@ async def submit_task(body: SubmitTask, db=Depends(get_session)):
cfg = await resolve_runtime_config(db, body.assistant_id)
if cfg.type != "prompt" or cfg.runtimeMode != "pipeline":
raise HTTPException(400, "后台任务仅支持提示词 Pipeline")
bound = {binding.tool_id for binding in cfg.tool_bindings}
tool = next((tool for tool in cfg.tools if tool.id == body.tool_id and tool.id in bound and tool.type == "task"), None)
if not tool:
raise HTTPException(400, "助手未绑定该任务工具")
if cfg.task_backend is None:
raise HTTPException(400, "助手未绑定任务后端")
try:
return await task_service.submit(assistant_id=body.assistant_id, conversation_id="web_" + body.assistant_id, tool=tool, instruction=body.instruction, invocation_id=body.request_id)
return await task_service.submit(
assistant_id=body.assistant_id, conversation_id="web_" + body.assistant_id,
backend=cfg.task_backend, instruction=body.instruction, invocation_id=body.request_id,
variable_state={"values": cfg.dynamic_variables, "definitions": cfg.dynamic_variable_definitions,
"secrets": cfg.secret_dynamic_variables},
)
except ValueError as exc:
raise HTTPException(400, str(exc)) from exc