feat: add persisted batch text testing

This commit is contained in:
Xin Wang
2026-08-10 13:49:24 +08:00
parent 5b8b9fd097
commit 19e8c8c108
27 changed files with 3855 additions and 1450 deletions
+3
View File
@@ -99,6 +99,9 @@ class BrainRuntime:
Callable[[bool, dict[str, Any]], Awaitable[None]] | None
) = None
flow_global_functions: list[Any] = field(default_factory=list)
# Tests replace external side effects without changing Pipecat or stored
# tool resources. Production leaves this unset and uses ToolExecutor.
tool_executor_factory: Callable[[Any], Any] | None = None
@dataclass(frozen=True)
+23 -8
View File
@@ -103,6 +103,8 @@ class PromptBrain(BaseBrain):
async def setup(self, cfg: AssistantConfig, runtime: BrainRuntime) -> None:
self._runtime = runtime
if runtime.tool_executor_factory is not None:
self._tools = runtime.tool_executor_factory(self._store)
self._tools.set_client_tools(runtime.client_tools)
self._actions = ActionRunner(
self._tools,
@@ -651,14 +653,27 @@ class PromptBrain(BaseBrain):
if not kind:
raise ValueError(f"系统工具 {tool.id} 缺少有效 kind")
if kind == "end_conversation":
return self._make_end_call_tool(tool, runtime)
if kind == "update_state":
return self._make_update_state_tool(tool, runtime)
if kind == "skip_turn":
return self._make_skip_turn_tool(tool)
if kind == "request_human_handoff":
return self._make_handoff_tool(tool, runtime)
raise ValueError(f"未知系统工具: {kind}")
schema, handler = self._make_end_call_tool(tool, runtime)
elif kind == "update_state":
schema, handler = self._make_update_state_tool(tool, runtime)
elif kind == "skip_turn":
schema, handler = self._make_skip_turn_tool(tool)
elif kind == "request_human_handoff":
schema, handler = self._make_handoff_tool(tool, runtime)
else:
raise ValueError(f"未知系统工具: {kind}")
if runtime.tool_executor_factory is None:
return schema, handler
async def mock_system_tool(params: FunctionCallParams) -> None:
result = await self._tools.execute(
tool,
dict(params.arguments or {}),
)
await params.result_callback(result)
return schema, mock_system_tool
def _make_update_state_tool(self, tool, runtime: BrainRuntime):
"""更新已声明的动态变量(会话状态),并让模型继续当前回答。"""
+24 -9
View File
@@ -214,7 +214,12 @@ class WorkflowBrain(BaseBrain):
self._cfg = cfg
self._runtime = runtime
self._store = DynamicVariableStore.from_config(cfg)
self._tools = ToolExecutor(self._store, client_tools=runtime.client_tools)
self._tools = (
runtime.tool_executor_factory(self._store)
if runtime.tool_executor_factory is not None
else ToolExecutor(self._store, client_tools=runtime.client_tools)
)
self._tools.set_client_tools(runtime.client_tools)
self._actions = ActionRunner(
self._tools,
is_session_ending=lambda: runtime.call_end.ending,
@@ -934,18 +939,28 @@ class WorkflowBrain(BaseBrain):
"""Build one platform-owned tool scoped to the active Agent node."""
kind = system_tool_kind(tool.definition or {})
if kind == "update_state":
return self._workflow_update_state_tool(
schema = self._workflow_update_state_tool(
tool,
node_id,
state_variable_names=state_variable_names,
)
if kind == "skip_turn":
return self._workflow_skip_turn_tool(tool)
if kind == "request_human_handoff":
return self._workflow_handoff_tool(tool, node_id)
if kind == "end_conversation":
return self._workflow_end_conversation_tool(tool, node_id)
raise ValueError(f"系统工具 {tool.id} 缺少有效 kind")
elif kind == "skip_turn":
schema = self._workflow_skip_turn_tool(tool)
elif kind == "request_human_handoff":
schema = self._workflow_handoff_tool(tool, node_id)
elif kind == "end_conversation":
schema = self._workflow_end_conversation_tool(tool, node_id)
else:
raise ValueError(f"系统工具 {tool.id} 缺少有效 kind")
runtime = self._require_runtime()
if runtime.tool_executor_factory is None:
return schema
async def mock_system_tool(args, _flow_manager):
return await self._tools.execute(tool, dict(args or {}))
return replace(schema, handler=mock_system_tool)
def _workflow_update_state_tool(
self,