diff options
| author | Agando <roduccomm@gmail.com> | 2026-10-18 16:30:46 +0200 |
|---|---|---|
| committer | Agando <roduccomm@gmail.com> | 2026-10-18 16:30:46 +0200 |
| commit | c011c40a42a1ef913ccd6bfd131864be11f9b669 (patch) | |
| tree | 24a030e7400c3136a6ab2f6443193b658fa2a4db /modules/core/module-aiassist.js | |
| parent | eb888c1d4f13ce059694dc8a1b840429491fcb26 (diff) | |
newOS4 v4.6.30: per-agent session isolation (D1)
Diffstat (limited to 'modules/core/module-aiassist.js')
| -rw-r--r-- | modules/core/module-aiassist.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/modules/core/module-aiassist.js b/modules/core/module-aiassist.js index 96f822d..74a071b 100644 --- a/modules/core/module-aiassist.js +++ b/modules/core/module-aiassist.js @@ -6,6 +6,7 @@ }; this.terminal = null; this.systemPrompt = this.buildSystemPrompt(); this.context = []; this.maxContext = 10; + this._sessions = new Map(); // agentTag -> {context, profile}; 'main' aliases this.context this.maxContextTokens = 2000; this.MAX_TOOL_TURNS = 8; this._pendingConfirmation = null; @@ -759,6 +760,13 @@ buildSystemPrompt() { this.commands['vaultmind-query'] = (args) => this._vaultmindQueryCmd(args); this.commands['wallet-lookup'] = (args) => this._walletLookupCmd(args); } + _sessionCtx(tag) { + const k = tag || 'main'; + // main is always the live this.context (commands like `ai-clear`/`load` reassign it) + if (k === 'main') return { context: this.context, profile: null }; + if (!this._sessions.has(k)) this._sessions.set(k, { context: [], profile: null }); + return this._sessions.get(k); + } async chat(args, opts = {}) { const userMessage = args.join(' '); if (!userMessage) { @@ -793,12 +801,14 @@ buildSystemPrompt() { this._loadContext(); // Compress context if it exceeds the token threshold this._compressContext(); + // Per-agent session: 'main' aliases this.context, agents get their own history. + const sess = this._sessionCtx(opts.agentTag); let loopResult; try { const messages = [ { role: 'system', content: this.systemPrompt } ]; - this.context.slice().forEach(msg => messages.push(msg)); + sess.context.slice().forEach(msg => messages.push(msg)); messages.push({ role: 'user', content: userMessage }); this.terminal.print('🤖 WebX11AI thinking...', 'info'); // Auto-load skills relevant to the user's query (awaited, not fire-and-forget) @@ -861,12 +871,12 @@ buildSystemPrompt() { } catch (e) { /* world model not available */ } loopResult = await this.agenticLoop(messages, opts); - this.context.push({ role: 'user', content: userMessage }); + sess.context.push({ role: 'user', content: userMessage }); if (loopResult.finalAnswer) { - this.context.push({ role: 'assistant', content: loopResult.finalAnswer }); + sess.context.push({ role: 'assistant', content: loopResult.finalAnswer }); } - if (this.context.length > this.maxContext * 2) { - this.context = this.context.slice(-this.maxContext * 2); + if (sess.context.length > this.maxContext * 2) { + sess.context.splice(0, sess.context.length - this.maxContext * 2); } // Reflection: after complex tasks, run health scan and auto-skill creation if (loopResult.toolTurns >= 2 && !this._cancelled) { |