forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_recommendation.py
More file actions
321 lines (248 loc) · 9.26 KB
/
Copy pathtask_recommendation.py
File metadata and controls
321 lines (248 loc) · 9.26 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
"""Canonical feedback, attention, and What Matters Now contracts."""
from datetime import datetime
from enum import Enum
from typing import Literal, Optional
from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, model_validator
from models.action_item import EvidenceRef
from models.task_intelligence import (
StableId,
TaskIntelligenceFeedbackAction,
TaskIntelligenceFeedbackReason,
TaskIntelligenceOutcomeCode,
)
class RecommendationSubjectKind(str, Enum):
candidate = 'candidate'
task = 'task'
workstream = 'workstream'
artifact = 'artifact'
decision = 'decision'
agent_open_loop = 'agent_open_loop'
class FeedbackSubjectKind(str, Enum):
candidate = 'candidate'
task = 'task'
workstream = 'workstream'
artifact = 'artifact'
decision = 'decision'
class InterventionSurface(str, Enum):
suggested = 'suggested'
what_matters_now = 'what_matters_now'
class ContextMatchSignal(str, Enum):
app = 'app'
person = 'person'
document = 'document'
meeting = 'meeting'
free_time = 'free_time'
dependency = 'dependency'
agent = 'agent'
class OpenLoopKind(str, Enum):
task = 'task'
artifact = 'artifact'
decision = 'decision'
approval = 'approval'
external_wait = 'external_wait'
class OpenLoopStatus(str, Enum):
open = 'open'
blocked = 'blocked'
awaiting_user = 'awaiting_user'
awaiting_external = 'awaiting_external'
class DeterministicFacts(BaseModel):
model_config = ConfigDict(extra='forbid', frozen=True)
days_to_due: Optional[float] = None
someone_blocked: bool = False
has_concrete_next_action: bool
focused_goal_linked: bool = False
context_match_signals: list[ContextMatchSignal] = Field(default_factory=list, max_length=4)
capture_confidence: float = Field(ge=0, le=1)
@model_validator(mode='after')
def require_unique_context_signals(self):
if len(self.context_match_signals) != len(set(self.context_match_signals)):
raise ValueError('context_match_signals must be unique')
return self
class ShortlistEligibility(BaseModel):
model_config = ConfigDict(extra='forbid', frozen=True)
open: bool
unexpired: bool
passes_recommendation_gates: bool
recent_material_activity: bool
inside_due_window: bool
class Recommendation(BaseModel):
model_config = ConfigDict(extra='forbid')
intervention_id: StableId
output_version: StableId
subject_kind: RecommendationSubjectKind
subject_id: StableId
feedback_subject_kind: FeedbackSubjectKind
feedback_subject_id: StableId
destination_task_id: Optional[StableId] = None
destination_workstream_id: Optional[StableId] = None
headline: str = Field(min_length=1, max_length=256)
why_now: str = Field(min_length=1, max_length=1024)
goal_or_workstream_label: Optional[str] = Field(default=None, max_length=256)
recommended_action: str = Field(min_length=1, max_length=128)
alternative_action: Optional[str] = Field(default=None, max_length=128)
evidence_preview: str = Field(max_length=512)
evidence_refs: list[EvidenceRef] = Field(min_length=1, max_length=50)
dedupe_key: StableId
expires_at: AwareDatetime
class WhatMattersNowProjection(BaseModel):
model_config = ConfigDict(extra='forbid')
schema_version: Literal[1] = 1
evaluation_id: StableId
output_version: StableId
material_version: StableId
generated_at: AwareDatetime
expires_at: AwareDatetime
recommendations: list[Recommendation] = Field(max_length=3)
class FeedbackCreate(BaseModel):
model_config = ConfigDict(extra='forbid')
subject_kind: FeedbackSubjectKind
subject_id: StableId
intervention_id: Optional[StableId] = None
action: TaskIntelligenceFeedbackAction
reason: Optional[TaskIntelligenceFeedbackReason] = None
context_snapshot_hash: Optional[str] = Field(default=None, pattern=r'^[a-f0-9]{64}$')
later_until: Optional[AwareDatetime] = None
@model_validator(mode='after')
def validate_action(self):
if self.reason is not None and self.action != TaskIntelligenceFeedbackAction.dismiss:
raise ValueError('reason is only valid for dismiss feedback')
if self.later_until is not None and self.action != TaskIntelligenceFeedbackAction.later:
raise ValueError('later_until is only valid for later feedback')
if (
self.action
in {
TaskIntelligenceFeedbackAction.do_now,
TaskIntelligenceFeedbackAction.later,
TaskIntelligenceFeedbackAction.dismiss,
}
and self.intervention_id is None
):
raise ValueError(f'{self.action.value} feedback requires intervention_id')
return self
class InterventionCreate(BaseModel):
model_config = ConfigDict(extra='forbid')
surface: InterventionSurface
subject_kind: FeedbackSubjectKind
subject_id: StableId
dedupe_key: StableId
evidence_refs: list[EvidenceRef] = Field(default_factory=list, max_length=50)
expires_at: AwareDatetime
class InterventionRecord(InterventionCreate):
intervention_id: StableId
attribution_chain_id: StableId
created_at: AwareDatetime
class FeedbackRecord(FeedbackCreate):
feedback_id: StableId
attribution_chain_id: StableId
created_at: AwareDatetime
dedupe_key: Optional[StableId] = None
proposed_completion: bool = False
proposed_completion_candidate_id: Optional[StableId] = None
class OutcomeCreate(BaseModel):
model_config = ConfigDict(extra='forbid')
attribution_chain_id: StableId
subject_kind: FeedbackSubjectKind
subject_id: StableId
outcome_code: TaskIntelligenceOutcomeCode
class OutcomeRecord(OutcomeCreate):
outcome_id: StableId
occurred_at: AwareDatetime
class NormalizedContextMatch(BaseModel):
model_config = ConfigDict(extra='forbid', frozen=True)
subject_kind: RecommendationSubjectKind
subject_id: StableId
signals: list[ContextMatchSignal] = Field(min_length=1, max_length=4)
@model_validator(mode='after')
def require_unique_signals(self):
if len(self.signals) != len(set(self.signals)):
raise ValueError('signals must be unique')
return self
class NormalizedContextSnapshot(BaseModel):
"""A bounded local match result; raw local context has no field to enter through."""
model_config = ConfigDict(extra='forbid')
schema_version: Literal[1] = 1
device_id: StableId
snapshot_id: StableId
matches: list[NormalizedContextMatch] = Field(default_factory=list, max_length=32)
generated_at: AwareDatetime
expires_at: AwareDatetime
class OpenLoopDescriptor(BaseModel):
model_config = ConfigDict(extra='forbid', frozen=True)
loop_id: StableId
kind: OpenLoopKind
subject_id: StableId
status: OpenLoopStatus
next_action_code: StableId
blocking_on_id: Optional[StableId] = None
updated_at: AwareDatetime
class OpenLoopSnapshot(BaseModel):
model_config = ConfigDict(extra='forbid')
schema_version: Literal[1] = 1
device_id: StableId
owner: StableId
runtime_id: StableId
workstream_id: StableId
conversation_id: StableId
context_packet_version: StableId
checkpoint_ref: Optional[StableId] = None
open_loop_snapshot: list[OpenLoopDescriptor] = Field(default_factory=list, max_length=32)
generated_at: AwareDatetime
expires_at: AwareDatetime
class EvaluationRequest(BaseModel):
model_config = ConfigDict(extra='forbid')
device_id: Optional[StableId] = None
material_hint: Optional[StableId] = None
class DecisionRecord(BaseModel):
"""Debug-only audit record. It intentionally contains no prompt or model reasoning."""
model_config = ConfigDict(extra='forbid')
evaluation_id: StableId
subject_kind: RecommendationSubjectKind
subject_id: StableId
shortlist_ids: list[StableId] = Field(max_length=20)
facts_snapshot: DeterministicFacts
eligibility: ShortlistEligibility
prompt_version: StableId
policy_version: StableId
fact_definition_version: StableId
model_version: StableId
decision_summary: str = Field(max_length=1024)
reason_codes: list[str] = Field(max_length=8)
evidence_refs: list[EvidenceRef] = Field(default_factory=list, max_length=50)
final_output_ref: StableId
evaluated_at: AwareDatetime
expires_at: AwareDatetime
class DecisionDebugProjection(BaseModel):
model_config = ConfigDict(extra='forbid')
projection: WhatMattersNowProjection
decisions: list[DecisionRecord]
class SnapshotReceipt(BaseModel):
model_config = ConfigDict(extra='forbid')
snapshot_id: StableId
replaced: bool
expires_at: datetime
__all__ = [
'ContextMatchSignal',
'DecisionDebugProjection',
'DecisionRecord',
'DeterministicFacts',
'EvaluationRequest',
'FeedbackCreate',
'FeedbackRecord',
'FeedbackSubjectKind',
'InterventionCreate',
'InterventionRecord',
'InterventionSurface',
'NormalizedContextMatch',
'NormalizedContextSnapshot',
'OpenLoopDescriptor',
'OpenLoopKind',
'OpenLoopSnapshot',
'OpenLoopStatus',
'OutcomeCreate',
'OutcomeRecord',
'Recommendation',
'RecommendationSubjectKind',
'ShortlistEligibility',
'SnapshotReceipt',
'WhatMattersNowProjection',
]