Semantic Kernel JavaScript
    Preparing search index...

    Represents a kernel.

    Index

    Constructors

    • Creates a new kernel.

      Returns Kernel

    Accessors

    • get services(): ServiceProvider

      Gets the ServiceProvider instance.

      Returns ServiceProvider

    Methods

    • Adds a plugin to the kernel.

      Parameters

      • plugin: ArrayKernelPlugin

        The plugin to add.

      Returns this

      The kernel.

    • Adds a service to the kernel.

      Parameters

      • ...props: [service: unknown, options?: { serviceId: string }]

      Returns this

      The kernel.

    • Invokes a prompt.

      Parameters

      Returns Promise<undefined | ChatResponse>

      The result of the prompt invocation.

    • Internal method to handle prompt rendering with filters.

      Parameters

      Returns Promise<PromptRenderContext>

    • Adds a function invocation filter to the kernel. These filters allow you to intercept and modify function execution operations using a middleware pattern. Filters are executed in registration order.

      Parameters

      • callback: (
            context: KernelFunctionInvocationContext,
            next: (context: KernelFunctionInvocationContext) => Promise<void>,
        ) => Promise<void>

        The callback function that will be invoked when a function is executed. This function receives a KernelFunctionInvocationContext and a next function. Call next(context) to continue to the next filter or actual function execution. Omit calling next() to short-circuit the pipeline.

      Returns void

      // Add a performance monitoring filter
      kernel.useFunctionInvocation(async (context, next) => {
      const start = Date.now();
      console.log(`Starting: ${context.function.metadata.name}`);

      await next(context);

      const duration = Date.now() - start;
      console.log(`Completed ${context.function.metadata.name} in ${duration}ms`);
      });

      // Add an error handling filter
      kernel.useFunctionInvocation(async (context, next) => {
      try {
      await next(context);
      } catch (error) {
      console.error(`Function ${context.function.metadata.name} failed:`, error);
      throw error;
      }
      });
      • KernelFunctionInvocationContext for details about the context object
      • FunctionInvocationFilter for the filter function signature
    • Adds a prompt rendering filter to the kernel. These filters allow you to intercept and modify prompt rendering operations using a middleware pattern. Filters are executed in registration order.

      Parameters

      • callback: (
            context: PromptRenderContext,
            next: (context: PromptRenderContext) => Promise<void>,
        ) => Promise<void>

        The callback function that will be invoked when a prompt is rendered. This function receives a PromptRenderContext and a next function. Call next(context) to continue to the next filter or actual prompt rendering. Omit calling next() to short-circuit the pipeline.

      Returns void

      // Add a logging filter
      kernel.usePromptRender(async (context, next) => {
      console.log('Rendering prompt for:', context.function.metadata.name);
      await next(context);
      console.log('Rendered prompt:', context.renderedPrompt);
      });

      // Add a prompt modification filter
      kernel.usePromptRender(async (context, next) => {
      await next(context);
      if (context.renderedPrompt) {
      context.renderedPrompt += '\nPlease provide a helpful response.';
      }
      });
      • PromptRenderContext for details about the context object
      • PromptRenderFilter for the filter function signature