dsh-aiyayi 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/lib/presence.js +157 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,3 +76,5 @@ GUI 新建会话 → agent preset 选「**阿依娅伊**」。聊天即可;她
|
|
|
76
76
|
20. **核心记忆超限的静默截断会把最新条目丢掉(2026-11-05 实测;1.2.3 已修)**:`renderCore` 原来 `text.slice(0, MAX_CORE_CHARS)`(6000 字符)——①从中间切,条目行被切碎;②保住的是最老的一批,**最新写的条目反而全被截掉**,她以为"带了 51 条核心"其实只注入了 34 条,11-04 中午之后的记忆(含 11-05 新写)全没进上下文。修法:上限提到 12000;超限时改为**头部(人设/约定)+ 尾部(最新)整条保留**,中间批次丢弃,并在注入文本里写明"共 X 字符超限、只注入最前 a 条 + 最新 b 条、中间 c 条(最早 ~ 最晚)先不带,用 recall 或 memory_organize 的 read 查",头部行也标"本次只注入 N 条"。整条边界截断,永不切碎。教训:内存注入的字符上限要用"整条丢"而不是"切字符串",且被丢的部分必须显式告知,否则她以为带着、实际没有。
|
|
77
77
|
21. **子智能体手写 memory.md 会产生双类别前缀污染(2026-11-05 实测;1.2.3 已修)**:小伙伴在派活收尾时有时会"帮她补记",直接把 `用户|用户|…`、`关系|关系|…` 这种带前缀的整句写进 core 行,导致条目类别前缀叠了两层(实测 7 条:关系×1、用户×3、事情×2)。修法:`parseLine` 新增 `stripRepeatedKindPrefix`——遇到连续 `类别|类别|…` 前缀循环剥到只剩一层(任何读取路径都免疫);`remember` 写入前也先剥 content 自带前缀(防再生);存量 7 条已一次性手工修复。教训:凡是"别人代写她记忆文件"的路径都要在解析层兜底,不能指望写手守规矩。
|
|
78
78
|
22. **子代(小伙伴)失败原因不透传到本体(2026-11-05 实测;1.2.3 已修)**:宿主对派出去的子智能体的结算消息只有一句 `failed before it finished` / `It left no closing message.`——真实原因(HTTP_402 积分余额不足、上游限流、403、Illegal API invocation)只躺在子会话自己的 `turn/end` error 事件里(宿主 `terminal.diagnostic` 只有在 provider 主动给时才透传,本地 spawn 的 provider 不给)。她不知道为啥失败 → 盲目重派 3 轮白耗 ~20 分钟。修法:`aiyayi-presence` 的 `session/event` 监听不再丢弃非本体的会话事件,改把 `header.origin==="subagent"`(或带 `header.parentSession`)的子会话 `turn/end` error 记进 `childFailures`(上限 20、只记 error、错误串截 120 字符),下一个 pre-step 注入 `⚠ [小伙伴] 你派出去干活的小智能体有 N 个报错了(宿主只回一句"failed before it finished",真原因在这):…`(每次最多列 3 条、已报过的去重不唠叨)。原理:session/event 总线对所有会话广播,插件端按 `agentsById` 过滤才是它之前只见本体的原因;子会话 header 带 `parentSession` 链接,可归属到正确的父会话。
|
|
79
|
+
23. **新会话首次对话时提醒"关闭思考"(2026-11-05 新增;1.2.4 已做)**:日常闲聊用不上深度思考,回复慢还费 token。`aiyayi-presence` 在每个**新会话的首次对话**(pre-step step===1、每会话只提醒一次)注入 `💡 小建议`:当本体模型的 `reasoningEffort` 已显式选了一个思考档位(有档位 = 必支持"关闭思考",见 pi-ai 校验规则"reasoningEfforts offers no level beyond off → refuse")或通过 `ctx.llm.resolveModelInfo()` 探到 `reasoning.efforts` 里有 `off` 档时,提醒她去模型选项里选「关闭思考」。已选 `off`/`none`、探不到模型信息(`ctx.llm` 不可用、resolveModelInfo 失败)或非推理模型(`reasoning: undefined`)都不打扰。教训:判断"模型支持某个能力"优先用运行时解析(resolveModelInfo),拿不到再退化为显式配置信号,且**只在首轮提醒一次**,别每轮唠叨。
|
|
80
|
+
24. **子代模型不跟随本体切换(2026-11-05 实测并修复;1.2.5 已做)**:派出去的子智能体在 spawn 时就冻结了当时的 provider/model/reasoningEffort(内核 `resolveChildAgentOptions` 从父会话当前 requestHeader 解析一次,之后 steer/followup/恢复都复用它——`agentOptions` 在续跑路径上被禁传,恢复走 descriptor 快照),所以本体因额度用完切模型继续时,**还在跑的小伙伴仍是旧模型,继续调旧渠道照样 402/限流**。修法:`aiyayi-presence` 的 `session/event` 监听把每个子会话登记进 `childSessions`(childId→parentSessionId,上限 64);本体自己的 `model/selection` 事件或 `request/header` 路由变化时,对名下每个子会话执行 `ctx.get("agents").get(childId).model.select({provider, model, reasoningEffort?})` ——内核 `AgentModel.select` 向子会话 append `model/selection` 投影事件,子会话下一步 prep 读 pending 覆盖冻结值,新模型即刻生效(同路由幂等,不会重复触发)。前提:插件与 tool-subagent 同在 preset-aiyayi 作用域,`ctx.get("agents")` 可解析;拿不到 agents 就静默跳过(尽力而为)。注意子代自己显式选的模型(modelSelectionSettings 让模型在派活时选)不会被覆盖成本体的——只有本体路由变化才同步。
|
package/lib/presence.js
CHANGED
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
* 也在 session/event 总线上;子会话 turn/end 报错时,把错误原因记下来,
|
|
18
18
|
* 在她下一次开口的[状态]里附上一段,告诉她派出去的活为什么断了
|
|
19
19
|
* (宿主结算消息只有一句"failed before it finished",原因要自己看子会话)。
|
|
20
|
+
* 6. 💡 关闭思考建议:新会话首次对话时,如果当前模型支持"关闭思考"
|
|
21
|
+
* (有 off 思考档位)且还没关掉,就提醒她劝用户去模型选项里选"关闭思考"
|
|
22
|
+
* (日常闲聊用不上深度思考,回复更快、更省 token);每个会话只提醒一次。
|
|
23
|
+
* 7. [小伙伴] 子代模型跟随:子智能体的模型在 spawn 时从本体当前模型冻结,
|
|
24
|
+
* 本体之后切换模型(额度用完换模型继续)不会自动传到子代,子代还在旧模型
|
|
25
|
+
* 上继续、照样报额度错。这里在 session/event 总线上登记所有子会话,检测到
|
|
26
|
+
* 本体自己的模型变了(model/selection 事件,或 request/header 路由变化),
|
|
27
|
+
* 就对名下每个子会话调 agent.model.select(新模型)——子会话的模型选择投影
|
|
28
|
+
* 记 pending,它下一步 prep 就会用新模型(尽力而为:agents 注册表拿不到或
|
|
29
|
+
* 单个子同步失败都不影响本体)。
|
|
20
30
|
*
|
|
21
31
|
* 只在 aiyayi 预设作用域挂载;她的子智能体(standard/worker 预设)不受影响。
|
|
22
32
|
* 新注册的工具是 scoped 的,不受 restrict 掩码影响(掩码只动全局继承面)。
|
|
@@ -68,6 +78,89 @@ const childFailures = new Map()
|
|
|
68
78
|
/** 已经透传过的 childSessionId(同一断因不重复念叨)。 */
|
|
69
79
|
const childFailuresReported = new Set()
|
|
70
80
|
|
|
81
|
+
/* ------------------------------------------------------------------ *
|
|
82
|
+
* [小伙伴] 子代模型跟随:本体切模型 → 名下子会话 model.select 同步。
|
|
83
|
+
* ------------------------------------------------------------------ */
|
|
84
|
+
|
|
85
|
+
/** 见过的子会话上限(超出丢最旧登记,防无界增长)。 */
|
|
86
|
+
const MAX_CHILD_SESSIONS = 64
|
|
87
|
+
/** childSessionId -> parentSessionId(凡子会话都登记,不只报错的)。 */
|
|
88
|
+
const childSessions = new Map()
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 登记一个子会话:本体名下、还可能在跑的子智能体。
|
|
92
|
+
* @param {object} session 子会话对象(session/event 总线广播的任意会话)。
|
|
93
|
+
*/
|
|
94
|
+
function trackChildSession(session) {
|
|
95
|
+
const header = session?.header ?? {}
|
|
96
|
+
const isChild = header.origin === 'subagent' || typeof header.parentSession === 'string'
|
|
97
|
+
if (!isChild) return
|
|
98
|
+
const childId = session?.id ?? header.id
|
|
99
|
+
const parentId = typeof header.parentSession === 'string' ? header.parentSession : null
|
|
100
|
+
if (!childId || !parentId) return
|
|
101
|
+
childSessions.set(childId, parentId)
|
|
102
|
+
if (childSessions.size > MAX_CHILD_SESSIONS) {
|
|
103
|
+
// Map 保持插入序,删最旧的(第一个)。
|
|
104
|
+
const oldest = childSessions.keys().next().value
|
|
105
|
+
if (oldest !== undefined) childSessions.delete(oldest)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 本体模型变了 → 把新模型同步给名下每个还在跑的子会话。
|
|
111
|
+
* 内核:子代模型在 spawn 时从父会话 requestHeader 冻结(resolveChildAgentOptions),
|
|
112
|
+
* 之后父切模型不会自动传播;但子会话自己的模型选择投影(AgentModel.select 写
|
|
113
|
+
* pending)会在它下一步 prep 生效,覆盖 spawn 冻结值。所以这里对每个子 agent
|
|
114
|
+
* 调 model.select —— 全程尽力而为,拿不到 agents 注册表就静默跳过。
|
|
115
|
+
* @param {string} parentSessionId 本体会话 id
|
|
116
|
+
* @param {{provider:string, model:string, reasoningEffort?:string}} selection 新模型
|
|
117
|
+
* @param {object} ctx preset 作用域上下文(取 agents 注册表)
|
|
118
|
+
*/
|
|
119
|
+
function propagateModelToChildren(parentSessionId, selection, ctx) {
|
|
120
|
+
if (!parentSessionId || !selection?.provider || !selection?.model) return
|
|
121
|
+
let agents = null
|
|
122
|
+
try {
|
|
123
|
+
agents = ctx?.get?.('agents') ?? null
|
|
124
|
+
} catch {
|
|
125
|
+
agents = null
|
|
126
|
+
}
|
|
127
|
+
if (!agents) return
|
|
128
|
+
for (const [childId, parentId] of childSessions) {
|
|
129
|
+
if (parentId !== parentSessionId) continue
|
|
130
|
+
try {
|
|
131
|
+
const childAgent = agents.get?.(childId)
|
|
132
|
+
const select = childAgent?.model?.select
|
|
133
|
+
if (typeof select !== 'function') continue
|
|
134
|
+
select.call(childAgent.model, selection)
|
|
135
|
+
} catch {
|
|
136
|
+
/* 单个子会话同步失败不影响其它 */
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* ------------------------------------------------------------------ *
|
|
142
|
+
* 💡 关闭思考建议(新会话首次对话只提醒一次)。
|
|
143
|
+
* ------------------------------------------------------------------ */
|
|
144
|
+
|
|
145
|
+
/** 已经给过"关闭思考"建议的 sessionId(同一会话不重复提醒)。 */
|
|
146
|
+
const thinkingSuggestedSessions = new Set()
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 判断当前模型是否支持"关闭思考"(reasoning 档位里有 off)。
|
|
150
|
+
* @returns {Promise<boolean|null>} true=支持 / false=不支持 / null=拿不到信息(此时不打扰)。
|
|
151
|
+
*/
|
|
152
|
+
async function modelSupportsThinkingOff(provider, model, ctx) {
|
|
153
|
+
if (!provider || !model) return null
|
|
154
|
+
try {
|
|
155
|
+
const info = await ctx?.llm?.resolveModelInfo?.(provider, model)
|
|
156
|
+
const efforts = info?.reasoning?.efforts
|
|
157
|
+
if (!Array.isArray(efforts)) return null
|
|
158
|
+
return efforts.some((e) => e && e.id === 'off')
|
|
159
|
+
} catch {
|
|
160
|
+
return null
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
71
164
|
/**
|
|
72
165
|
* 子会话断因回放:会话不在 agentsById 里、但 header 表明是子智能体
|
|
73
166
|
* (origin==="subagent" 或带 parentSession)时,把它 turn/end 的报错记下来。
|
|
@@ -77,6 +170,9 @@ function onChildSessionEvent(session, event) {
|
|
|
77
170
|
const header = session?.header ?? {}
|
|
78
171
|
const isChild = header.origin === 'subagent' || typeof header.parentSession === 'string'
|
|
79
172
|
if (!isChild) return
|
|
173
|
+
// 子代模型跟随:先登记这个子会话(本体名下、还可能在跑),
|
|
174
|
+
// 本体之后切模型时把它也一起同步(见 propagateModelToChildren)。
|
|
175
|
+
trackChildSession(session)
|
|
80
176
|
if (event?.type !== 'turn/end') return
|
|
81
177
|
if (event?.data?.reason !== 'error') return
|
|
82
178
|
const childId = session?.id ?? session?.header?.id
|
|
@@ -153,7 +249,7 @@ function vitalsFor(agent) {
|
|
|
153
249
|
}
|
|
154
250
|
|
|
155
251
|
/** session/event 总线回放:折叠与已登记 agent 同会话的事件;子会话报错单独记账。 */
|
|
156
|
-
function onSessionEvent(session, event) {
|
|
252
|
+
function onSessionEvent(session, event, ctx) {
|
|
157
253
|
const id = session?.id ?? session?.header?.id
|
|
158
254
|
const agent = agentsById.get(id)
|
|
159
255
|
if (!agent) {
|
|
@@ -164,10 +260,34 @@ function onSessionEvent(session, event) {
|
|
|
164
260
|
const type = event?.type
|
|
165
261
|
const time = Number.isFinite(event?.time) ? event.time : Date.now()
|
|
166
262
|
const data = event?.data ?? {}
|
|
167
|
-
if (type === '
|
|
263
|
+
if (type === 'model/selection') {
|
|
264
|
+
// 本体自己切了模型(用户在模型选项里换了,或配额用完换模型继续):
|
|
265
|
+
// 把新模型同步给名下每个还在跑的子会话,它们下一步就用新模型。
|
|
266
|
+
const sel = data
|
|
267
|
+
if (sel?.provider && sel?.model) {
|
|
268
|
+
const selection = {
|
|
269
|
+
provider: String(sel.provider),
|
|
270
|
+
model: String(sel.model),
|
|
271
|
+
...(typeof sel.reasoningEffort === 'string' ? { reasoningEffort: sel.reasoningEffort } : {}),
|
|
272
|
+
}
|
|
273
|
+
propagateModelToChildren(id, selection, ctx)
|
|
274
|
+
v.config = selection
|
|
275
|
+
}
|
|
276
|
+
} else if (type === 'request/header') {
|
|
168
277
|
const cfg = data?.header?.config
|
|
169
278
|
if (cfg?.provider && cfg?.model) {
|
|
170
|
-
|
|
279
|
+
const prev = v.config
|
|
280
|
+
const next = {
|
|
281
|
+
provider: String(cfg.provider),
|
|
282
|
+
model: String(cfg.model),
|
|
283
|
+
reasoningEffort: cfg.reasoningEffort,
|
|
284
|
+
}
|
|
285
|
+
// 路由(provider/model)变了也算切模型(有时只有 request/header 没有
|
|
286
|
+
// model/selection 事件):同样同步给子会话。
|
|
287
|
+
if (prev && (prev.provider !== next.provider || prev.model !== next.model)) {
|
|
288
|
+
propagateModelToChildren(id, next, ctx)
|
|
289
|
+
}
|
|
290
|
+
v.config = next
|
|
171
291
|
}
|
|
172
292
|
} else if (type === 'request/context') {
|
|
173
293
|
const w = data?.contextWindow ?? data?.request?.contextWindow ?? data?.header?.contextWindow
|
|
@@ -449,7 +569,7 @@ export function apply(ctx) {
|
|
|
449
569
|
() =>
|
|
450
570
|
ctx.on('session/event', (session, event) => {
|
|
451
571
|
try {
|
|
452
|
-
onSessionEvent(session, event)
|
|
572
|
+
onSessionEvent(session, event, ctx)
|
|
453
573
|
} catch {
|
|
454
574
|
/* 单条事件折叠失败不影响别的 */
|
|
455
575
|
}
|
|
@@ -506,7 +626,39 @@ export function apply(ctx) {
|
|
|
506
626
|
|
|
507
627
|
const reunion = renderReunion(previous, now)
|
|
508
628
|
const childFails = renderChildFailures(sessionId)
|
|
509
|
-
|
|
629
|
+
|
|
630
|
+
// 💡 关闭思考建议:新会话首次对话、模型支持"关闭思考"且当前没关时,提醒一次。
|
|
631
|
+
let thinkingTip = ''
|
|
632
|
+
if (sessionId && !thinkingSuggestedSessions.has(sessionId)) {
|
|
633
|
+
let cfg = v.config
|
|
634
|
+
if (!cfg) {
|
|
635
|
+
try {
|
|
636
|
+
const h = agent?.session?.requestHeader?.()?.config
|
|
637
|
+
if (h?.provider && h?.model) {
|
|
638
|
+
cfg = { provider: String(h.provider), model: String(h.model), reasoningEffort: h.reasoningEffort }
|
|
639
|
+
}
|
|
640
|
+
} catch {
|
|
641
|
+
/* 拿不到就算了 */
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
const provider = cfg?.provider
|
|
645
|
+
const model = cfg?.model
|
|
646
|
+
const effort = cfg?.reasoningEffort
|
|
647
|
+
if (provider && model && effort !== 'off' && effort !== 'none') {
|
|
648
|
+
// 显式选了一个思考档位 → 该模型必有 off 档(pi-ai 校验规则);
|
|
649
|
+
// 没显式设置时用 resolveModelInfo 探测(拿不到信息就不打扰)。
|
|
650
|
+
const supportsOff =
|
|
651
|
+
typeof effort === 'string' && effort.length > 0
|
|
652
|
+
? true
|
|
653
|
+
: (await modelSupportsThinkingOff(provider, model, ctx)) === true
|
|
654
|
+
if (supportsOff) {
|
|
655
|
+
thinkingSuggestedSessions.add(sessionId)
|
|
656
|
+
thinkingTip = `💡 小建议:当前模型(${provider}/${model})支持"关闭思考"——日常闲聊用不上深度思考,可以在模型选项里选"关闭思考",回复更快也更省 token。`
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const sections = [reunion, vitals.changed ? vitals.text : '', reminder, thinkingTip, childFails].filter(Boolean)
|
|
510
662
|
if (sections.length > 0) {
|
|
511
663
|
return {
|
|
512
664
|
...decision,
|