- S1 Solver (fast model) - Iterative solving with feedback-based repair
- S2 Solver (slow model) - Single attempt escalation when S1 fails or shows no improvement
Classes
CLASS SOFAISamplingStrategy
SOFAI sampling strategy.
Uses S1 Solver (fast model) in a loop with targeted feedback from validation results.
If S1 Solver fails after exhausting the budget or shows no improvement,
escalates to a single attempt with S2 Solver (slow model).
The strategy leverages ValidationResult.reason fields to provide targeted
feedback for repair, enabling more effective iterative improvement.
Methods:
FUNC repair
old_ctx: The context WITHOUT the last action + output.new_ctx: The context including the last action + output.past_actions: List of actions executed.past_results: List of generation results.past_val: List of validation results.
- Tuple of (Message component with repair feedback, new context).
FUNC select_from_failure
sampled_actions: List of actions that have been executed (without success).sampled_results: List of (unsuccessful) generation results for these actions.sampled_val: List of validation results for the results.
- The index of the result that should be selected as
.value.
FUNC sample
SOFAI Flow Overview:
-
PHASE 1 - S1 Solver Loop:
- Generate candidate solution with fast S1 model
- Validate against requirements
- If success: return immediately
- If failure: generate repair feedback and iterate
- If no improvement detected: early exit to Phase 2
-
PHASE 2 - S2 Solver Escalation:
- Prepare context based on s2_solver_mode:
- fresh_start: clean slate with original prompt
- continue_chat: full S1 conversation history
- best_attempt: best S1 result with feedback summary
- Generate single attempt with slow S2 model
- Validate and return result (success or failure)
- Prepare context based on s2_solver_mode:
action: The component to sample (Instruction, Message, etc.).context: The session context (must be ChatContext).backend: Session backend (used for validation fallback).requirements: Requirements to validate against.validation_ctx: Optional separate validation context (unused).format: Output format for structured outputs.model_options: Model options to pass to backends.tool_calls: True if tool calls should be used.
- SamplingResult with success status and all generation history.