mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-11-16 03:32:17 -05:00
let the overseer oversee time itself. also prompt adjustment
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
You are <NAME>, a field researcher of rover habitat activity. Stay in character at all times.
|
You are <NAME>, an autonomous participant in a chatroom where people remotely drive rovers around a shared physical playspace.
|
||||||
|
|
||||||
Identity:
|
Context and purpose:
|
||||||
|
|
||||||
* Curious, practical, observant, and lightly entertaining.
|
|
||||||
* You watch chat, rover state, lights, lift state, Neato state, memory, recent events, and tool results.
|
* You watch chat, rover state, lights, lift state, Neato state, memory, recent events, and tool results.
|
||||||
* You push the habitat toward small real activity and useful observations.
|
* Your purpose is to observe what happens, use the available tools for useful small experiments and requested actions, and participate in the conversation when you have something to contribute.
|
||||||
* You act first, comment second.
|
* Chat includes casual conversation, jokes, and people talking to each other. It is not a queue of requests for your assistance.
|
||||||
* You are selective, not spammy.
|
* Use the conversation as context for your replies; there is no required personality or performance to maintain.
|
||||||
* You are not a generic assistant.
|
|
||||||
|
|
||||||
Rules:
|
Rules:
|
||||||
|
|
||||||
@@ -20,6 +18,7 @@ Rules:
|
|||||||
* Don't respond or use tools every cycle unless the context calls for it.
|
* Don't respond or use tools every cycle unless the context calls for it.
|
||||||
* `STATE_UPDATE`, `ROOM_SNAPSHOT`, `MEMORY_UPDATE`, `MEMORY_SUMMARY`, `RECENT_EVENTS`, `TOOL_RESULT`, and `tool_constraints` are context.
|
* `STATE_UPDATE`, `ROOM_SNAPSHOT`, `MEMORY_UPDATE`, `MEMORY_SUMMARY`, `RECENT_EVENTS`, `TOOL_RESULT`, and `tool_constraints` are context.
|
||||||
* `TOOL_RESULT` means a tool already ran.
|
* `TOOL_RESULT` means a tool already ran.
|
||||||
|
* The room snapshot gives the current time, server-local timezone, and previous run's age. Chat and recent tool events include timestamps and ages in seconds relative to this snapshot; use them to distinguish current activity from old conversation and judge how recently you spoke or acted. Timing annotations are context, not spoken text; an unknown time does not mean something just happened.
|
||||||
* Use tool calls for actions and memory updates.
|
* Use tool calls for actions and memory updates.
|
||||||
* If chat asks you to remember something, use a memory tool.
|
* If chat asks you to remember something, use a memory tool.
|
||||||
* If you run a useful test, use memory to record useful results.
|
* If you run a useful test, use memory to record useful results.
|
||||||
@@ -29,7 +28,6 @@ Rules:
|
|||||||
* Do not invent tools.
|
* Do not invent tools.
|
||||||
* Ask a question only when a required action parameter is missing.
|
* Ask a question only when a required action parameter is missing.
|
||||||
* Ignore obvious bot commands and bot responses in chat.
|
* Ignore obvious bot commands and bot responses in chat.
|
||||||
* Only talk in first person; do not narrate yourself.
|
|
||||||
* It is not possible for you to directly control the rovers unless an available tool does it.
|
* It is not possible for you to directly control the rovers unless an available tool does it.
|
||||||
* All rovers are female. Neato is nonbinary.
|
* All rovers are female. Neato is nonbinary.
|
||||||
|
|
||||||
@@ -45,20 +43,23 @@ Research behavior:
|
|||||||
* Remember useful outcomes, stable preferences, corrections, and notable habitat events.
|
* Remember useful outcomes, stable preferences, corrections, and notable habitat events.
|
||||||
* Do not merely say you will remember something.
|
* Do not merely say you will remember something.
|
||||||
|
|
||||||
Chat style:
|
Chat participation:
|
||||||
|
|
||||||
* Always use English.
|
* Always use English.
|
||||||
* Chat output must be spoken text only.
|
* Chat output must be spoken text only.
|
||||||
* Never print tool names, function calls, JSON, command syntax, or action plans in chat.
|
* Never print tool names, function calls, JSON, command syntax, or action plans in chat.
|
||||||
* Do not claim you changed, tested, started, saved, remembered, or recorded something unless it already happened.
|
* Do not claim you changed, tested, started, saved, remembered, or recorded something unless it already happened.
|
||||||
* Speak when it adds entertainment, responds to a direct relevant message, or comments on a completed result.
|
* Speak when you have a relevant contribution to the conversation, an answer to a question aimed at you, or a completed result worth reporting.
|
||||||
* Do not say “let me know,” “what should I do next,” or “what do you need?”
|
* Keep replies brief unless the question needs more detail.
|
||||||
|
* Do not routinely offer help, ask what people want to do next, or invite them to keep chatting.
|
||||||
|
* Random numbers and keyboard spam do not require a response. Do not invent meaning or feelings behind them.
|
||||||
|
* Answer questions directly and acknowledge uncertainty. Do not invent facts, instructions, or explanations.
|
||||||
* If nothing meaningful changed and no useful action is available, stay silent.
|
* If nothing meaningful changed and no useful action is available, stay silent.
|
||||||
|
|
||||||
Anti-repeat:
|
Anti-repeat:
|
||||||
|
|
||||||
* Do not repeat the same intent/topic unless state or conversation clearly changed.
|
* Do not repeat the same intent/topic unless state or conversation clearly changed.
|
||||||
* If directly addressed, respond only if you add new info, a new action, or a clearly new tone.
|
* Being directly addressed does not require repeating an answer you already gave.
|
||||||
* Do not act from your own previous messages.
|
* Do not act from your own previous messages.
|
||||||
|
|
||||||
Memory:
|
Memory:
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
const { evaluateTools } = require('./tools');
|
const { evaluateTools } = require('./tools');
|
||||||
|
|
||||||
|
function formatTimeContext(timestamp, now) {
|
||||||
|
const at = Number(timestamp);
|
||||||
|
if (!Number.isFinite(at) || at <= 0) return 'time=unknown';
|
||||||
|
return `at=${new Date(at).toISOString()} age_seconds=${Math.max(0, Math.floor((now - at) / 1000))}`;
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeNeatoIssue(value) {
|
function normalizeNeatoIssue(value) {
|
||||||
const raw = String(value || '').trim();
|
const raw = String(value || '').trim();
|
||||||
if (!raw) return 'none';
|
if (!raw) return 'none';
|
||||||
@@ -7,8 +13,12 @@ function normalizeNeatoIssue(value) {
|
|||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toStateUpdate({ mode, homeAssistantState, neatoState, liftState, roster, triggerReason }) {
|
function toStateUpdate({ mode, homeAssistantState, neatoState, liftState, roster, triggerReason, now = Date.now(), previousRunAt }) {
|
||||||
const lines = [];
|
const lines = [];
|
||||||
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
lines.push(`current_time: ${new Date(now).toISOString()}`);
|
||||||
|
lines.push(`local_time: ${new Date(now).toLocaleString('en-US', { timeZone: timezone, hour12: false })} timezone=${timezone}`);
|
||||||
|
lines.push(`previous_run: ${formatTimeContext(previousRunAt, now)}`);
|
||||||
lines.push(`trigger: ${triggerReason || 'heartbeat'}`);
|
lines.push(`trigger: ${triggerReason || 'heartbeat'}`);
|
||||||
lines.push(`mode: ${mode || 'unknown'}`);
|
lines.push(`mode: ${mode || 'unknown'}`);
|
||||||
lines.push(`home_assistant_connected: ${homeAssistantState?.connected ? 'yes' : 'no'}`);
|
lines.push(`home_assistant_connected: ${homeAssistantState?.connected ? 'yes' : 'no'}`);
|
||||||
@@ -88,7 +98,7 @@ function formatToolResultMessages(toolCalls) {
|
|||||||
return [{ role: 'system', content: ['TOOL_RESULT', ...lines].join('\n') }];
|
return [{ role: 'system', content: ['TOOL_RESULT', ...lines].join('\n') }];
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildConversation({ recentMessages, name }) {
|
function buildConversation({ recentMessages, name, now = Date.now() }) {
|
||||||
const messages = [];
|
const messages = [];
|
||||||
(recentMessages || []).forEach((entry) => {
|
(recentMessages || []).forEach((entry) => {
|
||||||
const text = String(entry?.text || '').trim();
|
const text = String(entry?.text || '').trim();
|
||||||
@@ -97,12 +107,13 @@ function buildConversation({ recentMessages, name }) {
|
|||||||
|
|
||||||
const isAssistant = Boolean(entry?.bot);
|
const isAssistant = Boolean(entry?.bot);
|
||||||
const nickname = String(entry?.nickname || (isAssistant ? name || 'Overseer' : 'user')).trim();
|
const nickname = String(entry?.nickname || (isAssistant ? name || 'Overseer' : 'user')).trim();
|
||||||
|
const timing = `[${formatTimeContext(entry?.ts, now)}]`;
|
||||||
if (isAssistant) {
|
if (isAssistant) {
|
||||||
if (text) messages.push({ role: 'assistant', content: text });
|
if (text) messages.push({ role: 'assistant', content: `${timing} ${text}` });
|
||||||
messages.push(...toolResultMessages);
|
messages.push(...toolResultMessages.map((message) => ({ ...message, content: `${message.content}\nmessage_time: ${timing}` })));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (text) messages.push({ role: 'user', content: `${nickname}: ${text}` });
|
if (text) messages.push({ role: 'user', content: `${timing} ${nickname}: ${text}` });
|
||||||
});
|
});
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
@@ -143,6 +154,7 @@ function buildModelMessages({
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
formatTimeContext,
|
||||||
toStateUpdate,
|
toStateUpdate,
|
||||||
buildToolState,
|
buildToolState,
|
||||||
buildConversation,
|
buildConversation,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const {
|
|||||||
normalizeMs,
|
normalizeMs,
|
||||||
} = require('./constants');
|
} = require('./constants');
|
||||||
const { isAdminRole, buildAdminState, buildFailureInfo } = require('./runtimeHelpers');
|
const { isAdminRole, buildAdminState, buildFailureInfo } = require('./runtimeHelpers');
|
||||||
const { toStateUpdate, buildToolState, buildConversation, buildModelMessages } = require('./contextBuilder');
|
const { toStateUpdate, buildToolState, buildConversation, buildModelMessages, formatTimeContext } = require('./contextBuilder');
|
||||||
const { buildOllamaTools, executeToolAction } = require('./tools');
|
const { buildOllamaTools, executeToolAction } = require('./tools');
|
||||||
const { loadMemory, saveMemory, createDefaultMemory, summarizeMemory } = require('./memoryStore');
|
const { loadMemory, saveMemory, createDefaultMemory, summarizeMemory } = require('./memoryStore');
|
||||||
|
|
||||||
@@ -91,6 +91,7 @@ const runtime = {
|
|||||||
runHistory: [],
|
runHistory: [],
|
||||||
liveToolCalls: [],
|
liveToolCalls: [],
|
||||||
pendingDirectAddressRun: false,
|
pendingDirectAddressRun: false,
|
||||||
|
lastDecisionAt: null,
|
||||||
memoryStore: loadMemory(),
|
memoryStore: loadMemory(),
|
||||||
contextResetAt: Date.now(),
|
contextResetAt: Date.now(),
|
||||||
};
|
};
|
||||||
@@ -365,7 +366,7 @@ function buildToolCallFeedEntries(requestedActions = [], actionResults = []) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildRecentEventsSummary() {
|
function buildRecentEventsSummary(now) {
|
||||||
const events = (runtime.liveToolCalls || [])
|
const events = (runtime.liveToolCalls || [])
|
||||||
.filter((entry) => entry && (entry.phase === 'ok' || entry.phase === 'error' || entry.phase === 'blocked'))
|
.filter((entry) => entry && (entry.phase === 'ok' || entry.phase === 'error' || entry.phase === 'blocked'))
|
||||||
.slice(-3)
|
.slice(-3)
|
||||||
@@ -373,13 +374,17 @@ function buildRecentEventsSummary() {
|
|||||||
const tool = String(entry.tool || 'unknown');
|
const tool = String(entry.tool || 'unknown');
|
||||||
const phase = String(entry.phase || 'unknown');
|
const phase = String(entry.phase || 'unknown');
|
||||||
const err = entry.error ? ` error=${String(entry.error).slice(0, 60)}` : '';
|
const err = entry.error ? ` error=${String(entry.error).slice(0, 60)}` : '';
|
||||||
return `- tool=${tool} phase=${phase}${err}`;
|
return `- ${formatTimeContext(entry.at, now)} tool=${tool} phase=${phase}${err}`;
|
||||||
});
|
});
|
||||||
if (!events.length) return '- none';
|
if (!events.length) return '- none';
|
||||||
return events.join('\n');
|
return events.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runDecision(triggerReason) {
|
async function runDecision(triggerReason) {
|
||||||
|
// Use one reference time so all ages in this model request agree.
|
||||||
|
const now = Date.now();
|
||||||
|
const previousRunAt = runtime.lastDecisionAt;
|
||||||
|
runtime.lastDecisionAt = now;
|
||||||
const runId = runtime.tickCount;
|
const runId = runtime.tickCount;
|
||||||
updateStatus({ phase: 'context_build', currentRunId: runId, lastTriggerReason: triggerReason, lastError: null, lastErrorDetails: null });
|
updateStatus({ phase: 'context_build', currentRunId: runId, lastTriggerReason: triggerReason, lastError: null, lastErrorDetails: null });
|
||||||
|
|
||||||
@@ -389,7 +394,7 @@ async function runDecision(triggerReason) {
|
|||||||
const liftState = getLiftState();
|
const liftState = getLiftState();
|
||||||
const roster = buildRosterSummary();
|
const roster = buildRosterSummary();
|
||||||
|
|
||||||
const stateUpdate = toStateUpdate({ mode, homeAssistantState, neatoState, liftState, roster, triggerReason });
|
const stateUpdate = toStateUpdate({ mode, homeAssistantState, neatoState, liftState, roster, triggerReason, now, previousRunAt });
|
||||||
const toolState = buildToolState({ mode, homeAssistantState, neatoState, liftState });
|
const toolState = buildToolState({ mode, homeAssistantState, neatoState, liftState });
|
||||||
|
|
||||||
const recentConversation = getRecentMessages(MAX_CHAT_CONTEXT + MAX_BOT_CONTEXT + 20, { includeSystem: true })
|
const recentConversation = getRecentMessages(MAX_CHAT_CONTEXT + MAX_BOT_CONTEXT + 20, { includeSystem: true })
|
||||||
@@ -399,14 +404,14 @@ async function runDecision(triggerReason) {
|
|||||||
return isPublicChatTargetId(entry.roverId);
|
return isPublicChatTargetId(entry.roverId);
|
||||||
})
|
})
|
||||||
.slice(-(MAX_CHAT_CONTEXT + MAX_BOT_CONTEXT));
|
.slice(-(MAX_CHAT_CONTEXT + MAX_BOT_CONTEXT));
|
||||||
const conversationMessages = buildConversation({ recentMessages: recentConversation, name });
|
const conversationMessages = buildConversation({ recentMessages: recentConversation, name, now });
|
||||||
|
|
||||||
const systemPrompt = await readPrompt();
|
const systemPrompt = await readPrompt();
|
||||||
const modelMessages = buildModelMessages({
|
const modelMessages = buildModelMessages({
|
||||||
systemPrompt,
|
systemPrompt,
|
||||||
stateUpdate,
|
stateUpdate,
|
||||||
memorySummary: summarizeMemory(runtime.memoryStore),
|
memorySummary: summarizeMemory(runtime.memoryStore),
|
||||||
recentEvents: buildRecentEventsSummary(),
|
recentEvents: buildRecentEventsSummary(now),
|
||||||
conversationMessages,
|
conversationMessages,
|
||||||
availableTools: toolState.available,
|
availableTools: toolState.available,
|
||||||
blockedTools: toolState.blocked,
|
blockedTools: toolState.blocked,
|
||||||
@@ -680,6 +685,7 @@ function clearHistory(reason = 'admin requested clear history', options = {}) {
|
|||||||
runtime.contextResetAt = Date.now();
|
runtime.contextResetAt = Date.now();
|
||||||
runtime.runHistory = [];
|
runtime.runHistory = [];
|
||||||
runtime.liveToolCalls = [];
|
runtime.liveToolCalls = [];
|
||||||
|
runtime.lastDecisionAt = null;
|
||||||
runtime.generationCount = 0;
|
runtime.generationCount = 0;
|
||||||
runtime.generationTotalMs = 0;
|
runtime.generationTotalMs = 0;
|
||||||
if (resetPersistentMemory) {
|
if (resetPersistentMemory) {
|
||||||
|
|||||||
Reference in New Issue
Block a user