Examples
AuditEffectPlugin Scenario
Use an effect scenario to show how a plugin can do side effects without rewriting the main value
AuditEffectPlugin Scenario
Scenario
You want to record an event:
- a message arrived
- an action was triggered
but you do not want to:
- transform the value
- block the flow
That is a clean effect use case.
Example
import { Agent, BasePlugin, type PluginHooks } from "@downcity/agent";
class AuditEffectPlugin extends BasePlugin {
readonly name = "audit_effect";
readonly title = "Audit Effect";
readonly description = "Writes one audit line for every observed event.";
readonly hooks: PluginHooks = {
effect: {
"audit.observe": [
async ({ value, plugin }) => {
console.log(`[${plugin}] observed`, value);
},
],
},
};
}
const agent = new Agent({
id: "repo-helper",
path: "/path/to/project",
tools: {},
plugins: [new AuditEffectPlugin()],
});
await agent.plugins.effect("audit.observe", {
event: "incoming_message",
sessionId: "sess_001",
});Why this is not a pipeline
Because you do not care about returning a new value. The side effect is the whole point.