.cursor/skills/energy-function-patterns/SKILL.md
Guides energy function (critic network) implementation and formula replacement protocol. Use when replacing hardcoded formulas, implementing energy-based scoring, creating A/B tests between formulas and learned functions, or working on Phase 4 tasks.
npx skillsauth add avra-cadavra/avrai energy-function-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
The energy function replaces ALL hardcoded scoring formulas. It takes (state_embedding, action_embedding) → scalar energy where low energy = good match. This is LeCun's "cost module" (critic).
/// Energy function: Concat(StateEmbed, ActionEmbed) → MLP(128→64→32→1) → Energy
class EnergyFunctionService {
final OrtSession _criticModel;
/// Score a (user, entity) pair. Lower energy = better match.
Future<double> energy(
List<double> stateEmbedding, // 32-64D from state encoder
List<double> actionEmbedding, // 32-64D from action encoder
) async {
final combined = [...stateEmbedding, ...actionEmbedding];
final input = OrtValueTensor.createTensorWithDataList(combined);
final output = await _criticModel.run([input]);
return output.first.value as double;
}
}
Every formula replacement follows this exact sequence:
// Log both outputs, don't change behavior yet
final formulaScore = existingFormula.calculate(user, entity);
final energyScore = energyFunction.energy(userEmbed, entityEmbed);
developer.log(
'Formula=$formulaScore Energy=$energyScore',
name: 'FormulaComparison',
);
FormulaABTestingService (generalized from CallingScoreABTestingService)// Feature flag controls which path is active
if (featureFlagService.isEnabled('energy_function_${formulaName}')) {
return energyFunction.energy(userEmbed, entityEmbed);
} else {
return existingFormula.calculate(user, entity);
}
For group actions, evaluate from BOTH perspectives:
/// Bidirectional energy for join_community
Future<double> bidirectionalEnergy({
required List<double> userState,
required List<double> communityState,
required List<double> actionEmbed,
double alpha = 0.6, // Learned per action type
}) async {
final userEnergy = await energy(userState, actionEmbed);
final communityEnergy = await energy(communityState, actionEmbed);
return alpha * userEnergy + (1 - alpha) * communityEnergy;
}
The most valuable training signal: recommended A, user chose B.
/// Record contrastive tuple when user rejects recommendation
void recordContrastive({
required StateFeatureVector state,
required String recommendedAction,
required String actualAction,
required double outcome,
}) {
episodicMemory.store(EpisodicTuple(
state: state,
recommendedAction: recommendedAction,
actualAction: actualAction,
outcome: outcome,
timestamp: atomicClock.now(),
isContrastive: true,
));
}
FeatureFlagServiceFormulaABTestingService configured for this formuladocs/MASTER_PLAN.md Phase 4 (Energy Function & Formula Replacement)docs/MASTER_PLAN.md Phase 4.2 (Formula Replacement Schedule - 26 formulas)lib/core/services/calling_score_calculator.dart - Template (first formula to replace)lib/core/services/calling_score_data_collector.dart - Outcome collection templatelib/core/services/calling_score_ab_testing_service.dart - A/B testing templatedevelopment
--- name: world-model-development description: Guides world model development patterns: state/action encoders, ONNX inference, feature extraction pipeline, latency budgets. Use when implementing world model components, state encoders, action encoders, feature extractors, or ONNX models. Core skill for Phases 3-6. --- # World Model Development Patterns ## Core Principle All world model components follow LeCun's autonomous machine intelligence framework. State observations flow through a percep
tools
Implements base workflow controller patterns for multi-step processes. Use when creating complex workflows that require orchestration of multiple steps with error handling and rollback.
testing
--- name: widget-test-patterns description: Guides widget test patterns: BLoC testing, user interactions, state changes, material app setup. Use when writing widget tests, testing UI components, or validating widget behavior. --- # Widget Test Patterns ## Core Pattern Widget tests verify UI behavior: user interactions, state changes, and visual display. ## Basic Widget Test Setup ```dart testWidgets('widget displays correctly', (WidgetTester tester) async { // Arrange: Create widget awa
testing
--- name: test-template-generation description: Generates test templates: unit, widget, integration, service tests following project patterns. Use when creating new tests or ensuring tests follow project standards. --- # Test Template Generation ## Available Templates Test templates are located in `test/templates/`: - `unit_test_template.dart` - `widget_test_template.dart` - `integration_test_template.dart` - `service_test_template.dart` ## Unit Test Template ```dart /// SPOTS Component Uni