session.system()

读取当前 Session 生效的结构化 system prompt 快照

示例

const system = await session.system();

它返回什么

返回结构化 system snapshot:

{
  session_id: string;
  session: {
    agent_id: string;
    session_id: string;
    project_root: string;
    created_at: string;
    timezone: string;
  };
  blocks: Array<{
    source: "core" | "instruction" | "power" | "session";
    name: string;
    content: string;
  }>;
}

这些 blocks 可以包括:

  • Agent 身份块,携带 Agent 的 name 与 id
  • 调用方传入的静态 instruction
  • Downcity Agent core 说明,包括 Harness 设计思路、Shell command 规则和 Power 系统总规则
  • 已注册并启用的 Power system 文本
  • 稳定的 session 上下文,包括 session_id、project_root、创建时间与时区

返回内容和 session.prompt() 使用的是同一套稳定 system blocks。system 第一次生成后会固定在当前 Session 内存中;后续 Agent instruction 或 Power registry 变化不会修改它。新 Session 才会使用最新配置生成 system。

需要让已有本地 Session 显式采用 Agent 当前配置时,调用 session.syncshot()。

session 创建时间和时区是当前会话的参考时间上下文。当前时间等动态值应放入 user message,不应放进 instruction。

Block 顺序

@downcity/agent 会按固定顺序构造 system blocks:

  1. instruction / identity:由 SDK 注入的 Agent name 与 id。同一个 Agent 的所有 Session 共享这份身份。
  2. instruction / agent:宿主传入的 Agent 角色、业务规则和回复偏好。
  3. core:Downcity Agent 固定运行说明,包括 Harness 设计思路、Shell command 与 Power 系统总规则。
  4. power:每个已经启用、已 ready 且当前可用的 Power 自己的 system prompt。
  5. session:当前 session 的稳定上下文。

即使宿主传入了 instruction,core 也会继续注入,并紧跟在 instruction 后面。session 块只描述 session 自身,不重复 Agent 身份。

示例快照

{
  "session_id": "design-review",
  "session": {
    "agent_id": "reviewer",
    "session_id": "design-review",
    "project_root": "/path/to/project",
    "created_at": "2026-05-19T14:16:25.048Z",
    "timezone": "Asia/Shanghai"
  },
  "blocks": [
    {
      "source": "instruction",
      "name": "identity",
      "content": "# Agent Identity\n\nYou are \"代码审查员\" (agent id: reviewer)."
    },
    {
      "source": "instruction",
      "name": "agent",
      "content": "你是 Downcity 的项目助手。"
    },
    {
      "source": "core",
      "name": "default",
      "content": "# Downcity Agent\n\nYou are a Downcity Agent running inside the Downcity Agent runtime...\n\n# Harness Design\n\nDowncity Agent is a harness around an existing human-owned workspace, not a replacement platform...\n\n# Shell Commands\n\nAll Shell work goes through the `shell` power...\n\n# Power System\n\nYou are working in a power-based execution environment..."
    },
    {
      "source": "power",
      "name": "task",
      "content": "# Task Power\n\nYou can use the `task` power to manage task definitions, execution, scheduling, and status control..."
    },
    {
      "source": "session",
      "name": "context",
      "content": "Current session context:\nThis session is \"design-review\".\nThe current project root is \"/path/to/project\".\nThis session was created at 2026-05-19T14:16:25.048Z, with Asia/Shanghai as its reference timezone.\nThis creation time is a stable reference for the session and does not represent the current time for every run.\nIf the user message provides a newer current time, a relative time, or other dynamic context, prioritize the dynamic information from the user message."
    }
  ]
}

它不会做什么

session.system() 不会把 system prompt 写进 canonical Message history。

Session history 仍然只关注可见的 user / assistant 消息。如果你需要检查当前会随历史一起进入模型的提示词上下文,用 system()。