diff --git a/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs b/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs index 7490b64e1267..1ca19fcbcfff 100644 --- a/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs +++ b/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs @@ -19,7 +19,7 @@ public class InteractiveService : IDisposable private bool disposedValue; private const string DotnetInteractiveToolNotInstallMessage = "Cannot find a tool in the manifest file that has a command named 'dotnet-interactive'."; //private readonly ProcessJobTracker jobTracker = new ProcessJobTracker(); - private string installingDirectory; + private string? installingDirectory; public event EventHandler? DisplayEvent; @@ -30,7 +30,11 @@ public class InteractiveService : IDisposable public event EventHandler? HoverTextProduced; /// - /// Create an instance of InteractiveService + /// Install dotnet interactive tool to + /// and create an instance of . + /// + /// When using this constructor, you need to call to install dotnet interactive tool + /// and start the kernel. /// /// dotnet interactive installing directory public InteractiveService(string installingDirectory) @@ -38,8 +42,23 @@ public InteractiveService(string installingDirectory) this.installingDirectory = installingDirectory; } + /// + /// Create an instance of with a running kernel. + /// When using this constructor, you don't need to call to start the kernel. + /// + /// + public InteractiveService(Kernel kernel) + { + this.kernel = kernel; + } + public async Task StartAsync(string workingDirectory, CancellationToken ct = default) { + if (this.kernel != null) + { + return true; + } + this.kernel = await this.CreateKernelAsync(workingDirectory, true, ct); return true; }