Spy Plugin — 注入任意 handler 函数到 Agent Plugin Pipeline 的轻量方式。
替代 with_mock_plugin macro,避免引入 :meck 重依赖;
用户传入 anonymous handler 函数,Spy 在每次 handle_event/3 调用时转发给它。
使用
{:ok, session} =
CMDC.create_agent(
model: "mock:test",
plugins: [
{CMDCTest.Plugin.Spy,
handler: fn
{:before_tool, name, args}, state, _ctx ->
send(self(), {:tool_intercepted, name, args})
{:continue, state}
_event, state, _ctx ->
{:continue, state}
end,
priority: 100}
]
)配置
:handler(必填)—(event, plugin_state, ctx) -> action_tuple:priority— 优先级,默认 500:initial_state—:handler看到的plugin_state,默认%{}