a tool to help your Letta AI agents navigate bluesky
1import { 2 agentContext, 3 claimTaskThread, 4 releaseTaskThread, 5} from "../utils/agentContext.ts"; 6import { 7 msFrom, 8 msRandomOffset, 9 msUntilNextWakeWindow, 10} from "../utils/time.ts"; 11 12export const logStats = () => { 13 if (!claimTaskThread()) { 14 const newDelay = msRandomOffset(msFrom.minutes(5), msFrom.minutes(10)); 15 console.log( 16 `${agentContext.agentBskyName} is busy, attempting to log counts again in ${ 17 (newDelay / 1000) / 60 18 } minutes…`, 19 ); 20 // session is busy, logging stats in 5~10 minutes. 21 setTimeout(logStats, newDelay); 22 return; 23 } 24 25 if (!agentContext.reflectionEnabled) { 26 console.log( 27 `${agentContext.agentBskyName} reflection is disabled, skipping logStats…`, 28 ); 29 releaseTaskThread(); 30 return; 31 } 32 33 const delay = msUntilNextWakeWindow( 34 msFrom.minutes(30), 35 msFrom.hours(1), 36 ); 37 38 if (delay !== 0) { 39 setTimeout(logStats, delay); 40 console.log( 41 `${agentContext.agentBskyName} is current asleep. scheduling next stat log for ${ 42 (delay / 1000 / 60 / 60).toFixed(2) 43 } hours from now…`, 44 ); 45 releaseTaskThread(); 46 return; 47 } 48 49 console.log( 50 ` 51=== 52# current session interaction counts since last reflection: 53${agentContext.likeCount} ${ 54 agentContext.likeCount === 1 ? "like" : "likes" 55 }, ${agentContext.repostCount} ${ 56 agentContext.repostCount === 1 ? "repost" : "reposts" 57 }, ${agentContext.followCount} ${ 58 agentContext.followCount === 1 ? "new follower" : "new followers" 59 }, ${agentContext.mentionCount} ${ 60 agentContext.mentionCount === 1 ? "mention" : "mentions" 61 }, ${agentContext.replyCount} ${ 62 agentContext.replyCount === 1 ? "reply" : "replies" 63 }, and ${agentContext.quoteCount} ${ 64 agentContext.quoteCount === 1 ? "quote" : "quotes" 65 }. 66 67${agentContext.agentBskyName} has reflected ${agentContext.reflectionCount} time${ 68 agentContext.reflectionCount > 0 ? "s" : "" 69 } since last server start. interaction counts reset after each reflection session. 70=== 71`, 72 ); 73 setTimeout(logStats, msRandomOffset(msFrom.minutes(5), msFrom.minutes(15))); 74 releaseTaskThread(); 75};