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
+12 -15
View File
@@ -102,7 +102,7 @@ class PromptBrain(BaseBrain):
def system_prompt(self, cfg: AssistantConfig) -> str:
prompt = self._store.render(cfg.prompt) if self._dynamic_enabled else cfg.prompt
if cfg.runtimeMode == "pipeline" and any(tool.type == "task" for tool in cfg.tools):
if cfg.runtimeMode == "pipeline" and cfg.task_backend is not None:
from services.brains.prompt_tasks import TASK_HINT
prompt += "\n" + TASK_HINT
return prompt
@@ -158,20 +158,6 @@ class PromptBrain(BaseBrain):
):
logger.warning(f"跳过客户端未上报的工具: {tool.function_name}")
continue
if tool.type == "task":
if cfg.runtimeMode != "pipeline":
raise ValueError("后台任务工具仅支持提示词 Pipeline")
from services.brains.prompt_tasks import PromptTaskBridge
if self._task_bridge is not None:
raise ValueError("最多绑定一个后台任务工具")
self._task_bridge = PromptTaskBridge(cfg, runtime, self._tools)
for schema, handler in self._task_bridge.functions(tool, binding_by_id[tool.id]):
if schema.name in registered_names:
raise ValueError("后台任务函数名与已有工具冲突")
schemas.append(schema)
registered_names.add(schema.name)
runtime.llm.register_function(schema.name, handler, cancel_on_interruption=False)
continue
if tool.type == "system":
schema, handler = self._make_system_tool(tool, runtime)
elif tool.type in {"http", "mcp", "client"}:
@@ -195,6 +181,17 @@ class PromptBrain(BaseBrain):
handler,
cancel_on_interruption=policy.cancel_on_interruption,
)
if cfg.task_backend is not None:
if cfg.runtimeMode != "pipeline":
raise ValueError("任务后端仅支持提示词 Pipeline")
from services.brains.prompt_tasks import PromptTaskBridge
self._task_bridge = PromptTaskBridge(cfg, runtime, self._tools)
for schema, handler in self._task_bridge.functions():
if schema.name in registered_names:
raise ValueError("任务委派函数名与已有工具冲突")
schemas.append(schema)
registered_names.add(schema.name)
runtime.llm.register_function(schema.name, handler, cancel_on_interruption=False)
runtime.set_tools(schemas)
async def close(self):