F3: connect Prompt tools and web task controls to native Jobs
This commit is contained in:
@@ -72,6 +72,7 @@ class PromptBrain(BaseBrain):
|
||||
self._action_stages = ActionStageRunner(self._actions)
|
||||
self._message_stages = MessageStageRunner()
|
||||
self._tool_by_id = {tool.id: tool for tool in cfg.tools}
|
||||
self._task_bridge = None
|
||||
self._runtime: BrainRuntime | None = None
|
||||
self._realtime_controller: PromptRealtimeToolController | None = None
|
||||
self._output: FixedSpeechOutput | None = None
|
||||
@@ -100,7 +101,11 @@ class PromptBrain(BaseBrain):
|
||||
)
|
||||
|
||||
def system_prompt(self, cfg: AssistantConfig) -> str:
|
||||
return self._store.render(cfg.prompt) if self._dynamic_enabled else cfg.prompt
|
||||
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):
|
||||
from services.brains.prompt_tasks import TASK_HINT
|
||||
prompt += "\n" + TASK_HINT
|
||||
return prompt
|
||||
|
||||
def build_llm(self, cfg: AssistantConfig, context: LLMContext) -> FrameProcessor:
|
||||
from services.pipecat.service_factory import create_llm
|
||||
@@ -153,6 +158,20 @@ 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"}:
|
||||
@@ -178,6 +197,11 @@ class PromptBrain(BaseBrain):
|
||||
)
|
||||
runtime.set_tools(schemas)
|
||||
|
||||
async def close(self):
|
||||
if self._task_bridge:
|
||||
self._task_bridge.close()
|
||||
self._task_bridge = None
|
||||
|
||||
def restore_text_state(self, snapshot: dict[str, Any]) -> None:
|
||||
"""Restore Prompt startup progress for a later Responses API turn."""
|
||||
if snapshot.get("type") != "prompt":
|
||||
@@ -596,7 +620,7 @@ class PromptBrain(BaseBrain):
|
||||
|
||||
def _refresh_prompt(self) -> None:
|
||||
if self._dynamic_enabled and self._runtime is not None:
|
||||
self._runtime.set_system_prompt(self._store.render(self._cfg.prompt))
|
||||
self._runtime.set_system_prompt(self.system_prompt(self._cfg))
|
||||
|
||||
def _make_remote_tool(self, tool, runtime: BrainRuntime, binding):
|
||||
properties, required = self._tools.schema_parts(tool, binding)
|
||||
|
||||
Reference in New Issue
Block a user