feat(minecraft): timestamp in blackboard

This commit is contained in:
Rin
2026-02-18 11:12:05 +08:00
committed by Neko Ayaka
parent 6f63e72934
commit 6ff248c959
2 changed files with 36 additions and 7 deletions
@@ -9,13 +9,18 @@ export interface ChatMessage {
timestamp: number
}
export interface ActionHistoryLine {
line: string
timestamp: number
}
export interface BlackboardState {
ultimateGoal: string
currentTask: string
strategy: string
contextView: contextViewState
chatHistory: ChatMessage[]
recentActionHistory: string[]
recentActionHistory: ActionHistoryLine[]
pendingActions: string[]
selfUsername: string
}
@@ -49,7 +54,7 @@ export class Blackboard {
public get selfSummary(): string { return this._state.contextView.selfSummary }
public get environmentSummary(): string { return this._state.contextView.environmentSummary }
public get chatHistory(): ChatMessage[] { return this._state.chatHistory }
public get recentActionHistory(): string[] { return this._state.recentActionHistory }
public get recentActionHistory(): ActionHistoryLine[] { return this._state.recentActionHistory }
public get pendingActions(): string[] { return this._state.pendingActions }
public get selfUsername(): string { return this._state.selfUsername }
@@ -70,8 +75,8 @@ export class Blackboard {
this._state = { ...this._state, chatHistory: newHistory }
}
public addActionHistoryLine(line: string): void {
const next = [...this._state.recentActionHistory, line]
public addActionHistoryLine(line: string, timestamp: number = Date.now()): void {
const next = [...this._state.recentActionHistory, { line, timestamp }]
const trimmed = next.length > Blackboard.MAX_ACTION_HISTORY ? next.slice(-Blackboard.MAX_ACTION_HISTORY) : next
this._state = { ...this._state, recentActionHistory: trimmed }
}
@@ -86,7 +91,7 @@ export class Blackboard {
...this._state,
contextView: { ...this._state.contextView },
chatHistory: [...this._state.chatHistory],
recentActionHistory: [...this._state.recentActionHistory],
recentActionHistory: this._state.recentActionHistory.map(l => ({ ...l })),
pendingActions: [...this._state.pendingActions],
}
}
@@ -5,6 +5,18 @@ export function generateBrainSystemPrompt(
blackboard: Blackboard,
availableActions: Action[],
): string {
const now = Date.now()
const formatAgo = (timestamp: number): string => {
const diffMs = Math.max(0, now - timestamp)
const s = Math.floor(diffMs / 1000)
return `${s}s ago`
}
const withinLast = (timestamp: number, windowMs: number): boolean => {
return now - timestamp <= windowMs
}
const actionDefinitions = availableActions.map((a) => {
return {
name: a.name,
@@ -15,6 +27,18 @@ export function generateBrainSystemPrompt(
const availableActionsJson = JSON.stringify(actionDefinitions, null, 2)
const recentWindowMs = 30_000
const recentActionLines = blackboard.recentActionHistory
.filter(a => withinLast(a.timestamp, recentWindowMs))
.map(a => `- [${formatAgo(a.timestamp)}] ${a.line}`)
.join('\n')
const recentChatLines = blackboard.chatHistory
.filter(m => withinLast(m.timestamp, recentWindowMs))
.map(m => `- [${formatAgo(m.timestamp)}] ${m.sender}: ${m.content}`)
.join('\n')
// TODO extract prompt components later
// e.g. personality should be included from somewhere else
return `
@@ -74,9 +98,9 @@ Pending actions (started and still running):
${blackboard.pendingActions.map(a => `- ${a}`).join('\n') || '- none'}
Recent action results (most recent last):
${blackboard.recentActionHistory.map(a => `- ${a}`).join('\n') || '- none'}
${recentActionLines || '- none'}
# Chat History (Recents):
${blackboard.chatHistory.map(msg => `- ${msg.sender}: ${msg.content}`).join('\n') || 'No recent messages.'}
${recentChatLines || 'No recent messages.'}
`
}