Skip to content

Commit 6ff248c

Browse files
shinohara-rinnekomeowww
authored andcommitted
feat(minecraft): timestamp in blackboard
1 parent 6f63e72 commit 6ff248c

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

services/minecraft/src/cognitive/conscious/blackboard.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ export interface ChatMessage {
99
timestamp: number
1010
}
1111

12+
export interface ActionHistoryLine {
13+
line: string
14+
timestamp: number
15+
}
16+
1217
export interface BlackboardState {
1318
ultimateGoal: string
1419
currentTask: string
1520
strategy: string
1621
contextView: contextViewState
1722
chatHistory: ChatMessage[]
18-
recentActionHistory: string[]
23+
recentActionHistory: ActionHistoryLine[]
1924
pendingActions: string[]
2025
selfUsername: string
2126
}
@@ -49,7 +54,7 @@ export class Blackboard {
4954
public get selfSummary(): string { return this._state.contextView.selfSummary }
5055
public get environmentSummary(): string { return this._state.contextView.environmentSummary }
5156
public get chatHistory(): ChatMessage[] { return this._state.chatHistory }
52-
public get recentActionHistory(): string[] { return this._state.recentActionHistory }
57+
public get recentActionHistory(): ActionHistoryLine[] { return this._state.recentActionHistory }
5358
public get pendingActions(): string[] { return this._state.pendingActions }
5459
public get selfUsername(): string { return this._state.selfUsername }
5560

@@ -70,8 +75,8 @@ export class Blackboard {
7075
this._state = { ...this._state, chatHistory: newHistory }
7176
}
7277

73-
public addActionHistoryLine(line: string): void {
74-
const next = [...this._state.recentActionHistory, line]
78+
public addActionHistoryLine(line: string, timestamp: number = Date.now()): void {
79+
const next = [...this._state.recentActionHistory, { line, timestamp }]
7580
const trimmed = next.length > Blackboard.MAX_ACTION_HISTORY ? next.slice(-Blackboard.MAX_ACTION_HISTORY) : next
7681
this._state = { ...this._state, recentActionHistory: trimmed }
7782
}
@@ -86,7 +91,7 @@ export class Blackboard {
8691
...this._state,
8792
contextView: { ...this._state.contextView },
8893
chatHistory: [...this._state.chatHistory],
89-
recentActionHistory: [...this._state.recentActionHistory],
94+
recentActionHistory: this._state.recentActionHistory.map(l => ({ ...l })),
9095
pendingActions: [...this._state.pendingActions],
9196
}
9297
}

services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ export function generateBrainSystemPrompt(
55
blackboard: Blackboard,
66
availableActions: Action[],
77
): string {
8+
const now = Date.now()
9+
10+
const formatAgo = (timestamp: number): string => {
11+
const diffMs = Math.max(0, now - timestamp)
12+
const s = Math.floor(diffMs / 1000)
13+
return `${s}s ago`
14+
}
15+
16+
const withinLast = (timestamp: number, windowMs: number): boolean => {
17+
return now - timestamp <= windowMs
18+
}
19+
820
const actionDefinitions = availableActions.map((a) => {
921
return {
1022
name: a.name,
@@ -15,6 +27,18 @@ export function generateBrainSystemPrompt(
1527

1628
const availableActionsJson = JSON.stringify(actionDefinitions, null, 2)
1729

30+
const recentWindowMs = 30_000
31+
32+
const recentActionLines = blackboard.recentActionHistory
33+
.filter(a => withinLast(a.timestamp, recentWindowMs))
34+
.map(a => `- [${formatAgo(a.timestamp)}] ${a.line}`)
35+
.join('\n')
36+
37+
const recentChatLines = blackboard.chatHistory
38+
.filter(m => withinLast(m.timestamp, recentWindowMs))
39+
.map(m => `- [${formatAgo(m.timestamp)}] ${m.sender}: ${m.content}`)
40+
.join('\n')
41+
1842
// TODO extract prompt components later
1943
// e.g. personality should be included from somewhere else
2044
return `
@@ -74,9 +98,9 @@ Pending actions (started and still running):
7498
${blackboard.pendingActions.map(a => `- ${a}`).join('\n') || '- none'}
7599
76100
Recent action results (most recent last):
77-
${blackboard.recentActionHistory.map(a => `- ${a}`).join('\n') || '- none'}
101+
${recentActionLines || '- none'}
78102
79103
# Chat History (Recents):
80-
${blackboard.chatHistory.map(msg => `- ${msg.sender}: ${msg.content}`).join('\n') || 'No recent messages.'}
104+
${recentChatLines || 'No recent messages.'}
81105
`
82106
}

0 commit comments

Comments
 (0)