feat(rules): slot-grouped brain injection + graduation-time classifier#138
feat(rules): slot-grouped brain injection + graduation-time classifier#138
Conversation
… baseline Adds synthesize_brain_injection() — the canonical Preston-Rhodes 6-step output (task → context → examples → persona → format → tone). Groups rules by inferred slot, enforces a token budget (GRADATA_SYNTH_BUDGET, default 400), and seeds the persona slot from a soul.md-style baseline with graduated persona-slot rules layered as overrides. classify_slot() maps Lesson.category → slot; example_draft/corrected pairs route into the examples slot regardless of category. Legacy synthesize_rules_prompt() untouched for back-compat. Co-Authored-By: Gradata <noreply@gradata.ai>
Adds a Preston-Rhodes slot (task/context/examples/persona/format/tone) to every graduating lesson. The slot is assigned once when a lesson is first promoted (INSTINCT->PATTERN or PATTERN->RULE) by calling prompt_synthesizer.classify_slot, then round-trips through format_lessons / parse_lessons as a "Slot: <value>" meta line. Downstream, prompt_synthesizer.synthesize_brain_injection uses this slot to bucket lessons into the 6-step prompt ordering (task first, tone last). Legacy lessons without a slot fall back to category inference at render time.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughSummary
WalkthroughThe PR introduces Preston-Rhodes slot-based lesson synthesis and classification. A new Changes
Sequence Diagram(s)sequenceDiagram
participant User as Caller
participant Synth as synthesize_brain_injection()
participant Classify as classify_slot()
participant Render as Slot Renderer
participant Budget as Token Budgeter
User->>Synth: lessons[], budget_tokens
loop For each lesson
Synth->>Classify: lesson
Classify-->>Synth: slot (explicit→examples→category→context)
end
Synth->>Render: slot→sentence groups (SLOT_ORDER)
Render-->>Synth: formatted sentences
Synth->>Budget: sentences, budget_tokens
Budget-->>Synth: truncated sentences (drop lowest-priority)
Synth-->>User: SynthesizedPrompt (text, anchors_used)
sequenceDiagram
participant Grad as graduate()
participant Lesson as Lesson (INSTINCT→PATTERN)
participant Ensure as _ensure_slot()
participant Classify as classify_slot()
Grad->>Lesson: refine rule wording (ToT)
Grad->>Ensure: lesson
alt slot empty?
Ensure->>Classify: lesson
Classify-->>Ensure: inferred slot
Ensure->>Lesson: assign slot
else slot already set
Ensure-->>Grad: (no-op)
end
note over Ensure: failures swallowed
Grad->>Lesson: promote INSTINCT→PATTERN
Grad-->>Grad: complete
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly Related PRs
Suggested Labels
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
Lays the groundwork for wiring
prompt_synthesizerinto the session-start injection path (the legacyinject_brain_rules.pyN-rules block will be replaced in a follow-up PR).synthesize_brain_injection(lessons, *, budget_tokens, max_per_slot, persona_baseline)— new slot-grouped entry point that orders rules by Preston Rhodes' 6-step checklist (task → context → examples → persona → format → tone), enforces a 400-token default budget, and preserves inliner:xxxxanchors forcapture_learning.pyattribution.classify_slot(item)— resolves explicit slot → example pair → category lookup →contextfallback. Exposed at import time so graduation can tag lessons once, at promotion time.Lesson.slot— new optional dataclass field (default""). Format/parse round-trip throughlessons.mdasSlot: <value>._ensure_slot(lesson)runs once per lesson at INSTINCT→PATTERN and PATTERN→RULE promotion. Idempotent; classifier errors are swallowed (slot is optional metadata).Legacy
synthesize_rules_promptis untouched for back-compat. All existing tests remain green.Test plan
tests/test_prompt_synthesizer.py— 29 tests: classify_slot resolution order, Preston-Rhodes slot ordering, persona baseline (str vs Path), budget-drops-lowest-priority-first, examples-slot promotion on example_draft, Lesson-like object support.tests/test_slot_graduation.py— 7 tests: default slot, format omits empty, format+parse round-trip, INSTINCT→PATTERN assigns slot, existing slot preserved, no-promotion leaves slot unset.pytest tests/).Generated with Gradata