Examples
MessageAugmentPlugin 场景
用一个 pipeline 场景说明 plugin 如何对输入值做链式增强
MessageAugmentPlugin 场景
场景
你希望在消息进入主执行链之前,自动补一点上下文:
- 当前页面标题
- 当前来源标记
这类“进链前增强值”的场景,非常适合 pipeline。
示例
import { Agent, type Plugin } from "@downcity/agent";
export const messageAugmentPlugin: Plugin = {
name: "message_augment",
title: "Message Augment",
description: "Adds extra fields to inbound message payloads.",
hooks: {
pipeline: {
"chat.enrich_message": [
async ({ value }) => {
const body = value as Record<string, unknown>;
return {
...body,
source: body.source || "web",
pageTitle: body.pageTitle || "Untitled Page",
};
},
],
},
},
};
const agent = new Agent({
id: "repo-helper",
path: "/path/to/project",
tools: {},
plugins: [messageAugmentPlugin],
});
const message = await agent.plugins.pipeline("chat.enrich_message", {
text: "Please summarize this page",
});这个例子想表达什么
- pipeline 的重点是“拿到一个值,返回一个新值”
- 多个 plugin 可以继续往后接着改