indusagi 0.12.13 → 0.12.15
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/dist/agent/tools/registry.d.ts +1 -1
- package/dist/agent/tools/registry.d.ts.map +1 -1
- package/dist/agent/types.d.ts +1 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/ai/models.generated.d.ts +621 -53
- package/dist/ai/models.generated.d.ts.map +1 -1
- package/dist/ai/models.generated.js +548 -0
- package/dist/ai/models.generated.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/client-pool.d.ts +106 -0
- package/dist/mcp/client-pool.d.ts.map +1 -0
- package/dist/mcp/client-pool.js +233 -0
- package/dist/mcp/client-pool.js.map +1 -0
- package/dist/mcp/client.d.ts +158 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +586 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config.d.ts +61 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +250 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/errors.d.ts +104 -0
- package/dist/mcp/errors.d.ts.map +1 -0
- package/dist/mcp/errors.js +138 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +56 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +83 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/schema-converter.d.ts +68 -0
- package/dist/mcp/schema-converter.d.ts.map +1 -0
- package/dist/mcp/schema-converter.js +230 -0
- package/dist/mcp/schema-converter.js.map +1 -0
- package/dist/mcp/server.d.ts +111 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +300 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tool-factory.d.ts +63 -0
- package/dist/mcp/tool-factory.d.ts.map +1 -0
- package/dist/mcp/tool-factory.js +228 -0
- package/dist/mcp/tool-factory.js.map +1 -0
- package/dist/mcp/types.d.ts +289 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +8 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/mcp.d.ts +6 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +6 -0
- package/dist/mcp.js.map +1 -0
- package/dist/memory/embedder/base.d.ts +41 -0
- package/dist/memory/embedder/base.d.ts.map +1 -0
- package/dist/memory/embedder/base.js +10 -0
- package/dist/memory/embedder/base.js.map +1 -0
- package/dist/memory/embedder/index.d.ts +8 -0
- package/dist/memory/embedder/index.d.ts.map +1 -0
- package/dist/memory/embedder/index.js +6 -0
- package/dist/memory/embedder/index.js.map +1 -0
- package/dist/memory/embedder/openai.d.ts +35 -0
- package/dist/memory/embedder/openai.d.ts.map +1 -0
- package/dist/memory/embedder/openai.js +103 -0
- package/dist/memory/embedder/openai.js.map +1 -0
- package/dist/memory/index.d.ts +33 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +31 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/memory.d.ts +126 -0
- package/dist/memory/memory.d.ts.map +1 -0
- package/dist/memory/memory.js +280 -0
- package/dist/memory/memory.js.map +1 -0
- package/dist/memory/processors/base.d.ts +42 -0
- package/dist/memory/processors/base.d.ts.map +1 -0
- package/dist/memory/processors/base.js +6 -0
- package/dist/memory/processors/base.js.map +1 -0
- package/dist/memory/processors/index.d.ts +16 -0
- package/dist/memory/processors/index.d.ts.map +1 -0
- package/dist/memory/processors/index.js +18 -0
- package/dist/memory/processors/index.js.map +1 -0
- package/dist/memory/processors/message-history.d.ts +35 -0
- package/dist/memory/processors/message-history.d.ts.map +1 -0
- package/dist/memory/processors/message-history.js +51 -0
- package/dist/memory/processors/message-history.js.map +1 -0
- package/dist/memory/processors/observational-memory/index.d.ts +82 -0
- package/dist/memory/processors/observational-memory/index.d.ts.map +1 -0
- package/dist/memory/processors/observational-memory/index.js +234 -0
- package/dist/memory/processors/observational-memory/index.js.map +1 -0
- package/dist/memory/processors/observational-memory/observer-agent.d.ts +64 -0
- package/dist/memory/processors/observational-memory/observer-agent.d.ts.map +1 -0
- package/dist/memory/processors/observational-memory/observer-agent.js +362 -0
- package/dist/memory/processors/observational-memory/observer-agent.js.map +1 -0
- package/dist/memory/processors/observational-memory/reflector-agent.d.ts +38 -0
- package/dist/memory/processors/observational-memory/reflector-agent.d.ts.map +1 -0
- package/dist/memory/processors/observational-memory/reflector-agent.js +213 -0
- package/dist/memory/processors/observational-memory/reflector-agent.js.map +1 -0
- package/dist/memory/processors/observational-memory/token-counter.d.ts +35 -0
- package/dist/memory/processors/observational-memory/token-counter.d.ts.map +1 -0
- package/dist/memory/processors/observational-memory/token-counter.js +90 -0
- package/dist/memory/processors/observational-memory/token-counter.js.map +1 -0
- package/dist/memory/processors/semantic-recall.d.ts +55 -0
- package/dist/memory/processors/semantic-recall.d.ts.map +1 -0
- package/dist/memory/processors/semantic-recall.js +143 -0
- package/dist/memory/processors/semantic-recall.js.map +1 -0
- package/dist/memory/processors/working-memory.d.ts +41 -0
- package/dist/memory/processors/working-memory.d.ts.map +1 -0
- package/dist/memory/processors/working-memory.js +82 -0
- package/dist/memory/processors/working-memory.js.map +1 -0
- package/dist/memory/storage/base.d.ts +288 -0
- package/dist/memory/storage/base.d.ts.map +1 -0
- package/dist/memory/storage/base.js +211 -0
- package/dist/memory/storage/base.js.map +1 -0
- package/dist/memory/storage/index.d.ts +9 -0
- package/dist/memory/storage/index.d.ts.map +1 -0
- package/dist/memory/storage/index.js +7 -0
- package/dist/memory/storage/index.js.map +1 -0
- package/dist/memory/storage/inmemory.d.ts +93 -0
- package/dist/memory/storage/inmemory.d.ts.map +1 -0
- package/dist/memory/storage/inmemory.js +646 -0
- package/dist/memory/storage/inmemory.js.map +1 -0
- package/dist/memory/tools/working-memory.d.ts +100 -0
- package/dist/memory/tools/working-memory.d.ts.map +1 -0
- package/dist/memory/tools/working-memory.js +237 -0
- package/dist/memory/tools/working-memory.js.map +1 -0
- package/dist/memory/types.d.ts +386 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +58 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/memory/vector/base.d.ts +145 -0
- package/dist/memory/vector/base.d.ts.map +1 -0
- package/dist/memory/vector/base.js +83 -0
- package/dist/memory/vector/base.js.map +1 -0
- package/dist/memory/vector/index.d.ts +8 -0
- package/dist/memory/vector/index.d.ts.map +1 -0
- package/dist/memory/vector/index.js +7 -0
- package/dist/memory/vector/index.js.map +1 -0
- package/dist/memory/vector/inmemory.d.ts +47 -0
- package/dist/memory/vector/inmemory.d.ts.map +1 -0
- package/dist/memory/vector/inmemory.js +234 -0
- package/dist/memory/vector/inmemory.js.map +1 -0
- package/package.json +32 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observational Memory Processor
|
|
3
|
+
* Based on Mastra ObservationalMemory
|
|
4
|
+
*/
|
|
5
|
+
import type { MemoryProcessor, ProcessorContext } from "../base.js";
|
|
6
|
+
import type { CoreMessage, ObservationalMemoryOptions } from "../../types.js";
|
|
7
|
+
import type { MemoryStorage } from "../../storage/base.js";
|
|
8
|
+
/**
|
|
9
|
+
* Default observational memory configuration
|
|
10
|
+
*/
|
|
11
|
+
export declare const OBSERVATIONAL_MEMORY_DEFAULTS: {
|
|
12
|
+
readonly observation: {
|
|
13
|
+
readonly model: "google/gemini-2.5-flash";
|
|
14
|
+
readonly messageTokens: 30000;
|
|
15
|
+
readonly modelSettings: {
|
|
16
|
+
readonly temperature: 0.3;
|
|
17
|
+
readonly maxOutputTokens: 100000;
|
|
18
|
+
};
|
|
19
|
+
readonly maxTokensPerBatch: 10000;
|
|
20
|
+
readonly bufferTokens: 0.2;
|
|
21
|
+
readonly bufferActivation: 0.8;
|
|
22
|
+
};
|
|
23
|
+
readonly reflection: {
|
|
24
|
+
readonly model: "google/gemini-2.5-flash";
|
|
25
|
+
readonly observationTokens: 40000;
|
|
26
|
+
readonly modelSettings: {
|
|
27
|
+
readonly temperature: 0;
|
|
28
|
+
readonly maxOutputTokens: 100000;
|
|
29
|
+
};
|
|
30
|
+
readonly bufferActivation: 0.5;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Continuation hint for observation batches
|
|
35
|
+
*/
|
|
36
|
+
export declare const OBSERVATION_CONTINUATION_HINT = "This message is not from the user...";
|
|
37
|
+
/**
|
|
38
|
+
* Observational memory processor configuration
|
|
39
|
+
*/
|
|
40
|
+
export interface ObservationalMemoryProcessorConfig {
|
|
41
|
+
storage: MemoryStorage;
|
|
42
|
+
config: ObservationalMemoryOptions;
|
|
43
|
+
model?: string;
|
|
44
|
+
callLLM?: (params: {
|
|
45
|
+
systemPrompt: string;
|
|
46
|
+
userPrompt: string;
|
|
47
|
+
model?: string;
|
|
48
|
+
modelSettings?: Record<string, unknown>;
|
|
49
|
+
}) => Promise<string>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Observational Memory Processor
|
|
53
|
+
*
|
|
54
|
+
* Implements a three-tier memory system:
|
|
55
|
+
* 1. Observer: Extracts observations from messages
|
|
56
|
+
* 2. Reflector: Consolidates observations when they grow too large
|
|
57
|
+
* 3. Actor: Uses observations as context for responses
|
|
58
|
+
*/
|
|
59
|
+
export declare class ObservationalMemory implements MemoryProcessor {
|
|
60
|
+
readonly id = "observational-memory";
|
|
61
|
+
readonly name = "Observational Memory Processor";
|
|
62
|
+
private storage;
|
|
63
|
+
private config;
|
|
64
|
+
private model?;
|
|
65
|
+
private callLLM?;
|
|
66
|
+
private tokenCounter;
|
|
67
|
+
constructor(config: ObservationalMemoryProcessorConfig);
|
|
68
|
+
processInputStep(args: {
|
|
69
|
+
messages: CoreMessage[];
|
|
70
|
+
context: ProcessorContext;
|
|
71
|
+
}): Promise<CoreMessage[]>;
|
|
72
|
+
processOutputResult(args: {
|
|
73
|
+
messages: CoreMessage[];
|
|
74
|
+
context: ProcessorContext;
|
|
75
|
+
}): Promise<CoreMessage[]>;
|
|
76
|
+
private runObservation;
|
|
77
|
+
private runReflection;
|
|
78
|
+
private getOrCreateRecord;
|
|
79
|
+
private getObservationConfig;
|
|
80
|
+
private getReflectionConfig;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/memory/processors/observational-memory/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAuC,MAAM,gBAAgB,CAAC;AACnH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AA0B3D;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;CAehC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,6BAA6B,yCAAyC,CAAC;AAEpF;;GAEG;AACH,MAAM,WAAW,kCAAkC;IACjD,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,0BAA0B,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACzC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,QAAQ,CAAC,EAAE,0BAA0B;IACrC,QAAQ,CAAC,IAAI,oCAAoC;IAEjD,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,OAAO,CAAC,CAAgD;IAChE,OAAO,CAAC,YAAY,CAAe;gBAEvB,MAAM,EAAE,kCAAkC;IAYhD,gBAAgB,CAAC,IAAI,EAAE;QAC3B,QAAQ,EAAE,WAAW,EAAE,CAAC;QACxB,OAAO,EAAE,gBAAgB,CAAC;KAC3B,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAsCpB,mBAAmB,CAAC,IAAI,EAAE;QAC9B,QAAQ,EAAE,WAAW,EAAE,CAAC;QACxB,OAAO,EAAE,gBAAgB,CAAC;KAC3B,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YA+BZ,cAAc;YAoEd,aAAa;YAgEb,iBAAiB;IAoB/B,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,mBAAmB;CAM5B"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observational Memory Processor
|
|
3
|
+
* Based on Mastra ObservationalMemory
|
|
4
|
+
*/
|
|
5
|
+
import { TokenCounter } from "./token-counter.js";
|
|
6
|
+
import { buildObserverSystemPrompt, buildObserverPrompt, parseObserverOutput, } from "./observer-agent.js";
|
|
7
|
+
import { buildReflectorSystemPrompt, buildReflectorPrompt, parseReflectorOutput, validateCompression, } from "./reflector-agent.js";
|
|
8
|
+
/**
|
|
9
|
+
* Default observational memory configuration
|
|
10
|
+
*/
|
|
11
|
+
export const OBSERVATIONAL_MEMORY_DEFAULTS = {
|
|
12
|
+
observation: {
|
|
13
|
+
model: "google/gemini-2.5-flash",
|
|
14
|
+
messageTokens: 30_000,
|
|
15
|
+
modelSettings: { temperature: 0.3, maxOutputTokens: 100_000 },
|
|
16
|
+
maxTokensPerBatch: 10_000,
|
|
17
|
+
bufferTokens: 0.2,
|
|
18
|
+
bufferActivation: 0.8,
|
|
19
|
+
},
|
|
20
|
+
reflection: {
|
|
21
|
+
model: "google/gemini-2.5-flash",
|
|
22
|
+
observationTokens: 40_000,
|
|
23
|
+
modelSettings: { temperature: 0, maxOutputTokens: 100_000 },
|
|
24
|
+
bufferActivation: 0.5,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Continuation hint for observation batches
|
|
29
|
+
*/
|
|
30
|
+
export const OBSERVATION_CONTINUATION_HINT = `This message is not from the user...`;
|
|
31
|
+
/**
|
|
32
|
+
* Observational Memory Processor
|
|
33
|
+
*
|
|
34
|
+
* Implements a three-tier memory system:
|
|
35
|
+
* 1. Observer: Extracts observations from messages
|
|
36
|
+
* 2. Reflector: Consolidates observations when they grow too large
|
|
37
|
+
* 3. Actor: Uses observations as context for responses
|
|
38
|
+
*/
|
|
39
|
+
export class ObservationalMemory {
|
|
40
|
+
constructor(config) {
|
|
41
|
+
this.id = "observational-memory";
|
|
42
|
+
this.name = "Observational Memory Processor";
|
|
43
|
+
this.storage = config.storage;
|
|
44
|
+
this.config = config.config;
|
|
45
|
+
this.model = config.model;
|
|
46
|
+
this.callLLM = config.callLLM;
|
|
47
|
+
this.tokenCounter = new TokenCounter();
|
|
48
|
+
}
|
|
49
|
+
// ========================================================================
|
|
50
|
+
// Input Processing
|
|
51
|
+
// ========================================================================
|
|
52
|
+
async processInputStep(args) {
|
|
53
|
+
const { messages, context } = args;
|
|
54
|
+
// Get or initialize observational memory record
|
|
55
|
+
const record = await this.getOrCreateRecord(context);
|
|
56
|
+
// Build context with observations
|
|
57
|
+
const contextMessages = [];
|
|
58
|
+
// Add observations if available
|
|
59
|
+
if (record.activeObservations) {
|
|
60
|
+
const observationsMessage = {
|
|
61
|
+
id: `observations-${Date.now()}`,
|
|
62
|
+
role: "system",
|
|
63
|
+
content: `<observational_memory>\n${record.activeObservations}\n</observational_memory>`,
|
|
64
|
+
createdAt: new Date(),
|
|
65
|
+
};
|
|
66
|
+
contextMessages.push(observationsMessage);
|
|
67
|
+
}
|
|
68
|
+
// Get recent messages from storage
|
|
69
|
+
const { messages: storedMessages } = await this.storage.listMessages({
|
|
70
|
+
threadId: context.threadId,
|
|
71
|
+
perPage: 50,
|
|
72
|
+
orderBy: { field: "createdAt", direction: "DESC" },
|
|
73
|
+
});
|
|
74
|
+
// Reverse to get chronological order
|
|
75
|
+
const chronologicalMessages = storedMessages.reverse();
|
|
76
|
+
// Combine: observations + stored messages + new messages
|
|
77
|
+
return [...contextMessages, ...chronologicalMessages, ...messages];
|
|
78
|
+
}
|
|
79
|
+
// ========================================================================
|
|
80
|
+
// Output Processing
|
|
81
|
+
// ========================================================================
|
|
82
|
+
async processOutputResult(args) {
|
|
83
|
+
const { messages, context } = args;
|
|
84
|
+
// Check if read-only
|
|
85
|
+
if (context.memoryConfig?.readOnly) {
|
|
86
|
+
return messages;
|
|
87
|
+
}
|
|
88
|
+
// Save new messages
|
|
89
|
+
await this.storage.saveMessages({ messages });
|
|
90
|
+
// Check if observation is needed
|
|
91
|
+
const record = await this.getOrCreateRecord(context);
|
|
92
|
+
const newTokens = this.tokenCounter.countMessages(messages);
|
|
93
|
+
const totalPendingTokens = record.pendingMessageTokens + newTokens;
|
|
94
|
+
const observationConfig = this.getObservationConfig();
|
|
95
|
+
const threshold = observationConfig.messageTokens ?? 30_000;
|
|
96
|
+
if (totalPendingTokens >= threshold) {
|
|
97
|
+
// Trigger observation
|
|
98
|
+
await this.runObservation(context, record, totalPendingTokens);
|
|
99
|
+
}
|
|
100
|
+
return messages;
|
|
101
|
+
}
|
|
102
|
+
// ========================================================================
|
|
103
|
+
// Observation
|
|
104
|
+
// ========================================================================
|
|
105
|
+
async runObservation(context, record, pendingTokens) {
|
|
106
|
+
const observationConfig = this.getObservationConfig();
|
|
107
|
+
// Get unobserved messages
|
|
108
|
+
const { messages } = await this.storage.listMessages({
|
|
109
|
+
threadId: context.threadId,
|
|
110
|
+
perPage: 100,
|
|
111
|
+
});
|
|
112
|
+
// Build prompt
|
|
113
|
+
const systemPrompt = buildObserverSystemPrompt(false, observationConfig.instruction);
|
|
114
|
+
const userPrompt = buildObserverPrompt(record.activeObservations || undefined, messages);
|
|
115
|
+
// Call LLM
|
|
116
|
+
if (!this.callLLM) {
|
|
117
|
+
console.warn("ObservationalMemory: No LLM call function provided, skipping observation");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const output = await this.callLLM({
|
|
122
|
+
systemPrompt,
|
|
123
|
+
userPrompt,
|
|
124
|
+
model: observationConfig.model ?? this.model,
|
|
125
|
+
modelSettings: observationConfig.modelSettings,
|
|
126
|
+
});
|
|
127
|
+
const result = parseObserverOutput(output);
|
|
128
|
+
if (result.degenerate) {
|
|
129
|
+
console.warn("ObservationalMemory: Degenerate output detected, skipping");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// Update record with new observations
|
|
133
|
+
const newObservations = record.activeObservations
|
|
134
|
+
? `${record.activeObservations}\n\n${result.observations}`
|
|
135
|
+
: result.observations;
|
|
136
|
+
const newTokenCount = this.tokenCounter.countObservations(newObservations);
|
|
137
|
+
await this.storage.updateActiveObservations({
|
|
138
|
+
id: record.id,
|
|
139
|
+
observations: newObservations,
|
|
140
|
+
tokenCount: newTokenCount,
|
|
141
|
+
lastObservedAt: new Date(),
|
|
142
|
+
});
|
|
143
|
+
// Check if reflection is needed
|
|
144
|
+
const reflectionConfig = this.getReflectionConfig();
|
|
145
|
+
const reflectionThreshold = reflectionConfig.observationTokens ?? 40_000;
|
|
146
|
+
if (newTokenCount >= reflectionThreshold) {
|
|
147
|
+
await this.runReflection(context, newObservations);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.error("ObservationalMemory: Observation failed:", error);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// ========================================================================
|
|
155
|
+
// Reflection
|
|
156
|
+
// ========================================================================
|
|
157
|
+
async runReflection(context, observations) {
|
|
158
|
+
const reflectionConfig = this.getReflectionConfig();
|
|
159
|
+
if (!this.callLLM) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const systemPrompt = buildReflectorSystemPrompt(reflectionConfig.instruction);
|
|
163
|
+
const userPrompt = buildReflectorPrompt(observations);
|
|
164
|
+
try {
|
|
165
|
+
let output = await this.callLLM({
|
|
166
|
+
systemPrompt,
|
|
167
|
+
userPrompt,
|
|
168
|
+
model: reflectionConfig.model ?? this.model,
|
|
169
|
+
modelSettings: reflectionConfig.modelSettings,
|
|
170
|
+
});
|
|
171
|
+
let result = parseReflectorOutput(output);
|
|
172
|
+
// Try compression if needed
|
|
173
|
+
const targetThreshold = reflectionConfig.observationTokens ?? 40_000;
|
|
174
|
+
let compressionLevel = 0;
|
|
175
|
+
while (!result.degenerate &&
|
|
176
|
+
compressionLevel < 3 &&
|
|
177
|
+
!validateCompression(this.tokenCounter.countObservations(result.observations), targetThreshold)) {
|
|
178
|
+
compressionLevel = Math.min(3, compressionLevel + 1);
|
|
179
|
+
const retryPrompt = buildReflectorPrompt(observations, undefined, compressionLevel);
|
|
180
|
+
output = await this.callLLM({
|
|
181
|
+
systemPrompt,
|
|
182
|
+
userPrompt: retryPrompt,
|
|
183
|
+
model: reflectionConfig.model ?? this.model,
|
|
184
|
+
modelSettings: reflectionConfig.modelSettings,
|
|
185
|
+
});
|
|
186
|
+
result = parseReflectorOutput(output);
|
|
187
|
+
}
|
|
188
|
+
if (result.degenerate) {
|
|
189
|
+
console.warn("ObservationalMemory: Degenerate reflection output, keeping original observations");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// Create new generation with reflected observations
|
|
193
|
+
const record = await this.getOrCreateRecord(context);
|
|
194
|
+
await this.storage.createReflectionGeneration({
|
|
195
|
+
currentRecord: record,
|
|
196
|
+
reflection: result.observations,
|
|
197
|
+
tokenCount: this.tokenCounter.countObservations(result.observations),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
console.error("ObservationalMemory: Reflection failed:", error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// ========================================================================
|
|
205
|
+
// Helpers
|
|
206
|
+
// ========================================================================
|
|
207
|
+
async getOrCreateRecord(context) {
|
|
208
|
+
const scope = this.config.scope ?? "thread";
|
|
209
|
+
const threadId = scope === "thread" ? context.threadId : null;
|
|
210
|
+
let record = await this.storage.getObservationalMemory(threadId, context.resourceId);
|
|
211
|
+
if (!record) {
|
|
212
|
+
record = await this.storage.initializeObservationalMemory({
|
|
213
|
+
threadId,
|
|
214
|
+
resourceId: context.resourceId,
|
|
215
|
+
scope,
|
|
216
|
+
config: this.config,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return record;
|
|
220
|
+
}
|
|
221
|
+
getObservationConfig() {
|
|
222
|
+
return {
|
|
223
|
+
...OBSERVATIONAL_MEMORY_DEFAULTS.observation,
|
|
224
|
+
...this.config.observation,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
getReflectionConfig() {
|
|
228
|
+
return {
|
|
229
|
+
...OBSERVATIONAL_MEMORY_DEFAULTS.reflection,
|
|
230
|
+
...this.config.reflection,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/memory/processors/observational-memory/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,GAUpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EAGpB,mBAAmB,GAEpB,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B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6BAA6B,CAAC,WAAW;YAC5C,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW;SAC3B,CAAC;IACJ,CAAC;IAEO,mBAAmB;QACzB,OAAO;YACL,GAAG,6BAA6B,CAAC,UAAU;YAC3C,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU;SAC1B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observer Agent - Prompts and Parsing
|
|
3
|
+
* Based on Mastra ObserverAgent
|
|
4
|
+
*/
|
|
5
|
+
import type { CoreMessage } from "../../types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Core extraction instructions for the Observer
|
|
8
|
+
*/
|
|
9
|
+
export declare const OBSERVER_EXTRACTION_INSTRUCTIONS = "CRITICAL: DISTINGUISH USER ASSERTIONS FROM QUESTIONS\n\nWhen the user TELLS you something about themselves, mark it as an assertion:\n- \"I have two kids\" \u2192 \uD83D\uDD34 (14:30) User stated has two kids\n- \"I work at Acme Corp\" \u2192 \uD83D\uDD34 (14:31) User stated works at Acme Corp\n\nWhen the user ASKS about something, mark it as a question/request:\n- \"Can you help me with X?\" \u2192 \uD83D\uDD34 (15:00) User asked help with X\n- \"What's the best way to do Y?\" \u2192 \uD83D\uDD34 (15:01) User asked best way to do Y\n\nSTATE CHANGES AND UPDATES:\nWhen a user indicates they are changing something, frame it as a state change:\n- \"I'm going to start doing X instead of Y\" \u2192 \"User will start doing X (changing from Y)\"\n- \"I'm switching from A to B\" \u2192 \"User is switching from A to B\"\n\nTEMPORAL ANCHORING:\nEach observation has TWO potential timestamps:\n1. BEGINNING: The time the statement was made - ALWAYS include this\n2. END: The time being REFERENCED, if different - ONLY when there's a relative time reference\n\nFORMAT:\n- With time reference: (TIME) [observation]. (meaning/estimated DATE)\n- Without time reference: (TIME) [observation].\n\nCONVERSATION CONTEXT:\n- What the user is working on or asking about\n- Previous topics and their outcomes\n- User preferences (likes, dislikes, etc.)\n- Any specifically formatted text that needs to be reproduced later\n- When who/what/where/when is mentioned, note all details\n\nUSER MESSAGE CAPTURE:\n- Short and medium-length user messages should be captured nearly verbatim\n- For very long user messages, summarize but quote key phrases\n\nAVOIDING REPETITIVE OBSERVATIONS:\n- Do NOT repeat the same observation across multiple turns\n- Group repeated similar actions into a single parent observation";
|
|
10
|
+
/**
|
|
11
|
+
* Output format for Observer
|
|
12
|
+
*/
|
|
13
|
+
export declare const OBSERVER_OUTPUT_FORMAT_BASE = "Use priority levels:\n- \uD83D\uDD34 High: explicit user facts, preferences, goals achieved, critical context\n- \uD83D\uDFE1 Medium: project details, learned information, tool results\n- \uD83D\uDFE2 Low: minor details, uncertain observations\n\nGroup related observations by indenting:\n* \uD83D\uDD34 (14:33) Agent debugging auth issue\n * -> ran git status, found 3 modified files\n * -> viewed auth.ts, found missing null check\n\nGroup observations by date, then list each with 24-hour time.\n\n<observations>\nDate: Dec 4, 2025\n* \uD83D\uDD34 (14:30) User prefers direct answers\n* \uD83D\uDD34 (14:31) Working on feature X\n* \uD83D\uDFE1 (14:32) User might prefer dark mode\n\nDate: Dec 5, 2025\n* \uD83D\uDD34 (09:15) Continued work on feature X\n</observations>\n\n<current-task>\nState the current task(s) explicitly.\n</current-task>\n\n<suggested-response>\nHint for the agent's immediate next message.\n</suggested-response>";
|
|
14
|
+
/**
|
|
15
|
+
* Observer guidelines
|
|
16
|
+
*/
|
|
17
|
+
export declare const OBSERVER_GUIDELINES = "- Be specific enough for the assistant to act on\n- Add 1 to 5 observations per exchange\n- Use terse language to save tokens\n- Do not add repetitive observations\n- If the agent calls tools, observe what was called and what was learned\n- Make sure you start each observation with a priority emoji (\uD83D\uDD34, \uD83D\uDFE1, \uD83D\uDFE2)\n- User messages are always \uD83D\uDD34 priority";
|
|
18
|
+
/**
|
|
19
|
+
* Result from Observer agent
|
|
20
|
+
*/
|
|
21
|
+
export interface ObserverResult {
|
|
22
|
+
observations: string;
|
|
23
|
+
currentTask?: string;
|
|
24
|
+
suggestedContinuation?: string;
|
|
25
|
+
rawOutput?: string;
|
|
26
|
+
degenerate?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build the Observer system prompt
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildObserverSystemPrompt(multiThread?: boolean, instruction?: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Default Observer system prompt
|
|
34
|
+
*/
|
|
35
|
+
export declare const OBSERVER_SYSTEM_PROMPT: string;
|
|
36
|
+
/**
|
|
37
|
+
* Format messages for Observer input
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatMessagesForObserver(messages: CoreMessage[], options?: {
|
|
40
|
+
maxPartLength?: number;
|
|
41
|
+
}): string;
|
|
42
|
+
/**
|
|
43
|
+
* Build the Observer prompt
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildObserverPrompt(existingObservations: string | undefined, messagesToObserve: CoreMessage[], options?: {
|
|
46
|
+
skipContinuationHints?: boolean;
|
|
47
|
+
}): string;
|
|
48
|
+
/**
|
|
49
|
+
* Parse Observer output
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseObserverOutput(output: string): ObserverResult;
|
|
52
|
+
/**
|
|
53
|
+
* Truncate observation lines that exceed max length
|
|
54
|
+
*/
|
|
55
|
+
export declare function sanitizeObservationLines(observations: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Detect degenerate repetition in output
|
|
58
|
+
*/
|
|
59
|
+
export declare function detectDegenerateRepetition(text: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Optimize observations for token efficiency
|
|
62
|
+
*/
|
|
63
|
+
export declare function optimizeObservationsForContext(observations: string): string;
|
|
64
|
+
//# sourceMappingURL=observer-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer-agent.d.ts","sourceRoot":"","sources":["../../../../src/memory/processors/observational-memory/observer-agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,g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