Skip to main content

Overview

The AutoGen.SemanticKernel package enables integration between AutoGen and Microsoft Semantic Kernel, allowing you to:
  • Use Semantic Kernel agents in AutoGen workflows
  • Access Semantic Kernel plugins from AutoGen agents
  • Combine both frameworks’ strengths
  • Leverage existing Semantic Kernel code

Installation

You’ll also need the Semantic Kernel package:

Basic Setup

1

Create a Semantic Kernel

2

Create a SemanticKernelAgent

3

Use the agent

SemanticKernelAgent

The main agent class for Semantic Kernel integration:

Constructor Parameters

Kernel
required
Configured Semantic Kernel instance
string
required
Unique identifier for the agent
string
Instructions defining the agent’s behavior

Using Semantic Kernel Plugins

Leverage Semantic Kernel plugins in AutoGen:
1

Create Semantic Kernel plugins

2

Add plugins to kernel

3

Create agent with plugins

Multi-Agent with Semantic Kernel

Combine Semantic Kernel and OpenAI agents:

Azure OpenAI with Semantic Kernel

Use Azure OpenAI in Semantic Kernel:

Using Kernel Functions with AutoGen Agents

Use Semantic Kernel functions with non-SK agents:

Built-in Semantic Kernel Plugins

Use built-in SK plugins:

Prompt Templates

Use Semantic Kernel prompt templates:
Provide:
  1. Overall assessment
  2. Potential bugs
  3. Improvement suggestions
  4. Best practices violated ”;
var response = await kernel.InvokePromptAsync(prompt); return response.ToString(); } } var kernel = Kernel.CreateBuilder() .AddOpenAIChatCompletion(“gpt-4”, apiKey) .Build(); kernel.Plugins.AddFromObject(new TemplatePlugin(), “Template”); var agent = new SemanticKernelAgent( kernel: kernel, name: “reviewer”) .RegisterMessageConnector();

Custom Plugins

Create complex plugins:

Message Connector

Register the message connector for AutoGen message support:

Best Practices

Use SemanticKernelAgent when:
  • You have existing Semantic Kernel code
  • You need SK-specific plugins (Bing, etc.)
  • You want SK’s memory capabilities
  • You’re using SK prompt templates
  • You need SK’s planning features
  • Reuse Kernel instances
  • Cache plugin results when appropriate
  • Use async operations for I/O
  • Limit plugin complexity
  • Monitor token usage

Semantic Kernel vs AutoGen Functions

Semantic Kernel Plugins

Advantages:
  • Rich ecosystem of plugins
  • Built-in memory and planning
  • Prompt templates
  • Enterprise features
Use for:
  • Complex orchestration
  • Multi-step planning
  • Memory requirements
  • Existing SK code

AutoGen Functions

Advantages:
  • Simpler, lighter weight
  • Source generator for type safety
  • Direct control
  • Better for simple functions
Use for:
  • Simple function calling
  • New projects
  • Performance-critical code
  • Minimal dependencies

Next Steps

Function Calling

Learn about AutoGen’s function calling

OpenAI Integration

Use OpenAI models with AutoGen

Group Chat

Create multi-agent workflows

Semantic Kernel Docs