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 {
Plugin,
type PluginJsonObject,
type PluginHooks,
} from "@downcity/city/plugin";
class MessageAugmentPlugin extends Plugin {
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 PluginJsonObject;
return {
...body,
source: body.source || "web",
pageTitle: body.pageTitle || "Untitled Page",
};
},
],
},
};
}
// City has registered message_augment and bound it to entry's Agent/Workspace.
const message = await city.plugins.scope({ agent_id: agent.id, workspace_id: workspace.id }).pipeline<PluginJsonObject>("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