自定义 Power
使用 Action、Hook、System、Lifecycle 与 City 构建自定义 Power。
Power 是 City 提供给 Agent 的能力。一个 City 中每个 Power ID 只有一个实例,所有已注册 Agent 自动获得全部 Power;Agent 不保存 Power,也不维护 Power 配置引用。
import { City, Workspace } from "@downcity/city";
import { Power, create_action } from "@downcity/city/power";
class NotesPower extends Power {
readonly name = "notes";
readonly title = "Notes Helper";
readonly description = "Adds note-related actions.";
readonly actions = {
status: create_action({
description: "Read current execution scope.",
execute: async ({ context }) => ({
success: true,
data: {
agent_id: context.agent.id,
workspace_id: context.workspace.id,
session_id: context.session?.id ?? null,
},
}),
}),
};
}
const workspace = new Workspace({ id: "project", path: process.cwd() });
const city = new City({ workspaces: [workspace], powers: [new NotesPower()] });
city.agents.add(agent);Action、Hook、System、Resolve、Availability、HTTP 与 Lifecycle 都通过 PowerContext 工作。
context.agent、context.workspace、context.session 和 context.turn 是受限的直接句柄;
运行数据写入 context.storage,不需要只依赖 ID 回查对象。
完整的 module、manifest、Context 与测试说明见 Power 开发指南。