Skip to content

Commit 39322f1

Browse files
ooplesclaude
andcommitted
feat: add chain-of-thought reasoning support for ai agent assistance
Implement Phase 4 of Chain-of-Thought integration plan, enabling AI agent assistance to use step-by-step reasoning when making recommendations during model building. Changes: - Extended AgentAssistanceOptions with reasoning configuration: - EnableReasoning (bool, default false) - MaxReasoningSteps (int, default 5, range 1-10) - ReasoningConfidenceThreshold (double, default 0.7, range 0.0-1.0) - Updated predefined configurations (Default, Minimal, Comprehensive) - Added fluent builder methods to AgentAssistanceOptionsBuilder: - EnableReasoning() / DisableReasoning() - WithMaxReasoningSteps(int) with range validation - WithReasoningConfidenceThreshold(double) with range validation - Implemented AskAsync method in PredictionModelResult: - Allows users to ask questions about model predictions using configured agent - Uses reasoning settings from AgentAssistanceOptions - Returns placeholder response until reasoning infrastructure merge - Includes helper method to build question context - Added comprehensive integration tests (14 tests) for agent + reasoning: - Configuration validation - Fluent builder patterns - Preset verification - Range validation for reasoning parameters Full implementation will integrate with ChainOfThoughtStrategy once the reasoning feature branch is merged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fbd712e commit 39322f1

File tree

4 files changed

+684
-5
lines changed

4 files changed

+684
-5
lines changed

src/Models/AgentAssistanceOptions.cs

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,125 @@ public class AgentAssistanceOptions
212212
/// </remarks>
213213
public bool EnableMetaLearningAdvice { get; set; } = false;
214214

215+
/// <summary>
216+
/// Gets or sets a value indicating whether the agent should use Chain-of-Thought reasoning.
217+
/// </summary>
218+
/// <value>True to enable reasoning; false to disable. Default is false.</value>
219+
/// <remarks>
220+
/// <para>
221+
/// When enabled, the agent will generate step-by-step reasoning explanations when making decisions
222+
/// or recommendations during model building. This provides transparency into the agent's decision-making
223+
/// process and can help users understand why certain recommendations are made.
224+
/// </para>
225+
/// <para><b>For Beginners:</b> Chain-of-Thought reasoning makes the AI explain its thinking step-by-step.
226+
///
227+
/// What this does:
228+
/// - Agent shows its reasoning process (not just final answers)
229+
/// - Each decision is broken down into logical steps
230+
/// - You can see why the agent recommends certain choices
231+
/// - Helps you learn and verify the agent's logic
232+
///
233+
/// Example without reasoning:
234+
/// - "I recommend using a Random Forest model."
235+
///
236+
/// Example with reasoning:
237+
/// - "Step 1: Your dataset has 10,000 samples, which is medium-sized."
238+
/// - "Step 2: You have 50 features with complex non-linear relationships."
239+
/// - "Step 3: Random Forest handles non-linearity well and doesn't require feature scaling."
240+
/// - "Conclusion: I recommend using a Random Forest model."
241+
///
242+
/// Why enable this:
243+
/// - Learn how AI agents make decisions
244+
/// - Verify the agent's reasoning is sound
245+
/// - Build trust in AI recommendations
246+
/// - Educational value for understanding ML concepts
247+
///
248+
/// Why it's disabled by default:
249+
/// - Generates more output (can be verbose)
250+
/// - Takes slightly more time
251+
/// - Not necessary if you just want quick recommendations
252+
///
253+
/// Enable this when: You want to understand the agent's reasoning or are learning about ML.
254+
/// </para>
255+
/// </remarks>
256+
public bool EnableReasoning { get; set; } = false;
257+
258+
/// <summary>
259+
/// Gets or sets the maximum number of reasoning steps the agent should generate.
260+
/// </summary>
261+
/// <value>The maximum number of reasoning steps. Default is 5.</value>
262+
/// <remarks>
263+
/// <para>
264+
/// When Chain-of-Thought reasoning is enabled, this controls how many reasoning steps the agent
265+
/// will generate. More steps provide more detailed explanations but take longer to generate.
266+
/// This is only used when EnableReasoning is true.
267+
/// </para>
268+
/// <para><b>For Beginners:</b> This limits how many steps the AI shows in its reasoning.
269+
///
270+
/// Why this matters:
271+
/// - More steps = more detailed explanation but takes longer
272+
/// - Fewer steps = quicker but less detailed
273+
/// - 5 steps is usually enough for most decisions
274+
///
275+
/// Example with 3 steps (brief):
276+
/// - "Step 1: Dataset is small (100 samples)"
277+
/// - "Step 2: Linear patterns detected"
278+
/// - "Step 3: Recommend Linear Regression"
279+
///
280+
/// Example with 7 steps (detailed):
281+
/// - "Step 1: Dataset has 100 samples"
282+
/// - "Step 2: That's considered small for ML"
283+
/// - "Step 3: Checking feature relationships..."
284+
/// - "Step 4: Found linear correlations"
285+
/// - "Step 5: Linear models work well here"
286+
/// - "Step 6: Comparing Linear Regression vs Ridge Regression"
287+
/// - "Step 7: Recommend Linear Regression due to no multicollinearity"
288+
///
289+
/// Recommended values:
290+
/// - 3-5: Quick, concise reasoning
291+
/// - 5-7: Balanced detail
292+
/// - 7-10: Very detailed explanations
293+
/// </para>
294+
/// </remarks>
295+
public int MaxReasoningSteps { get; set; } = 5;
296+
297+
/// <summary>
298+
/// Gets or sets the minimum confidence threshold for agent reasoning verification.
299+
/// </summary>
300+
/// <value>The confidence threshold (0.0 to 1.0). Default is 0.7.</value>
301+
/// <remarks>
302+
/// <para>
303+
/// When Chain-of-Thought reasoning is enabled, this threshold determines the minimum confidence
304+
/// score required for reasoning steps to be considered valid. Steps below this threshold may trigger
305+
/// refinement or additional verification. Higher values require more confident reasoning.
306+
/// This is only used when EnableReasoning is true.
307+
/// </para>
308+
/// <para><b>For Beginners:</b> This is the quality bar for the AI's reasoning.
309+
///
310+
/// How it works:
311+
/// - Each reasoning step gets a confidence score (0.0 to 1.0)
312+
/// - 1.0 = completely confident, 0.0 = no confidence
313+
/// - Steps below the threshold are flagged as uncertain
314+
/// - The agent may revise or refine low-confidence steps
315+
///
316+
/// Example with threshold 0.7:
317+
/// - Step with 0.9 confidence: Accepted (high quality)
318+
/// - Step with 0.6 confidence: Flagged for refinement (below threshold)
319+
///
320+
/// Choosing the right threshold:
321+
/// - 0.5-0.6: Lenient, accepts most reasoning (faster but less rigorous)
322+
/// - 0.7-0.8: Balanced, good quality control (recommended)
323+
/// - 0.8-0.9: Strict, only high-confidence reasoning (slower but more reliable)
324+
///
325+
/// Trade-offs:
326+
/// - Higher threshold = more reliable but slower (more refinement iterations)
327+
/// - Lower threshold = faster but may accept weaker reasoning
328+
///
329+
/// Default of 0.7 is a good balance for most use cases.
330+
/// </para>
331+
/// </remarks>
332+
public double ReasoningConfidenceThreshold { get; set; } = 0.7;
333+
215334
/// <summary>
216335
/// Gets a predefined configuration with data analysis and model selection enabled.
217336
/// </summary>
@@ -225,6 +344,7 @@ public class AgentAssistanceOptions
225344
/// - ✗ Hyperparameter tuning (uses default settings)
226345
/// - ✗ Feature analysis (keeps all features)
227346
/// - ✗ Meta-learning advice (not needed for standard problems)
347+
/// - ✗ Reasoning (disabled for simplicity)
228348
///
229349
/// Use this when: You're getting started and want helpful guidance without overwhelming detail.
230350
/// It's a good balance between AI assistance and keeping things simple.
@@ -236,7 +356,10 @@ public class AgentAssistanceOptions
236356
EnableModelSelection = true,
237357
EnableHyperparameterTuning = false,
238358
EnableFeatureAnalysis = false,
239-
EnableMetaLearningAdvice = false
359+
EnableMetaLearningAdvice = false,
360+
EnableReasoning = false,
361+
MaxReasoningSteps = 5,
362+
ReasoningConfidenceThreshold = 0.7
240363
};
241364

242365
/// <summary>
@@ -252,6 +375,7 @@ public class AgentAssistanceOptions
252375
/// - ✗ Hyperparameter tuning (you'll tune manually)
253376
/// - ✗ Feature analysis (you'll handle features yourself)
254377
/// - ✗ Meta-learning advice (not needed)
378+
/// - ✗ Reasoning (disabled for speed)
255379
///
256380
/// Use this when: You're experienced with ML and only want validation on which model type to use.
257381
/// Everything else you'll handle yourself. This gives you maximum control with one helpful suggestion.
@@ -263,7 +387,10 @@ public class AgentAssistanceOptions
263387
EnableModelSelection = true,
264388
EnableHyperparameterTuning = false,
265389
EnableFeatureAnalysis = false,
266-
EnableMetaLearningAdvice = false
390+
EnableMetaLearningAdvice = false,
391+
EnableReasoning = false,
392+
MaxReasoningSteps = 5,
393+
ReasoningConfidenceThreshold = 0.7
267394
};
268395

269396
/// <summary>
@@ -279,12 +406,14 @@ public class AgentAssistanceOptions
279406
/// - ✓ Hyperparameter tuning (optimizes settings)
280407
/// - ✓ Feature analysis (identifies important variables)
281408
/// - ✓ Meta-learning advice (if using meta-learning)
409+
/// - ✓ Reasoning (explains all decisions step-by-step)
282410
///
283411
/// Use this when:
284412
/// - You want the AI to help with every decision
285413
/// - You're working on an important project and want maximum performance
286414
/// - You want to learn what the AI recommends for each aspect
287415
/// - You're new to ML and want comprehensive guidance
416+
/// - You want to understand the agent's reasoning process
288417
///
289418
/// Note: This will make model building take longer because the agent does more analysis, but you'll
290419
/// get more insights and potentially better results.
@@ -296,7 +425,10 @@ public class AgentAssistanceOptions
296425
EnableModelSelection = true,
297426
EnableHyperparameterTuning = true,
298427
EnableFeatureAnalysis = true,
299-
EnableMetaLearningAdvice = true
428+
EnableMetaLearningAdvice = true,
429+
EnableReasoning = true,
430+
MaxReasoningSteps = 7,
431+
ReasoningConfidenceThreshold = 0.7
300432
};
301433

302434
/// <summary>
@@ -331,6 +463,9 @@ public class AgentAssistanceOptions
331463
EnableModelSelection = this.EnableModelSelection,
332464
EnableHyperparameterTuning = this.EnableHyperparameterTuning,
333465
EnableFeatureAnalysis = this.EnableFeatureAnalysis,
334-
EnableMetaLearningAdvice = this.EnableMetaLearningAdvice
466+
EnableMetaLearningAdvice = this.EnableMetaLearningAdvice,
467+
EnableReasoning = this.EnableReasoning,
468+
MaxReasoningSteps = this.MaxReasoningSteps,
469+
ReasoningConfidenceThreshold = this.ReasoningConfidenceThreshold
335470
};
336471
}

src/Models/AgentAssistanceOptionsBuilder.cs

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public class AgentAssistanceOptionsBuilder
4141
EnableModelSelection = false,
4242
EnableHyperparameterTuning = false,
4343
EnableFeatureAnalysis = false,
44-
EnableMetaLearningAdvice = false
44+
EnableMetaLearningAdvice = false,
45+
EnableReasoning = false,
46+
MaxReasoningSteps = 5,
47+
ReasoningConfidenceThreshold = 0.7
4548
};
4649

4750
/// <summary>
@@ -308,6 +311,129 @@ public AgentAssistanceOptionsBuilder DisableMetaLearningAdvice()
308311
return this;
309312
}
310313

314+
/// <summary>
315+
/// Enables Chain-of-Thought reasoning for agent decision-making.
316+
/// </summary>
317+
/// <returns>The current builder instance for method chaining.</returns>
318+
/// <remarks>
319+
/// <para>
320+
/// When enabled, the AI agent will generate step-by-step reasoning explanations when making decisions
321+
/// or recommendations during model building. This provides transparency into the agent's decision-making
322+
/// process and can help users understand why certain recommendations are made.
323+
/// </para>
324+
/// <para><b>For Beginners:</b> This makes the AI show its step-by-step thinking process.
325+
///
326+
/// What you get:
327+
/// - Detailed explanation of why the AI recommends certain choices
328+
/// - Step-by-step breakdown of the agent's reasoning
329+
/// - Transparency into AI decision-making
330+
/// - Educational insights about ML best practices
331+
///
332+
/// This is useful when:
333+
/// - You want to understand why the AI makes certain recommendations
334+
/// - You're learning about machine learning
335+
/// - You need to verify the agent's logic
336+
/// - You want to build trust in AI recommendations
337+
///
338+
/// For example, instead of just saying "Use Random Forest", the AI might explain:
339+
/// - "Step 1: Your dataset has 10,000 samples (medium-sized)"
340+
/// - "Step 2: Features show non-linear relationships"
341+
/// - "Step 3: Random Forest handles non-linearity well"
342+
/// - "Conclusion: Recommend Random Forest"
343+
///
344+
/// Note: This may make responses slightly longer and take more time.
345+
/// </para>
346+
/// </remarks>
347+
public AgentAssistanceOptionsBuilder EnableReasoning()
348+
{
349+
_options.EnableReasoning = true;
350+
return this;
351+
}
352+
353+
/// <summary>
354+
/// Disables Chain-of-Thought reasoning.
355+
/// </summary>
356+
/// <returns>The current builder instance for method chaining.</returns>
357+
/// <remarks>
358+
/// This method turns off reasoning explanations, useful if you want quick recommendations
359+
/// without detailed step-by-step explanations.
360+
/// </remarks>
361+
public AgentAssistanceOptionsBuilder DisableReasoning()
362+
{
363+
_options.EnableReasoning = false;
364+
return this;
365+
}
366+
367+
/// <summary>
368+
/// Sets the maximum number of reasoning steps the agent should generate.
369+
/// </summary>
370+
/// <param name="maxSteps">The maximum number of reasoning steps (1-10).</param>
371+
/// <returns>The current builder instance for method chaining.</returns>
372+
/// <remarks>
373+
/// <para>
374+
/// Controls how many reasoning steps the agent will generate when EnableReasoning is true.
375+
/// More steps provide more detailed explanations but take longer to generate.
376+
/// </para>
377+
/// <para><b>For Beginners:</b> This controls how detailed the AI's explanations are.
378+
///
379+
/// Recommended values:
380+
/// - 3-5: Quick, concise reasoning (faster)
381+
/// - 5-7: Balanced detail (recommended)
382+
/// - 7-10: Very detailed explanations (slower but thorough)
383+
///
384+
/// Default is 5 steps, which works well for most cases.
385+
/// </para>
386+
/// </remarks>
387+
/// <exception cref="ArgumentOutOfRangeException">
388+
/// Thrown when maxSteps is less than 1 or greater than 10.
389+
/// </exception>
390+
public AgentAssistanceOptionsBuilder WithMaxReasoningSteps(int maxSteps)
391+
{
392+
if (maxSteps < 1 || maxSteps > 10)
393+
throw new ArgumentOutOfRangeException(nameof(maxSteps), "Maximum reasoning steps must be between 1 and 10.");
394+
395+
_options.MaxReasoningSteps = maxSteps;
396+
return this;
397+
}
398+
399+
/// <summary>
400+
/// Sets the minimum confidence threshold for reasoning verification.
401+
/// </summary>
402+
/// <param name="threshold">The confidence threshold (0.0 to 1.0).</param>
403+
/// <returns>The current builder instance for method chaining.</returns>
404+
/// <remarks>
405+
/// <para>
406+
/// Controls the minimum confidence score required for reasoning steps to be considered valid.
407+
/// Steps below this threshold may trigger refinement or additional verification.
408+
/// </para>
409+
/// <para><b>For Beginners:</b> This sets the quality bar for the AI's reasoning.
410+
///
411+
/// How it works:
412+
/// - Each reasoning step gets a confidence score (0.0 to 1.0)
413+
/// - Steps below the threshold are flagged for refinement
414+
/// - Higher threshold = more reliable but slower
415+
/// - Lower threshold = faster but may accept weaker reasoning
416+
///
417+
/// Recommended values:
418+
/// - 0.5-0.6: Lenient (faster, less rigorous)
419+
/// - 0.7-0.8: Balanced (recommended)
420+
/// - 0.8-0.9: Strict (slower, more reliable)
421+
///
422+
/// Default is 0.7, which provides good quality control.
423+
/// </para>
424+
/// </remarks>
425+
/// <exception cref="ArgumentOutOfRangeException">
426+
/// Thrown when threshold is less than 0.0 or greater than 1.0.
427+
/// </exception>
428+
public AgentAssistanceOptionsBuilder WithReasoningConfidenceThreshold(double threshold)
429+
{
430+
if (threshold < 0.0 || threshold > 1.0)
431+
throw new ArgumentOutOfRangeException(nameof(threshold), "Reasoning confidence threshold must be between 0.0 and 1.0.");
432+
433+
_options.ReasoningConfidenceThreshold = threshold;
434+
return this;
435+
}
436+
311437
/// <summary>
312438
/// Builds and returns the configured AgentAssistanceOptions instance.
313439
/// </summary>

0 commit comments

Comments
 (0)