- 新增 pam_deploy_graph 包,包含 agent、action router、runner、parser 和配置加载能力 - 支持 hybrid_node_mcp 路由策略:PAM_HOME 走脚本 action,PAM_NODE 走 MCP - 新增 fake runner 和 CLI 预演/全局流程验证入口 - 新增路由、输出解析、配置加载、脚本命令构造、Skill 策略加载测试 - 在 README 中记录当前代码骨架、实现进度、使用方式和下一步建议
48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
"""Action routing for HOME script actions and NODE MCP actions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from .constants import ALLOWED_ACTIONS, HOME_ACTIONS, NODE_ACTIONS
|
|
from .models import AgentState, BackendName, ExecutionStrategy, ActionResult
|
|
|
|
|
|
def build_action_backends(strategy: ExecutionStrategy) -> dict[str, BackendName]:
|
|
if strategy == "fake":
|
|
return {action: "fake" for action in ALLOWED_ACTIONS}
|
|
if strategy == "script_only":
|
|
return {action: "script" for action in ALLOWED_ACTIONS}
|
|
if strategy == "hybrid_node_mcp":
|
|
routes: dict[str, BackendName] = {action: "script" for action in HOME_ACTIONS}
|
|
routes.update({action: "mcp" for action in NODE_ACTIONS})
|
|
return routes
|
|
raise ValueError(f"Unknown execution strategy: {strategy}")
|
|
|
|
|
|
class ActionRouter:
|
|
def __init__(self, *, script_runner, mcp_runner=None, fake_runner=None) -> None:
|
|
self.script_runner = script_runner
|
|
self.mcp_runner = mcp_runner
|
|
self.fake_runner = fake_runner
|
|
|
|
def run_action(self, state: AgentState, action: str, **kwargs) -> ActionResult:
|
|
backend = state.action_backends.get(action)
|
|
if not backend:
|
|
raise ValueError(f"Action is not routed: {action}")
|
|
if backend == "script":
|
|
return self.script_runner.run(
|
|
action,
|
|
params=state.params,
|
|
script_entry=state.script_entry,
|
|
config_path=state.config_path,
|
|
trace_file_path=state.trace_file_path,
|
|
**kwargs,
|
|
)
|
|
if backend == "mcp":
|
|
if self.mcp_runner is None:
|
|
raise RuntimeError(f"MCP runner is required for action: {action}")
|
|
return self.mcp_runner.run(action, params=state.params, **kwargs)
|
|
if self.fake_runner is None:
|
|
raise RuntimeError(f"Fake runner is required for action: {action}")
|
|
return self.fake_runner.run(action, params=state.params, **kwargs)
|
|
|