MessageAugmentPower Scenario
Use a pipeline scenario to show how a power can enrich an inbound value step by step
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 {
Power,
type PowerJsonObject,
type PowerHooks,
} from "@downcity/city/power";
class MessageAugmentPower extends Power {
readonly name = "message_augment";
readonly title = "Message Augment";
readonly description = "Adds extra fields to inbound message payloads.";
readonly hooks: PowerHooks = {
pipeline: {
"chat.enrich_message": [
async ({ value }) => {
const body = value as PowerJsonObject;
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.powers.scope({ agent_id: agent.id, workspace_id: workspace.id }).pipeline<PowerJsonObject>("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 powers can extend the same chain in sequence