aboutsummaryrefslogtreecommitdiff
path: root/modules/core/core-bundle.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/core-bundle.js')
-rw-r--r--modules/core/core-bundle.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/modules/core/core-bundle.js b/modules/core/core-bundle.js
index ddfad31..6022a37 100644
--- a/modules/core/core-bundle.js
+++ b/modules/core/core-bundle.js
@@ -8029,6 +8029,7 @@ class ServerMonitorModule {
}; 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;
@@ -8782,6 +8783,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) {
@@ -8816,12 +8824,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)
@@ -8884,12 +8894,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) {
@@ -15962,7 +15972,9 @@ class OrchestratorModule {
try {
const aiModule = this.terminal.moduleManager.modules['WebX11AIAssistantModule'];
if (aiModule && typeof aiModule.chat === 'function') {
- const result = await aiModule.chat([`[DELEGATED] ${task}`], { agentTag: agent.id + '/' + (agent.role || 'worker') });
+ const _agentTag = agent.id + '/' + (agent.role || 'worker');
+ const result = await aiModule.chat([`[DELEGATED] ${task}`], { agentTag: _agentTag });
+ try { aiModule._sessions.delete(_agentTag); } catch (_e) {}
agent.status = 'completed';
// Write result to outbox