Examples
MessageAugmentPlugin 场景
用一个 pipeline 场景说明 plugin 如何对输入值做链式增强
MessageAugmentPlugin 场景
场景
你希望在消息进入主执行链之前,自动补一点上下文:
- 当前页面标题
- 当前来源标记
这类“进链前增强值”的场景,非常适合 pipeline。
示例
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",
});这个例子想表达什么
- pipeline 的重点是“拿到一个值,返回一个新值”
- 多个 plugin 可以继续往后接着改