Restore live autonomy with direct runtime and fresh snapshot capacity
This commit is contained in:
+19
-7
@@ -103,8 +103,8 @@ export async function runLiveAutonomyTick(
|
||||
options:{forceBotId?:string;now?:number}={}
|
||||
){
|
||||
const now=options.now??Date.now();
|
||||
const s=await store.load();
|
||||
const revision=s.revision;
|
||||
let s=await store.load();
|
||||
let revision=s.revision;
|
||||
const events=await recentAleEvents(db,400);
|
||||
|
||||
const candidates=s.bots
|
||||
@@ -139,29 +139,41 @@ export async function runLiveAutonomyTick(
|
||||
return {ok:true,ran:false,reason:options.forceBotId?'No recent authoritative observation for that managed Playerbot':'No managed Playerbot is due with a recent authoritative observation'};
|
||||
}
|
||||
|
||||
const bot=pick.bot;
|
||||
let bot=pick.bot;
|
||||
const observation=observationFrom(bot,pick.obs,events);
|
||||
const brain=providerForBot(bot,s.settings,config);
|
||||
let decision:Decision;
|
||||
let usedFallback=false;
|
||||
try{
|
||||
decision=await brain.provider.decide(bot,observation);
|
||||
}catch(error){
|
||||
if(brain.route.provider==='deterministic')throw error;
|
||||
decision=await new DeterministicProvider().decide(bot,observation);
|
||||
realmEvent(s,'system',`${bot.name} LLM route unavailable; used deterministic fallback for this heartbeat.`,bot.id);
|
||||
usedFallback=true;
|
||||
}
|
||||
// Model inference can take seconds while authoritative events update state.
|
||||
// Commit the decision against current state, not the pre-inference revision.
|
||||
const botId=bot.id;
|
||||
s=await store.load();
|
||||
revision=s.revision;
|
||||
const currentBot=s.bots.find(b=>b.id===botId);
|
||||
if(!currentBot||currentBot.status==='dead'||currentBot.status==='retired'||!currentBot.autonomy?.managed){
|
||||
return {ok:true,ran:false,reason:'Resident is no longer eligible for an autonomous intention'};
|
||||
}
|
||||
bot=currentBot;
|
||||
if(usedFallback)realmEvent(s,'system',`${bot.name} LLM route unavailable; used deterministic fallback for this heartbeat.`,bot.id);
|
||||
const source=compileLivePlayerbotIntent(bot.name,decision);
|
||||
const queued=await queueAleCommand(db,source);
|
||||
|
||||
bot.lastDecision=decision;
|
||||
bot.decisions++;
|
||||
bot.goal=decision.goal;
|
||||
bot.level=observation.level;
|
||||
bot.zone=observation.zone;
|
||||
const newerObservation=Date.parse(bot.autonomy?.observedAt??'')>Date.parse(pick.obs.at);
|
||||
if(!newerObservation){bot.level=observation.level;bot.zone=observation.zone;}
|
||||
bot.autonomy={
|
||||
...(bot.autonomy??{}),
|
||||
managed:true,
|
||||
observedAt:pick.obs.at,
|
||||
observedAt:newerObservation?bot.autonomy?.observedAt:pick.obs.at,
|
||||
lastIntentAt:new Date(now).toISOString(),
|
||||
nextIntentAt:new Date(now+nextIntervalMs(bot)).toISOString(),
|
||||
lastAleCommandId:queued.id
|
||||
|
||||
Reference in New Issue
Block a user