A programming framework for agentic AI
fixed - added max retry parameter, increased max timeout.
Ryan Sweet40394ac126ee
diff --git a/cli/Program.cs b/cli/Program.csindex c47f2eb98..6dca0dbdd 100644--- a/cli/Program.cs+++ b/cli/Program.cs@@ -14,7 +14,7 @@ class Programstatic async Task Main(string[] args){- var maxRetryOption = new Option<int?>(+ var maxRetryOption = new Option<int>(name: "--maxRetry",description: "The number of retires to use if throttled",getDefaultValue: () => 6);@@ -29,27 +29,27 @@ class Programvar doCommand = new Command("do", "Doers :) ");var doItCommand = new Command("it", "Do it!");- doItCommand.SetHandler(async (file) => await ChainFunctions(file.FullName, maxRetry), fileOption, maxRetryOption);+ doItCommand.SetHandler(async (file, maxRetry) => await ChainFunctions(file.FullName, maxRetry), fileOption, maxRetryOption);doCommand.AddCommand(doItCommand);var pmCommand = new Command("pm", "Commands for the PM team");var pmReadmeCommand = new Command("readme", "Produce a Readme for a given input");- pmReadmeCommand.SetHandler(async (file) => await CallWithFile<string>(nameof(PM), PM.Readme , file.FullName), fileOption);+ pmReadmeCommand.SetHandler(async (file, maxRetry) => await CallWithFile<string>(nameof(PM), PM.Readme , file.FullName, maxRetry), fileOption, maxRetryOption);var pmBootstrapCommand = new Command("bootstrap", "Bootstrap a project for a given input");- pmBootstrapCommand.SetHandler(async (file) => await CallWithFile<string>(nameof(PM), PM.BootstrapProject, file.FullName), fileOption);+ pmBootstrapCommand.SetHandler(async (file, maxRetry) => await CallWithFile<string>(nameof(PM), PM.BootstrapProject, file.FullName, maxRetry), fileOption, maxRetryOption);pmCommand.AddCommand(pmReadmeCommand);pmCommand.AddCommand(pmBootstrapCommand);var devleadCommand = new Command("devlead", "Commands for the Dev Lead team");var devleadPlanCommand = new Command("plan", "Plan the work for a given input");- devleadPlanCommand.SetHandler(async (file) => await CallWithFile<DevLeadPlanResponse>(nameof(DevLead), DevLead.Plan, file.FullName), fileOption);+ devleadPlanCommand.SetHandler(async (file, maxRetry) => await CallWithFile<DevLeadPlanResponse>(nameof(DevLead), DevLead.Plan, file.FullName, maxRetry), fileOption, maxRetryOption);devleadCommand.AddCommand(devleadPlanCommand);var devCommand = new Command("dev", "Commands for the Dev team");var devPlanCommand = new Command("plan", "Implement the module for a given input");- devPlanCommand.SetHandler(async (file) => await CallWithFile<string>(nameof(Developer), Developer.Implement, file.FullName), fileOption);+ devPlanCommand.SetHandler(async (file, maxRetry) => await CallWithFile<string>(nameof(Developer), Developer.Implement, file.FullName, maxRetry), fileOption, maxRetryOption);devCommand.AddCommand(devPlanCommand);rootCommand.AddCommand(pmCommand);@@ -65,22 +65,22 @@ class Programvar sandboxSkill = new SandboxSkill();var outputPath = Directory.CreateDirectory("output");- var readme = await CallWithFile<string>(nameof(PM), PM.Readme , file);+ var readme = await CallWithFile<string>(nameof(PM), PM.Readme , file, maxRetry);string readmeFile = Path.Combine(outputPath.FullName, "README.md");await SaveToFile(readmeFile, readme);- var script = await CallWithFile<string>(nameof(PM), PM.BootstrapProject, file);+ var script = await CallWithFile<string>(nameof(PM), PM.BootstrapProject, file, maxRetry);await sandboxSkill.RunInDotnetAlpineAsync(script);await SaveToFile(Path.Combine(outputPath.FullName, "bootstrap.sh"), script);- var plan = await CallWithFile<DevLeadPlanResponse>(nameof(DevLead), DevLead.Plan, readmeFile);+ var plan = await CallWithFile<DevLeadPlanResponse>(nameof(DevLead), DevLead.Plan, readmeFile, maxRetry);await SaveToFile(Path.Combine(outputPath.FullName, "plan.json"), JsonSerializer.Serialize(plan));var implementationTasks = plan.steps.SelectMany((step) => step.subtasks.Select(async (subtask) => {- var implementationResult = await CallFunction<string>(nameof(Developer), Developer.Implement, subtask.LLM_prompt);- var improvementResult = await CallFunction<string>(nameof(Developer), Developer.Improve, subtask.LLM_prompt);+ var implementationResult = await CallFunction<string>(nameof(Developer), Developer.Implement, subtask.LLM_prompt, maxRetry);+ var improvementResult = await CallFunction<string>(nameof(Developer), Developer.Improve, subtask.LLM_prompt, maxRetry);await sandboxSkill.RunInDotnetAlpineAsync(implementationResult);await SaveToFile(Path.Combine(outputPath.FullName, $"{step.step}-{subtask.subtask}.sh"), improvementResult);return improvementResult; }));@@ -92,15 +92,15 @@ class Programawait File.WriteAllTextAsync(filePath, content);}- public static async Task<T> CallWithFile<T>(string skillName, string functionName, string filePath)+ public static async Task<T> CallWithFile<T>(string skillName, string functionName, string filePath, int maxRetry){if(!File.Exists(filePath))throw new FileNotFoundException($"File not found: {filePath}", filePath);var input = File.ReadAllText(filePath);- return await CallFunction<T>(skillName, functionName, input);+ return await CallFunction<T>(skillName, functionName, input, maxRetry);}- public static async Task<T> CallFunction<T>(string skillName, string functionName, string input)+ public static async Task<T> CallFunction<T>(string skillName, string functionName, string input, int maxRetry){var kernelSettings = KernelSettings.LoadSettings();var kernelConfig = new KernelConfig();@@ -123,11 +123,11 @@ class Program.WithConfiguration(kernelConfig).Configure(c => c.SetDefaultHttpRetryConfig(new HttpRetryConfig{- MaxRetryCount = 6,+ MaxRetryCount = maxRetry,UseExponentialBackoff = true,// MinRetryDelay = TimeSpan.FromSeconds(2),// MaxRetryDelay = TimeSpan.FromSeconds(8),- MaxTotalRetryTime = TimeSpan.FromSeconds(30),+ MaxTotalRetryTime = TimeSpan.FromSeconds(300),// RetryableStatusCodes = new[] { HttpStatusCode.TooManyRequests, HttpStatusCode.RequestTimeout },// RetryableExceptions = new[] { typeof(HttpRequestException) }}))