Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions packages/agent-sdk/src/managers/aiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,25 +891,13 @@ export class AIManager {
});
}

// Append: task reminder as system-reminder at tail (conditional rules already persisted above)
const tailParts: string[] = [];

// Task reminder: persist as meta message (conditional rules already persisted above)
const taskReminderText = await this.maybeGetTaskReminderText(toolNames);
if (taskReminderText) {
// Persist to messageManager so turn counter can find the marker on future turns
this.messageManager.addUserMessage({
content: taskReminderText,
isMeta: true,
});
// Also inject into current turn's API call (persisted message won't be in recentMessages)
tailParts.push(taskReminderText);
}

if (tailParts.length > 0) {
callAgentOptions.messages.push({
role: "user",
content: `<system-reminder>\n${tailParts.join("\n\n")}\n</system-reminder>`,
});
}

// Add streaming callbacks only if streaming is enabled
Expand Down
2 changes: 1 addition & 1 deletion specs/043-task-management-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
- **FR-027**:当任务列表非空时,提醒消息末尾必须附加当前任务列表,格式为 `#id [status] subject`(每个任务一行)。
- **FR-028**:当任务列表为空时,提醒消息必须仍然注入,作为通用提醒鼓励 agent 使用任务跟踪功能,但不附加任务列表。
- **FR-029**:提醒消息的文本必须明确指示 agent 不得向用户提及该提醒的存在。
- **FR-030**:任务提醒必须持久化到会话历史中作为 `isMeta: true` 用户消息,确保轮次计数器能找到之前的提醒标记(`<!-- task-reminder -->`),避免每轮重复注入。当前轮额外注入到 tail `<system-reminder>` 供 API 可见。
- **FR-030**:任务提醒必须持久化到会话历史中作为 `isMeta: true` 用户消息,确保轮次计数器能找到之前的提醒标记(`<!-- task-reminder -->`),避免每轮重复注入。
- **FR-031**:如果 TaskCreate 和 TaskUpdate 工具不在当前 agent 的可用工具集中,系统必须完全跳过任务提醒逻辑,不注入任何提醒消息。

### 关键实体 *(如果功能涉及数据则包含)*
Expand Down
14 changes: 14 additions & 0 deletions specs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,17 @@
| 服务端托管配置 | 从 Wave AI 下载并应用托管设置,支持校验和缓存和合并优先级 | 3 | 11 | [规格](055-server-managed-config.md) |
| OpenTelemetry 集成 | OpenTelemetry 指标、追踪和日志插桩,支持多种导出器(jsonl、OTLP) | 3 | 16 | [规格](052-opentelemetry.md) |
| 用量追踪 | SDK 用量追踪回调(`onUsagesChange`),用于 AI 调用和压缩 | 4 | 15 | [规格](010-usage-tracking-callback.md) |

## 上下文消息结构总览

发送给 AI 模型的 `messages` 数组按以下顺序组装:

| 位置 | 角色 | 内容 | 缓存标记 | 持久化 | 用户可见 | 说明 |
|------|------|------|----------|--------|----------|------|
| [0] | system | 基础系统提示词 + 任务执行准则 + 行动准则 + 工具策略 + 输出效率 + 语气风格 | 有 | 不持久化 | 否 | 子代理替换基础系统提示词,其余相同 |
| | | 语言指令 + `<env>` 环境信息 + 自动记忆 (MEMORY.md) | 无 | 不持久化 | 否 | |
| [1] | user (meta) | `<system-reminder>`: 项目 AGENTS.md + 用户 AGENTS.md + 无条件规则 | 无 | 不持久化,每轮插入头部 | 否 | 唯一每轮注入 |
| 历史 | user / assistant / tool | 文本块 / 图片块 / 工具块 / 后台任务通知块 / 推理块 | 最后一条有 | 持久化到 session JSONL | 是 | |
| | user (isMeta) | 计划模式提醒 / 条件规则 / 任务提醒 / Goal 消息 / SessionStart Hook 上下文 / 后台任务通知 / Token 限制续写 | 同上 | 同上 | 否 | 触发时插入当时的结尾,各类型有独立触发条件 |

**专用调用**(独立系统提示词,不经过主系统提示词组装):压缩、网页内容提取、BTW 旁路问题、Goal 评估、Workflow 结构化输出。