github-actions[bot] commited on
Commit
9210696
·
1 Parent(s): b6e922f

Automated Deploy: 8c61713efe55d273e3d33b9759666b0a0769a72b

Browse files
AI-coach-agent/src/ai_coach/group_review.py CHANGED
@@ -13,7 +13,7 @@ from pydantic import BaseModel, ConfigDict, Field
13
  from .cost import compute_cost
14
  from .schemas import Usage
15
 
16
- VERSION = 'sam-groups-v1'
17
  ASPECTS = {
18
  'rotation': {
19
  'hip_shoulder_differentiation': ('Hip and shoulder turning', {'hip_heading_deg','shoulder_heading_deg','hip_shoulder_separation_deg'}),
@@ -76,6 +76,21 @@ Respect these definitions rigorously:
76
  - Do not claim ball contact, early/late to a pitch, missed power, injury, pain,
77
  force, torque, elite/normal status, guaranteed results, or improvement over time.
78
  Use simple direct language, name the movement, and make the next step practical.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  '''
80
 
81
 
@@ -144,10 +159,16 @@ def available_facts(groups):
144
  return facts,evidence
145
 
146
 
147
- def _text(text):
148
  value=' '.join(text.split())
149
  if (len(value.split())>35 or re.search(r'\d|\b(injury|pain|injured|diagnos\w*|elite|normal|optimal|ideal|mph|degrees?|milliseconds?|torque|force)\b',value,re.I)):
150
  raise ValueError('Unsupported quantities, benchmark or medical claim in coaching prose')
 
 
 
 
 
 
151
  return value[0].upper()+value[1:]+('' if value[-1] in '.!?' else '.')
152
 
153
 
@@ -169,13 +190,13 @@ def build_reviews(parsed,facts,evidence,model):
169
  for a in rating.aspects]
170
  value=round(10*sum(a['grade'] for a in aspects)/(4*len(aspects)),1)
171
  band=next(label for minimum,label in [(9,'Strong pattern'),(7,'Solid foundation'),(5,'Developing'),(3,'Needs practice'),(0,'Priority for practice')] if value>=minimum)
172
- def point(p):return {'text':_text(p.text),'evidence':resolved(p.evidence_ids)}
173
  result[key]={'score':{'name':'Estimated coaching score','value':value,'max_value':10,
174
  'status':'estimated','band':band,'basis':'available_measurement_ai_rubric',
175
  'rubric_version':VERSION,'source':'coach_agent','model':model,'aspects':aspects,
176
  'reason_code':None,'accuracy_validated':False},
177
  'coaching':{'summary':_text(rating.summary),'what_went_well':[point(p) for p in rating.what_went_well],
178
- 'what_needs_work':[point(p) for p in rating.what_needs_work],'next_step':point(rating.next_step),
179
  'source':'coach_agent','model':model}}
180
  return result
181
 
@@ -237,7 +258,7 @@ def review_groups(service,groups):
237
  break
238
  except ValueError:
239
  reason='coach_response_invalid'
240
- feedback='\nREPAIR: The previous response failed validation. Return all requested groups and aspects with only their supplied evidence IDs. Every prose field must have no digits, no benchmark or medical claims, and at most thirty-five words. Use an integer grade from zero through four.'
241
  if reviews is None:return
242
  for group in groups:
243
  if group.key in reviews:
 
13
  from .cost import compute_cost
14
  from .schemas import Usage
15
 
16
+ VERSION = 'sam-groups-v2'
17
  ASPECTS = {
18
  'rotation': {
19
  'hip_shoulder_differentiation': ('Hip and shoulder turning', {'hip_heading_deg','shoulder_heading_deg','hip_shoulder_separation_deg'}),
 
76
  - Do not claim ball contact, early/late to a pitch, missed power, injury, pain,
77
  force, torque, elite/normal status, guaranteed results, or improvement over time.
78
  Use simple direct language, name the movement, and make the next step practical.
79
+ Scalar-statistic rules: maximum values and window-end values do not describe a
80
+ motion curve. Never infer acceleration, deceleration, interruptions, smoothness,
81
+ steady/maintained posture, synchronization, balance, repeatability or consistency
82
+ from them. A summary and strength must describe supplied geometry or sampled peak
83
+ relationships, not an unobserved time history. Do not call speed productive,
84
+ explosive or efficient without a comparison baseline. Suggestions may propose
85
+ working toward a smoother or more repeatable rehearsal, but must not assert that
86
+ the current swing was jerky, inconsistent, abruptly stopped or unstable.
87
+ Do not recommend symmetry or identical foot headings; differing foot headings are
88
+ not inherently a mistake. For stance, compare the supplied span and projection
89
+ as geometry and suggest rehearsing a comfortable setup, not correcting proven
90
+ balance or planting. Prefer simple bat-only or tee practice over extra equipment.
91
+ Avoid the words acceleration and deceleration entirely; only speeds were supplied.
92
+ Do not repeat data limitations in player feedback. Describe what is measured and
93
+ give refinements to try without inventing a fault or requesting missing inputs.
94
  '''
95
 
96
 
 
159
  return facts,evidence
160
 
161
 
162
+ def _text(text,*,suggestion=False):
163
  value=' '.join(text.split())
164
  if (len(value.split())>35 or re.search(r'\d|\b(injury|pain|injured|diagnos\w*|elite|normal|optimal|ideal|mph|degrees?|milliseconds?|torque|force)\b',value,re.I)):
165
  raise ValueError('Unsupported quantities, benchmark or medical claim in coaching prose')
166
+ if re.search(r'\b(accelerat\w*|decelerat\w*|symmetr\w*|productive|explosive|efficient|jerky|unstable|abrupt\w*)\b',value,re.I):
167
+ raise ValueError('Unsupported dynamic or performance claim')
168
+ if not suggestion and re.search(r'\b(maintain\w*|steady|stable|stability|smooth\w*|repeatab\w*|synchroni[sz]\w*|continuous|uninterrupted|balance\w*|consisten\w*|inconsisten\w*)\b',value,re.I):
169
+ raise ValueError('A scalar summary cannot establish temporal control')
170
+ if re.search(r'\b(missing|unavailable|insufficient)\b|(?:cannot|can.t)\s+(?:assess|score|judge)',value,re.I):
171
+ raise ValueError('Player coaching must use the available evidence')
172
  return value[0].upper()+value[1:]+('' if value[-1] in '.!?' else '.')
173
 
174
 
 
190
  for a in rating.aspects]
191
  value=round(10*sum(a['grade'] for a in aspects)/(4*len(aspects)),1)
192
  band=next(label for minimum,label in [(9,'Strong pattern'),(7,'Solid foundation'),(5,'Developing'),(3,'Needs practice'),(0,'Priority for practice')] if value>=minimum)
193
+ def point(p,*,suggestion=False):return {'text':_text(p.text,suggestion=suggestion),'evidence':resolved(p.evidence_ids)}
194
  result[key]={'score':{'name':'Estimated coaching score','value':value,'max_value':10,
195
  'status':'estimated','band':band,'basis':'available_measurement_ai_rubric',
196
  'rubric_version':VERSION,'source':'coach_agent','model':model,'aspects':aspects,
197
  'reason_code':None,'accuracy_validated':False},
198
  'coaching':{'summary':_text(rating.summary),'what_went_well':[point(p) for p in rating.what_went_well],
199
+ 'what_needs_work':[point(p,suggestion=True) for p in rating.what_needs_work],'next_step':point(rating.next_step,suggestion=True),
200
  'source':'coach_agent','model':model}}
201
  return result
202
 
 
258
  break
259
  except ValueError:
260
  reason='coach_response_invalid'
261
+ feedback='\nREPAIR: The previous response failed validation. Return all requested groups and aspects with only their supplied evidence IDs. Every prose field must have no digits, no benchmark or medical claims, and at most thirty-five words. Do not infer temporal control from a scalar: no maintained/steady/smooth/repeatable/synchronized observations, acceleration/deceleration or foot symmetry. Summaries and strengths describe geometry or sampled peak relationships; refinements are practice goals. Use an integer grade from zero through four.'
262
  if reviews is None:return
263
  for group in groups:
264
  if group.key in reviews:
baseball_batting/sam_batting_contract.py CHANGED
@@ -193,7 +193,7 @@ class GroupScore(Strict):
193
  status: Literal['estimated', 'pending']
194
  band: str | None = None
195
  basis: Literal['available_measurement_ai_rubric'] = 'available_measurement_ai_rubric'
196
- rubric_version: str = 'sam-groups-v1'
197
  source: Literal['coach_agent', 'none']
198
  model: str | None = None
199
  aspects: list[ScoreAspect] = Field(default_factory=list, max_length=3)
 
193
  status: Literal['estimated', 'pending']
194
  band: str | None = None
195
  basis: Literal['available_measurement_ai_rubric'] = 'available_measurement_ai_rubric'
196
+ rubric_version: str = 'sam-groups-v2'
197
  source: Literal['coach_agent', 'none']
198
  model: str | None = None
199
  aspects: list[ScoreAspect] = Field(default_factory=list, max_length=3)
docs/SAM_BATTING_API.md CHANGED
@@ -205,7 +205,7 @@ evidence item. Do not interpret a null individual metric as a missing group scor
205
  Do not display unavailable individual measurements in the player’s main cards;
206
  they remain in the complete API result for diagnostics. Zero is a valid score.
207
 
208
- The `sam-groups-v1` rubric has named aspects for each group:
209
 
210
  | Group | Aspects |
211
  | --- | --- |
@@ -220,7 +220,7 @@ pattern to preserve. Python computes `round(10 * sum(grades) / (4 * aspect_count
220
  The rubric version, individual grades and supporting evidence are returned. A grade
221
  is an AI coaching opinion about the measured pattern, not a population percentile,
222
  age comparison, diagnosis, player-ability rating or objective proof of a fault.
223
- There are no invented ideal angle/speed bands. More separation, faster movement or
224
  smaller head motion is not automatically better. Suggestions can be refinements
225
  to try; the agent must not invent a mistake simply to fill a list.
226
 
 
205
  Do not display unavailable individual measurements in the player’s main cards;
206
  they remain in the complete API result for diagnostics. Zero is a valid score.
207
 
208
+ The `sam-groups-v2` rubric has named aspects for each group:
209
 
210
  | Group | Aspects |
211
  | --- | --- |
 
220
  The rubric version, individual grades and supporting evidence are returned. A grade
221
  is an AI coaching opinion about the measured pattern, not a population percentile,
222
  age comparison, diagnosis, player-ability rating or objective proof of a fault.
223
+ Temporal claims such as acceleration, deceleration, maintained posture and repeatability cannot be inferred from scalar summaries. Strengths describe supplied geometry/peak relationships; improvement points are practical refinements. Different toe headings are not a proven fault or a demand for matching angles. There are no invented ideal angle/speed bands. More separation, faster movement or
224
  smaller head motion is not automatically better. Suggestions can be refinements
225
  to try; the agent must not invent a mistake simply to fill a list.
226
 
docs/sam-batting-result.schema.json CHANGED
@@ -270,7 +270,7 @@
270
  "type": "string"
271
  },
272
  "rubric_version": {
273
- "default": "sam-groups-v1",
274
  "title": "Rubric Version",
275
  "type": "string"
276
  },
 
270
  "type": "string"
271
  },
272
  "rubric_version": {
273
+ "default": "sam-groups-v2",
274
  "title": "Rubric Version",
275
  "type": "string"
276
  },
docs/sam-group-review.schema.json CHANGED
@@ -271,7 +271,7 @@
271
  "type": "string"
272
  },
273
  "rubric_version": {
274
- "default": "sam-groups-v1",
275
  "title": "Rubric Version",
276
  "type": "string"
277
  },
@@ -986,7 +986,7 @@
986
  "type": "string"
987
  },
988
  "rubric_version": {
989
- "default": "sam-groups-v1",
990
  "title": "Rubric Version",
991
  "type": "string"
992
  },
 
271
  "type": "string"
272
  },
273
  "rubric_version": {
274
+ "default": "sam-groups-v2",
275
  "title": "Rubric Version",
276
  "type": "string"
277
  },
 
986
  "type": "string"
987
  },
988
  "rubric_version": {
989
+ "default": "sam-groups-v2",
990
  "title": "Rubric Version",
991
  "type": "string"
992
  },
tests/test_sam_group_scoring.py CHANGED
@@ -180,3 +180,24 @@ def test_provider_error_details_are_typed_and_redact_the_key(tmp_path,monkeypatc
180
  groups=group_fixture();service.review_groups(groups)
181
  assert all(g.score.reason_code=='coach_provider_http_429' for g in groups)
182
  assert all('fixture-not-a-key' not in g.score.failure_detail and '[redacted]' in g.score.failure_detail for g in groups)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  groups=group_fixture();service.review_groups(groups)
181
  assert all(g.score.reason_code=='coach_provider_http_429' for g in groups)
182
  assert all('fixture-not-a-key' not in g.score.failure_detail and '[redacted]' in g.score.failure_detail for g in groups)
183
+
184
+
185
+ @pytest.mark.parametrize('claim',[
186
+ 'Your lean was maintained throughout the motion.',
187
+ 'The stance provided a repeatable base.',
188
+ 'Hand acceleration was synchronized with the pelvis.',
189
+ 'Hip rotation ended with abrupt deceleration.',
190
+ 'Make the initial foot headings symmetrical.',
191
+ 'Missing data prevents judging this movement.'
192
+ ])
193
+ def test_scalar_evidence_cannot_be_laundered_into_dynamic_or_symmetry_claims(claim):
194
+ groups=group_fixture();facts,evidence=available_facts(groups);raw=provider_response(groups)
195
+ raw['groups'][0]['summary']=claim
196
+ with pytest.raises(ValueError):build_reviews(RatingBatch.model_validate(raw),facts,evidence,'fixture')
197
+
198
+
199
+ def test_practice_goals_are_distinct_from_claims_about_current_motion():
200
+ from ai_coach.group_review import _text
201
+ goal='Practice a repeatable setup before each swing.'
202
+ assert _text(goal,suggestion=True)==goal
203
+ with pytest.raises(ValueError):_text(goal)