microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.76k stars 3.23k forks source link

.Net: RC4 HandlebarsPlanner.CreatePlanAsync System.StackOverflowException #4324

Closed strikene closed 8 months ago

strikene commented 10 months ago

Describe the bug This bug exists in RC3, RC4 at the same time, even if no plugins are loaded HandlebarsPlanner.CreatePlanAsync Throws an exception System.StackOverflowException To Reproduce Steps to reproduce the behavior: HandlebarsPlanner hbp = new HandlebarsPlanner(new HandlebarsPlannerOptions() {AllowLoops=false });

var createdplan = await hbp.CreatePlanAsync(sk._SK_Kernel, "Generate an analysis report, refer to C:\1. pdf" );

To Reproduce at Microsoft.SemanticKernel.Planning.Handlebars.KernelParameterMetadataExtensions.ToHandlebarsParameterTypeMetadata(System.Type) at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner.SetComplexTypeDefinition(Microsoft.SemanticKernel.KernelParameterMetadata, System.Collections.Generic.HashSet1<Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsParameterTypeMetadata>, System.Collections.Generic.Dictionary2<System.String,System.String>) at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner.GetAvailableFunctionsManual(Microsoft.SemanticKernel.Kernel, System.Collections.Generic.HashSet1<Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsParameterTypeMetadata> ByRef, System.Collections.Generic.Dictionary2<System.String,System.String> ByRef) at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner+d8.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner+d8, Microsoft.SemanticKernel.Planners.Handlebars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3]](d8 ByRef) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner+d8, Microsoft.SemanticKernel.Planners.Handlebars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3]](d8 ByRef) at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner.CreatePlanCoreAsync(Microsoft.SemanticKernel.Kernel, System.String, System.Threading.CancellationToken) at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner+<>c.b__2_0(Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner, Microsoft.SemanticKernel.Kernel, System.String, System.Threading.CancellationToken) at Microsoft.SemanticKernel.Planning.PlannerInstrumentation+d4`2[[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.SemanticKernel.Planning.PlannerInstrumentation+d42[[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Microsoft.SemanticKernel.Planners.Handlebars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3]](<CreatePlanAsync>d__42<System.Canon,System.Canon> ByRef) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Microsoft.SemanticKernel.Planning.PlannerInstrumentation+<CreatePlanAsync>d__42[[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Microsoft.SemanticKernel.Planners.Handlebars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3]](d4`2<System.Canon,System.Canon> ByRef) at Microsoft.SemanticKernel.Planning.PlannerInstrumentation.CreatePlanAsync[[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Func`5<System.Canon,Microsoft.SemanticKernel.Kernel,System.String,System.Threading.CancellationToken,System.Threading.Tasks.Task`1>, System.Canon, Microsoft.SemanticKernel.Kernel, System.String, Microsoft.Extensions.Logging.ILogger, System.Threading.CancellationToken) at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlanner.CreatePlanAsync(Microsoft.SemanticKernel.Kernel, System.String, System.Threading.CancellationToken) at ConsoleChatMSSKV2.Program+

d0.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Canon ByRef)

Screenshots

image

Platform

  • OS: Windows
  • IDE: Visual Studio
  • Language: C# .net7
  • Source: "Microsoft.Extensions.Http.Resilience" Version="8.0.0" "Microsoft.KernelMemory.WebClient" Version="0.20.231211.3" "Azure.ResourceManager.Billing" Version="1.0.1" "Azure.ResourceManager.Resources" Version="1.6.0" "Azure.ResourceManager.Subscription" Version="1.0.1" "Azure.ResourceManager.Support" Version="1.0.1" "Microsoft.SemanticKernel" Version="1.0.0-rc4" "Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.0.0-rc4" "Microsoft.SemanticKernel.Connectors.Sqlite" Version="1.0.0-rc4" "Microsoft.SemanticKernel.Experimental.Assistants" Version="1.0.0-rc4" "Microsoft.SemanticKernel.Experimental.Orchestration.Flow" Version="1.0.0-beta8" "Microsoft.SemanticKernel.Planners.Handlebars" Version="1.0.0-rc4" "Microsoft.SemanticKernel.Planners.OpenAI" Version="1.0.0-rc4" "Microsoft.SemanticKernel.Plugins.MsGraph" Version="1.0.0-rc4" "Microsoft.SemanticKernel.Plugins.Web" Version="1.0.0-rc4" "SharpToken" Version="1.2.12" "Azure.AI.OpenAI" Version="1.0.0-beta.11" "System.Text.Json" Version="8.0.0"
alliscode commented 10 months ago

Hi @strikene, thank you for creating this issue. I have not been able to reproduce this. Looking at the stack trace, HandlebarsPlanner.GetAvailableFunctionsManual is calling into HandlebarsPlanner.SetComplexTypeDefinition which indicates that it's found at least one plugin registered.

If you have any plugins registered, can you please provide information about them to help us diagnose the issue?

If you are sure there are no plugins registered, could you please provide a minimal example that reproduces the error, showing how you are creating the kernel?

Thanks!

alliscode commented 10 months ago

PR #4344 fixes an issue where a plugin with a parameter that is defined recursively results in a stack overflow exception. This may be the same issue that you are seeing. Please take a cool and let us know if this matches your situation. Thanks.

strikene commented 10 months ago

Hi @strikene, thank you for creating this issue. I have not been able to reproduce this. Looking at the stack trace, HandlebarsPlanner.GetAvailableFunctionsManual is calling into HandlebarsPlanner.SetComplexTypeDefinition which indicates that it's found at least one plugin registered.

If you have any plugins registered, can you please provide information about them to help us diagnose the issue?

If you are sure there are no plugins registered, could you please provide a minimal example that reproduces the error, showing how you are creating the kernel?

Thanks!

HI @alliscode

I found the reason I loaded the TextMemoryPlugin,HttpPlugin,TextPlugin,TimePlugin,WaitPlugin,ConversationSummaryPlugin and once I didn't load it there would be no problem

here is code show add 'TextMemoryPlugin' IKernelBuilder builder = //new KernelBuilder() Kernel.CreateBuilder() .AddAzureOpenAIChatCompletion( deploymentName: cfg_ChatCompletion.ModelName, endpoint: cfg_ChatCompletion.EndPoint, apiKey: cfg_ChatCompletion.Key, serviceId: OpenAIUseType.ChatCompletion.ToString(), modelId: "GPT-4") .AddAzureOpenAIChatCompletion( deploymentName: cfg_Planer.ModelName, endpoint: cfg_Planer.EndPoint, apiKey: cfg_Planer.Key, serviceId: OpenAIUseType.Planer.ToString(), modelId: "GPT-4") .AddAzureOpenAIChatCompletion( deploymentName: cfg_AssistantRole.ModelName, endpoint: cfg_AssistantRole.EndPoint, apiKey: cfg_AssistantRole.Key, serviceId: OpenAIUseType.AssistantRole.ToString(), modelId: "GPT-4") .AddAzureOpenAITextEmbeddingGeneration( deploymentName: cfg_Embedding.ModelName, endpoint: cfg_Embedding.EndPoint, apiKey: cfg_Embedding.Key, serviceId: OpenAIUseType.Embedding.ToString(), modelId: "text-embedding-ada-002") ; /// 429 builder.Services.AddHttpClient(); builder.Services.ConfigureHttpClientDefaults(c => { c.AddHttpMessageHandler(x => new AzureOpenAIRequestDelegatingHandler( _MSSKV2LoggerFactory.CreateLogger(nameof(AzureOpenAIRequestDelegatingHandler)) , 10)); }); this._SK_Kernel = builder.Build(); ITextEmbeddingGenerationService embeddingGenerator = this._SK_Kernel.GetRequiredService();

this._SemanticTextMemory = new(store.Result, embeddingGenerator); this._TextMemoryPlugin = new(this._SemanticTextMemory); // use for recall an add memory this._SK_Kernel.ImportPluginFromObject(this._TextMemoryPlugin);

this._SK_Kernel.ImportPluginFromObject(new ExtenedFilePlugin(), nameof(ExtenedFilePlugin)); this._SK_Kernel.ImportPluginFromObject(new HttpPlugin(), nameof(HttpPlugin)); this._SK_Kernel.ImportPluginFromObject(new TextPlugin(), nameof(TextPlugin)); this._SK_Kernel.ImportPluginFromObject(new TimePlugin(), nameof(TimePlugin)); this._SK_Kernel.ImportPluginFromObject(new WaitPlugin(), nameof(WaitPlugin)); this._SK_Kernel.ImportPluginFromObject(new ConversationSummaryPlugin(), nameof(ConversationSummaryPlugin));

In fact, this error occurs when I just load 'TextMemoryPlugin'.

Maybe I'm loading the plugin the wrong way?

matthewbolanos commented 9 months ago

Can you try importing the plugins using ImportPluginFromType? I.e., this._SK_Kernel.ImportPluginFromType()?

teresaqhoang commented 8 months ago

Closing as this should be resolved with PR #4344

Also verified import of all the following plugins at once doesn't produce exception

kernel.ImportPluginFromObject(new TextMemoryPlugin(memoryWithACS), nameof(TextMemoryPlugin));
kernel.ImportPluginFromObject(new HttpPlugin(), nameof(HttpPlugin));
kernel.ImportPluginFromObject(new TextPlugin(), nameof(TextPlugin));
kernel.ImportPluginFromObject(new TimePlugin(), nameof(TimePlugin));
kernel.ImportPluginFromObject(new WaitPlugin(), nameof(WaitPlugin));
kernel.ImportPluginFromObject(new ConversationSummaryPlugin(), nameof(ConversationSummaryPlugin));

See logs: RunPoetrySampleAsync-638423948945845517.txt