mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-08-28 05:25:04 +00:00
fix(dsh): deduplicate pending memory guidance
This commit is contained in:
parent
513fb5b7f4
commit
7efd850645
3 changed files with 31 additions and 12 deletions
|
|
@ -25,17 +25,25 @@ export function memoryGuidance(language: "en" | "zh" = "en"): string {
|
|||
return GUIDANCE[language];
|
||||
}
|
||||
|
||||
export function hasGuidance(session: DshSession): boolean {
|
||||
return (session.events || []).some((event) => {
|
||||
const source = isRecord(event.data) ? event.data.source : undefined;
|
||||
return (
|
||||
event.type === "user/message" &&
|
||||
isRecord(source) &&
|
||||
source.kind === "plugin" &&
|
||||
source.plugin === REME_PLUGIN_SOURCE &&
|
||||
source.form === "instructions"
|
||||
);
|
||||
});
|
||||
export function hasGuidance(
|
||||
session: DshSession,
|
||||
pendingMessages: readonly unknown[] = [],
|
||||
): boolean {
|
||||
return (
|
||||
(session.events || []).some(
|
||||
(event) => event.type === "user/message" && isGuidance(event.data),
|
||||
) || pendingMessages.some(isGuidance)
|
||||
);
|
||||
}
|
||||
|
||||
function isGuidance(value: unknown): boolean {
|
||||
const source = isRecord(value) ? value.source : undefined;
|
||||
return (
|
||||
isRecord(source) &&
|
||||
source.kind === "plugin" &&
|
||||
source.plugin === REME_PLUGIN_SOURCE &&
|
||||
source.form === "instructions"
|
||||
);
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,11 @@ export function apply(ctx: Context, input: ReMeConfigInput = {}): void {
|
|||
() => () => runtime.dispose(agent.session),
|
||||
"remeMemory.disposeSession()",
|
||||
);
|
||||
if (agent.status !== "idle" || hasGuidance(agent.session)) return;
|
||||
if (
|
||||
agent.status !== "idle" ||
|
||||
hasGuidance(agent.session, agent.inbox.nextStep)
|
||||
)
|
||||
return;
|
||||
agent.inject(
|
||||
createUserMessage({
|
||||
content: [{ type: "text", text: memoryGuidance(config.language) }],
|
||||
|
|
|
|||
|
|
@ -42,11 +42,14 @@ test("composes root-agent guidance and reme_search on supported DSH releases", a
|
|||
|
||||
const injected = [];
|
||||
const agentCleanups = [];
|
||||
const nextStep = [];
|
||||
const agent = {
|
||||
status: "idle",
|
||||
session: { id: "root", header: {}, events: [] },
|
||||
inbox: { nextStep },
|
||||
inject(message) {
|
||||
injected.push(message);
|
||||
nextStep.push(message);
|
||||
},
|
||||
ctx: {
|
||||
effect(execute) {
|
||||
|
|
@ -62,6 +65,9 @@ test("composes root-agent guidance and reme_search on supported DSH releases", a
|
|||
assert.equal(injected[0].source.plugin, "reme-memory");
|
||||
assert.match(injected[0].content[0].text, /长期记忆/);
|
||||
|
||||
handlers.get("agent/session-start")({ agent, source: "resume" });
|
||||
assert.equal(injected.length, 1);
|
||||
|
||||
await Promise.all(agentCleanups.map((cleanup) => cleanup()));
|
||||
await Promise.all(cleanups.map((cleanup) => cleanup()));
|
||||
});
|
||||
|
|
@ -162,6 +168,7 @@ test("registers a ReMe settings namespace and reads changed values for new sessi
|
|||
agent: {
|
||||
status: "idle",
|
||||
session: { id: "settings-session", header: {}, events: [] },
|
||||
inbox: { nextStep: [] },
|
||||
inject(message) {
|
||||
injected.push(message);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue