Plugins in semantic kernel doesn't work - python

Ghazal 0 Reputation points
2025-04-06T14:23:23.9866667+00:00

Hi I am trying to implement a plugin for my agent using the seemantic kernel plugins in python. But doesn't matter how I implement it:

  • directy creating the plugin in the 'Plugins' folder in the script itself;
  • trying to impement the FunFact and Joke (ready made);

-copy and paste a code from the AI Agent book (Chapter 05)
I keep getting this error that the plugin is not found
36, in __getitem__

return self.functions[key]

~~~~~~~~~~~~~~^^^^^

KeyError: 'recommender, ....'
Do you have any idea on what am I doing wrong? or what is goin on? This is my code and recommend pugin with SKprompt.txt and Config.json both are nestedd under "RecommendPlugin".

recommender_plugin = kernel.add_plugin(
    plugins_path,
    plugin_name="recommend",
)

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Pavankumar Purilla 8,335 Reputation points Microsoft External Staff Moderator
    2025-04-08T06:44:40.5766667+00:00

    Hi Ghazal,

    The issue you’re encountering (KeyError: 'recommender') usually means that the plugin or one of its functions is not being properly recognized or registered by Semantic Kernel.

    In Semantic Kernel, there are two main ways to add and use plugins: one is through prompt-based plugins, which require a specific folder structure containing skprompt.txt and config.json; the other is through native code plugins, where you define your plugin as a Python class and use the @kernel_function decorator on its methods. This error often happens if the plugin folder name, plugin name, or function name used in your code doesn’t exactly match what is defined or loaded into the kernel. For prompt-based plugins, it’s important to ensure that the folder and file names are correct and that you are using add_plugin_from_directory() to load them.

    However, we recommend using native code plugins, especially when getting started. You can define a class with your functions and register it using kernel.add_plugin(MyPlugin(), plugin_name="recommender"). This method also integrates smoothly with AI function calling. Switching to this approach should help you avoid plugin registration issues and make your development process smoother.

    For more information: What is a Plugin
    I hope this information helps. Thank you!

    0 comments No comments

  2. Ghazal 0 Reputation points
    2025-04-14T08:24:27.9766667+00:00

    Hi Pavankumar,

    Thanks for your reply. I think I have updated the IDE and for some reason it wasn't loading the new libraries for semantic-kernel. It is now working just fine after a restart. I am also using the new Function calling. It was more than helpful!

    0 comments No comments

  3. Pavankumar Purilla 8,335 Reputation points Microsoft External Staff Moderator
    2025-04-15T01:12:52.2033333+00:00

    Hi Ghazal,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution.

    Please click "Accept" the answer as original posters help the community find answers faster by identifying the correct answer.

    Issue : Plugins in semantic kernel doesn't work - python

    Resolution : I think I have updated the IDE and for some reason it wasn't loading the new libraries for semantic-kernel. It is now working just fine after a restart. I am also using the new Function calling.

    Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members.

    Accept answers on Microsoft Q&A | Microsoft Learn

    An accepted answer is the answer that the person who asked the question chooses as the one they think best solves their problem.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.