Examples
MessageAugmentPlugin Scenario
Use a pipeline scenario to show how a plugin can enrich an inbound value step by step
MessageAugmentPlugin Scenario
Scenario
You want to enrich a message before it enters the main execution path:
- add the current page title
- add a source marker
This kind of pre-chain value enrichment is a strong fit for pipeline.
Example
import {
Agent,
BasePlugin,
type JsonObject,
type PluginHooks,
} from "@downcity/agent";
class MessageAugmentPlugin extends BasePlugin {
readonly name = "message_augment";
readonly title = "Message Augment";
readonly description = "Adds extra fields to inbound message payloads.";
readonly hooks: PluginHooks = {
pipeline: {
"chat.enrich_message": [
async ({ value }) => {
const body = value as JsonObject;
return {
...body,
source: body.source || "web",
pageTitle: body.pageTitle || "Untitled Page",
};
},
],
},
};
}
const agent = new Agent({
id: "repo-helper",
path: "/path/to/project",
tools: {},
plugins: [new MessageAugmentPlugin()],
});
const message = await agent.plugins.pipeline<JsonObject>("chat.enrich_message", {
text: "Please summarize this page",
});What this scenario is meant to teach
- a pipeline receives one value and returns a new value
- several plugins can extend the same chain in sequence