Sessions

session.system()

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

session.system()

示例

const system = await session.system();

它返回什么

返回结构化 system snapshot:

{
  sessionId: string;
  session: {
    agentId: string;
    sessionId: string;
    projectRoot: string;
    createdAt: string;
    timezone: string;
  };
  blocks: Array<{
    source: "core" | "instruction" | "plugin" | "session";
    name: string;
    content: string;
  }>;
}

这些 blocks 可以包括:

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

返回内容和 session.prompt() 使用的是同一套稳定 system blocks。

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

Block 顺序

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

  1. instruction:宿主传入的 Agent 角色、业务规则和回复偏好。
  2. core:Downcity Agent 固定运行说明,包括 Harness 设计思路、Shell command 与 plugin 系统总规则。
  3. plugin:每个已经启用、已 ready 且当前可用的 plugin 自己的 system prompt。
  4. session:当前 session 的稳定上下文。

即使宿主传入了 instructioncore 也会继续注入,并紧跟在 instruction 后面。

示例快照

{
  "sessionId": "design-review",
  "session": {
    "agentId": "city-dev",
    "sessionId": "design-review",
    "projectRoot": "/path/to/project",
    "createdAt": "2026-05-19T14:16:25.048Z",
    "timezone": "Asia/Shanghai"
  },
  "blocks": [
    {
      "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\nCommand execution tools:\n- Prefer `shell_exec` for short, one-off commands.\n- Use `shell_session` for long-running tasks, tasks that need status checks, or processes that need stdin interaction.\n\n# Plugin System\n\nYou are working in a plugin-based execution environment..."
    },
    {
      "source": "plugin",
      "name": "task",
      "content": "# Task Plugin\n\nThe task plugin manages scheduled and repeatable tasks..."
    },
    {
      "source": "session",
      "name": "context",
      "content": "当前会话上下文:\n你正在服务 agent \"city-dev\" 的 session \"design-review\"\n当前项目根目录是 \"/path/to/project\"\n本会话创建于 2026-05-19T14:16:25.048Z,参考时区是 Asia/Shanghai。\n这个创建时间是当前会话的稳定参考时间,不代表每轮运行时的当前时间。\n如果用户消息中提供了新的当前时间、相对时间或其他动态上下文,应优先使用用户消息中的动态信息。"
    }
  ]
}

它不会做什么

session.system() 不会把 system prompt 写进 active.jsonl 或历史 Segment。

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