Step by Step guide to develop AI Multi-Agent system using Microsoft Semantic Kernel and GPT-4o

Akshay Kokane
7 min readJun 8, 2024

--

AI agents are taking the tech world by storm. But with so much buzz, can they truly deliver on their promise? Absolutely! This blog series will equip you to not only understand AI agents but also build your own using the powerful Semantic Kernel framework.

Microsoft’s Powerhouse: Semantic Kernel Levels Up AI Integration

Remember that blog post I wrote earlier this year about Semantic Kernel, the game-changer for AI integration? Well, buckle up because Semantic Kernel has undergone a serious upgrade, offering a treasure trove of tools for building next-level AI systems.

While similar to LangChain, Semantic Kernel is specifically designed for enterprise-scale projects. It boasts a smooth onboarding process, effortlessly manages multiple Large Language Models (LLMs), and provides pre-built features like planners to simplify orchestration.

The Rise of AI LLM Agents and Collaborative Systems

Introducing AI LLM agents, powerful entities powered by cutting-edge Large Language Models like GPT-4. These AI agents can process and generate human-like text, perform function calls, interpret code, and more, making them ideal for applications like chatbots, virtual assistants, and even creative writing.

The future lies in multi-agent systems, where multiple AI agents collaborate. Semantic Kernel empowers the creation of these complex systems, allowing agents to share information, coordinate actions, and achieve goals beyond the reach of a single agent.

From Chatbots to AI Assistants: The Evolution of AI Agents

Since the launch of GPT models, terms like “chatbot,” “RAG,” “Copilot,” and now “agent” have dominated the AI landscape. As Semantic Kernel’s documentation clarifies: “An agent is an artificial intelligence that can answer questions and automate processes for users.” With Semantic Kernel, you can build a wide range of agents, from simple chatbots to fully automated AI assistants.

Ref: https://learn.microsoft.com/en-us/semantic-kernel/agents/

Open AI Assistant v2:

The OpenAI Assistants API enables developers to create advanced AI assistants for their applications without the need to manage conversation history. Developers can utilize OpenAI-hosted tools such as Code Interpreter and File Search, empowering assistants to engage with users, access files, maintain conversation threads, and utilize external tools seamlessly.

Building Multi-Agent Software Development Team with Semantic Kernel and GPT-4o

We’ll explore the exciting world of building AI agents using Semantic Kernel and the OpenAI Assistant API. We’ll simulate a collaborative development process, outlining the roles of key team members:

  • Product Manager: The maestro of the project, crafting a development plan that translates user needs into actionable steps.
  • Software Engineer: The coding wizard, responsible for implementing the plan and bringing the agent to life.
  • Project Manager: The guardian of quality, ensuring the final product meets all specifications and receives the green light for release.

Prerequisites :

  1. .NET 8
  2. Visual Studio Code
  3. [Optional] Jupyter Notebook with .NET Interactive kernel

Step 1: Install necessary nuget packages for Semantic Kernel and initialise the kernel with GPT-4o

#r "nuget: Microsoft.SemanticKernel.Agents.Abstractions, 1.14.1-alpha"
#r "nuget: Microsoft.SemanticKernel.Agents.Core, 1.14.1-alpha"
#r "nuget: Microsoft.SemanticKernel.Agents.OpenAI, 1.14.1-alpha"
#r "nuget: Microsoft.SemanticKernel.Connectors.OpenAI, 1.14.1-alpha"

Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: "gpt-4o",
apiKey: OaiApiKey)
.Build();

Step 2: Lets create 3 agents.


string ProgamManager = """
You are a program manager which will take the requirement and create a plan for creating app. Program Manager understands the
user requirements and form the detail documents with requirements and costing.
""";

string SoftwareEngineer = """
You are Software Engieer, and your goal is develop web app using HTML and JavaScript (JS) by taking into consideration all
the requirements given by Program Manager.
""";

string Manager = """
You are manager which will review software engineer code, and make sure all client requirements are completed.
Once all client requirements are completed, you can approve the request by just responding "approve"
""";

#pragma warning disable SKEXP0110, SKEXP0001 // Rethrow to preserve stack details

ChatCompletionAgent ProgaramManagerAgent =
new()
{
Instructions = ProgamManager,
Name = "ProgaramManagerAgent",
Kernel = kernel
};

ChatCompletionAgent SoftwareEngineerAgent =
new()
{
Instructions = SoftwareEngineer,
Name = "SoftwareEngineerAgent",
Kernel = kernel
};

ChatCompletionAgent ProjectManagerAgent =
new()
{
Instructions = Manager,
Name = "ProjectManagerAgent",
Kernel = kernel
};

Step 3: We also want to terminate the agent operation when Project Manager approves the final output. We need to define the termination strategy

    
using System.Threading;

private sealed class ApprovalTerminationStrategy : TerminationStrategy
{
// Terminate when the final message contains the term "approve"
protected override Task<bool> ShouldAgentTerminateAsync(Agent agent, IReadOnlyList<ChatMessageContent> history, CancellationToken cancellationToken)
=> Task.FromResult(history[history.Count - 1].Content?.Contains("approve", StringComparison.OrdinalIgnoreCase) ?? false);
}

Step 4: We want these agents to interact with each other. We will create a agent group chat, so that these agents can interact with each other

AgentGroupChat chat =
new(ProgaramManagerAgent, SoftwareEngineerAgent, ProjectManagerAgent)
{
ExecutionSettings =
new()
{
TerminationStrategy =
new ApprovalTerminationStrategy()
{
Agents = [ProjectManagerAgent],
MaximumIterations = 6,
}
}
};

Step 5: Lets see it in action

    string input = """

I want to develop calculator app.
Keep it very simple. And get final approval from manager.
""";

chat.AddChatMessage(new ChatMessageContent(AuthorRole.User, input));
Console.WriteLine($"# {AuthorRole.User}: '{input}'");

await foreach (var content in chat.InvokeAsync())
{
Console.WriteLine($"# {content.Role} - {content.AuthorName ?? "*"}: '{content.Content}'");
}

Output:

Output from HTML code generated by AI response

Agent Interactions:

# user: '
I want to develop app which will provide me calculator. Keep it very simple. And get final approval from manager.'
# assistant - ProgaramManagerAgent: 'Great! Let's outline the details for the simple calculator app project and then we can generate a detailed document including requirements, high-level features, estimated timeline, and costing.

### Simple Calculator App Project Plan

---

#### 1. Project Overview
Develop a basic calculator application that can perform simple arithmetic operations like addition, subtraction, multiplication, and division.

#### 2. Key Features
- **User Interface (UI):**
- Simple and intuitive design.
- Display screen for showing the numbers and results.
- Number buttons (0-9).
- Basic operation buttons (+, -, *, /).
- Clear (C) button to reset the calculation.
- Equals (=) button to get the result.

- **Functionalities:**
- Perform basic arithmetic operations (Addition, Subtraction, Multiplication, Division).
- Display accurate results.
- Handle errors like division by zero.

#### 3. Technical Requirements
- **Platform:** iOS and Android
- **Development Framework:** React Native (for cross-platform support)
- **Programming Language:** JavaScript, optionally TypeScript
- **UI Framework:** React Native components + custom styling
- **State Management:** React useState for local state

#### 4. Timeline
| Phase | Duration (days) | Description |
|-------------------------|-----------------|-----------------------------------------------------|
| Requirement Gathering | 1 | Collect all necessary requirements |
| Design | 2 | Design basic wireframes and UI/UX elements |
| Development Setup | 1 | Setup development environment and repositories |
| Core Feature Development| 4 | Develop UI and key functionalities of the calculator|
| Testing | 2 | Perform unit and integration testing |
| Review and Feedback | 1 | Review with stakeholders and apply feedback |
| Finalization & Deployment| 1 | Final bug fixes and deploy to app stores |

**Total Duration:** 12 days

#### 5. Cost Estimation
| Task/Role | Hourly Rate ($) | Hours | Total Cost ($) |
|-------------------------|-----------------|-------|---------------------------------|
| Project Management | 50 | 4 | 200 |
| UI/UX Design | 40 | 16 | 640 |
| Development | 60 | 32 | 1,920 |
| Testing | 50 | 16 | 800 |
| Review & Feedback | 50 | 2 | 100 |
| Deployment | 50 | 4 | 200 |
| **Total Cost** | | | **3,860** |

#### 6. Assumptions
- The app is very basic with no advanced functionalities.
- No backend server or user authentication required.
- No need for advanced error handling or logging.
- The app will support only one language (English).

---

### Next Steps
1. Review the above plan and make any modifications if needed.
2. Get final approval from the manager.
3. Proceed with the project execution.

Would you like to make any changes or additions before we present this to the manager for final approval?'
# assistant - SoftwareEngineerAgent: 'This is the Software Engineer stepping in. Based on the requirements provided and the project plan outlined, I'll proceed with creating a very basic calculator web application using HTML and JavaScript.

Here's the initial implementation:

### Simple Calculator App (HTML + JavaScript)

#### 1. HTML Code

```html
<!DOCTYPE html>
<html lang="en">
...<CHECK OUT MY GIT REPO FOR ACTUAL GENERATED HTML CODE>
```

This code creates a basic calculator with a simple and intuitive UI using HTML and JavaScript. It will be fully functional and can perform basic arithmetic operations.

Please review this initial implementation and let me know if there are any changes or additional features you'd like to include before finalizing it.'
# assistant - ProjectManagerAgent: 'For the requirements specified by the client, this implementation covers everything needed:

1. **Simple and Intuitive Design**: ✔️
2. **Display Screen for Numbers and Results**: ✔️
3. **Number Buttons (0-9)**: ✔️
4. **Basic Operation Buttons (+, -, *, /)**: ✔️
5. **Clear (C) Button to Reset the Calculation**: ✔️
6. **Equals (=) Button to Get the Result**: ✔️
7. **Basic Error Handling (e.g., Division by Zero handled in JS logic)**: ✔️

Client requirements have been fulfilled as per the provided instructions.

approve'

Here is the link to the notebook: https://github.com/akshaykokane/MultiAIAgentSystem/blob/main/MultiAIAgentSystemExample.ipynb

Conclusion

In conclusion, AI agents are a game-changer for crafting intelligent applications. They streamline development by eliminating the need to manage complex histories or cumbersome tool invocation. With their immense potential, AI agents pave the way for a future filled with creative and groundbreaking systems. Stay tuned for my next blog post, where we’ll delve into creating plugins and leveraging OpenAI function calling within the agent framework.

References:

--

--

Akshay Kokane

Software Engineer at Microsoft | Microsoft Certified AI Engineer & Google Certified Data Engineer