-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmn.ts
More file actions
52 lines (42 loc) · 1.08 KB
/
dmn.ts
File metadata and controls
52 lines (42 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
export type DmnState = 'foraging' | 'paused' | 'resting' | 'working'
export const DMN_TICK_INTERVALS: Record<DmnState, null | number> = {
foraging: 30000,
paused: null,
resting: 300000,
working: 3000,
}
export interface DmnContext {
lastTickAt: number
lastUserInputAt: number
state: DmnState
}
export const createDmnContext = (): DmnContext => ({
lastTickAt: 0,
lastUserInputAt: 0,
state: 'resting',
})
/**
* Compute next DMN state based on turn result
* - tool calls made → working
* - no tool calls → decays from working → foraging → resting
* - paused stays unchanged
*/
export const nextDmnState = (
current: DmnContext,
hasToolCalls: boolean,
modelSlept: boolean,
): DmnState => {
if (current.state === 'paused')
return 'paused'
if (modelSlept)
return 'resting'
if (hasToolCalls)
return 'working'
if (current.state === 'working')
return 'foraging'
if (current.state === 'foraging')
return 'resting'
return 'resting'
}
export const shouldSkipTick = (ctx: DmnContext): boolean =>
Date.now() - ctx.lastUserInputAt < 5000