namespace AxCopilot.Services.Agent; internal static class AgentLoopRuntimeThresholds { public static int GetNoToolCallResponseThreshold(int defaultValue) => ResolveThresholdValue( Environment.GetEnvironmentVariable("AXCOPILOT_NOTOOL_RESPONSE_THRESHOLD"), defaultValue, min: 1, max: 6); public static int GetNoToolCallRecoveryMaxRetries(int defaultValue) => ResolveThresholdValue( Environment.GetEnvironmentVariable("AXCOPILOT_NOTOOL_RECOVERY_MAX_RETRIES"), defaultValue, min: 0, max: 6); public static int GetPlanExecutionRetryMax(int defaultValue) => ResolveThresholdValue( Environment.GetEnvironmentVariable("AXCOPILOT_PLAN_EXECUTION_RETRY_MAX"), defaultValue, min: 0, max: 6); public static int GetTerminalEvidenceGateMaxRetries(int defaultValue) => ResolveThresholdValue( Environment.GetEnvironmentVariable("AXCOPILOT_TERMINAL_EVIDENCE_GATE_MAX_RETRIES"), defaultValue, min: 0, max: 3); public static int ResolveNoToolCallResponseThreshold(string? envRaw) => ResolveThresholdValue(envRaw, defaultValue: 2, min: 1, max: 6); public static int ResolveNoToolCallRecoveryMaxRetries(string? envRaw) => ResolveThresholdValue(envRaw, defaultValue: 3, min: 0, max: 6); public static int ResolvePlanExecutionRetryMax(string? envRaw) => ResolveThresholdValue(envRaw, defaultValue: 2, min: 0, max: 6); public static int ResolveTerminalEvidenceGateMaxRetries(string? envRaw) => ResolveThresholdValue(envRaw, defaultValue: 1, min: 0, max: 3); private static int ResolveThresholdValue(string? raw, int defaultValue, int min, int max) { if (!int.TryParse(raw, out var value)) return defaultValue; return Math.Clamp(value, min, max); } }