Middleware in Microsoft Agent Framework

A critical need, when creating multi-agent applications is to manage token usage in API calls. This is where middleware plays a crucial role. In this post, we will explore what middleware is within the Microsoft Agent Framework, why it is essential for capping token usage, and how to implement it effectively.

What is Middleware in the Microsoft Agent Framework?

Middleware serves as an intermediary layer that processes requests and responses between users and AI agents. It acts as a bridge, allowing developers to intercept, inspect, and modify the data flowing through the system. This capability is vital for implementing additional logic, such as validation, logging, and, importantly, token management.

In the context of the Microsoft Agent Framework, middleware can be utilized to enhance the functionality of AI agents by providing a structured way to handle requests and responses. This not only improves the overall efficiency of the system but also allows for greater control over how the AI interacts with users.

Continue reading
Posted in AI | Leave a comment

Activity Source in Microsoft Agent Framework

In the rapidly evolving landscape of artificial intelligence, the ability to monitor and debug multi-agent systems is paramount. The Microsoft Agent Framework (MAF) has taken a significant step forward by integrating OpenTelemetry, a powerful observability framework that enhances the monitoring capabilities of AI agents. This post delves into the key features, innovations, and real-world applications of this integration, providing developers with the insights they need to optimize their AI systems.

Continue reading
Posted in AI | Comments Off on Activity Source in Microsoft Agent Framework

Logging & OpenTelemetry in MAF

In the rapidly evolving landscape of software development, particularly in the realm of artificial intelligence and automation, the importance of robust logging mechanisms cannot be overstated. This is especially true for multi-agent systems, where numerous agents interact and collaborate to achieve complex tasks. In this post, we will explore the significance of logging in a multi-agent Microsoft Agent Framework application, the trends and innovations in logging practices, real-world use cases, and a practical implementation example.

Continue reading
Posted in AI | Comments Off on Logging & OpenTelemetry in MAF

Which Pilot is Which?

Microsoft can make you crazy by naming so many products with overlapping titles: Copilot, Copilot Studio, GitHub Copilot, and GitHub Copilot App

In the rapidly evolving landscape of software development and productivity tools, understanding the distinctions between various Microsoft AI-assisted applications is crucial for developers and users alike. This post will delve into the differences between Copilot, Copilot Studio, GitHub Copilot, and the GitHub Copilot App, highlighting their unique features, use cases, and how they can enhance your workflow.

Continue reading
Posted in AI, Tools and Utilities | Comments Off on Which Pilot is Which?

Ensuring Agent Safety in AI Development

Key Insights from Microsoft Learn*

As artificial intelligence continues to evolve, ensuring the safety and security of AI agents has become more important. The Microsoft Learn documentation on agent safety provides a comprehensive overview of best practices and guidelines for developers.

Continue reading
Posted in AI | Comments Off on Ensuring Agent Safety in AI Development

MAF-Doctor Walkthrough

Our latest video is a walkthrough of MAF-Doctor. This is an extraordinary utility for anyone using the Microsoft Agent Framework.

Posted in AI, Microsoft Agent Framework, Utilities | Comments Off on MAF-Doctor Walkthrough

Transparency in Agentics

A key requirement in building agentic systems is for their reasoning to be transparent. This allows you to ensure accuracy and to provide “human in the loop” oversight. This is also a key requirement for debugging your agents and their interactions.

To accomplish this, your agents will need, at a minimum, structured logs of its plans, what tools it calls and an audit trail of the steps it takes.

Continue reading
Posted in AI, Programming | Comments Off on Transparency in Agentics

Migrating C# -> Microsoft Agent Framework

In a previous blog post I ported a Python application to C#. However, I did not take advantage of the Microsoft Agent Framework (MAF). In this admittedly long post, I’ll migrate that code to MAF.

Note, the updated source code for the .NET version of this demo application is available at https://github.com/JesseLiberty/blogMigration—public

The Microsoft Agent Framework (MAF) is an open-source software development kit (SDK) designed to facilitate the creation of agentic AI solutions and multi-agent workflows, primarily utilizing Python or C#.

Continue reading
Posted in AI, Microsoft Agent Framework, Programming | Comments Off on Migrating C# -> Microsoft Agent Framework

Dependency Injection & Agent Framework

In the previous blog posts we ported a Python implementation of an agentic application to C# and Microsoft Agent Framework. We used interfaces, but we did not use Dependency Injection (DI). It is pretty easy to add.

Agents, tools, executors and workflows all depend on interfaces, and DI depends on registering the relationship between these interfaces and the concrete class that implements them.

For example, here is how you create a workflow

services.AddSingleton<Workflow>(sp =>
{
    var blogger = sp.GetRequiredService<BloggerExecutor>();
    var researcher = sp.GetRequiredService<ResearcherExecutor>();
    var author = sp.GetRequiredService<AuthorExecutor>();
    var reviewer = sp.GetRequiredService<ReviewerExecutor>();

    return new WorkflowBuilder(blogger)
        .AddEdge(blogger, researcher)
        .AddEdge(researcher, author)
        .AddEdge(author, reviewer)
        .AddEdge<ResearchState>(reviewer, author, s => s?.NeedsRevision == true)
        .WithOutputFrom(reviewer)
        .Build();
});
Continue reading
Posted in AI, C#, Essentials, Programming | Comments Off on Dependency Injection & Agent Framework

Migrating Agentic Code Python -> C# Part 6 (final)

Note, the complete source code for the .NET version of this demo application is now available at https://github.com/JesseLiberty/blogMigration—public

In the previous post we finished up creating our agents. You’ll remember that each of the agents declared nodes. We’re finally going to put them to use in a class BlogWorkflow. However, up to now we’ve not fully taken advantage of the Microsoft Agent Framework (MAF). Let’s fix that up first. To do so we’ll add a class BlogExecutors. We’ll create MAF workflow executors that will wrap existing “node” chains so that the business logic is reused unchanged.

Note: In this post we’re only going to move towards Microsoft Agent Framework from where things currently stand. To see this fully migrated to an application that truly utilizes MAF, navigate to here


Let’s start with the BloggerExecutor which will allow the blogger to plan the task and seed the sub-task:

using Microsoft.Agents.AI.Workflows;

namespace BlogMigration;

/// <summary>Entry executor: lets the blogger plan the task and seed the sub-task.</summary>
internal sealed partial class BloggerExecutor(IBloggerChain blogger) : Executor("Blogger")
{
    [MessageHandler]
    private async ValueTask<ResearchState> HandleAsync(ResearchState state, IWorkflowContext context)
        => await blogger.BloggerNodeAsync(state);
}

An executor is a node in Microsoft Agent Framework. Each executor can receive messages, process them and emit new messages. In this case, whenever the workflow engine routes a ResearchState message to the executor, this method is invoked. The method takes the current workflow state and the workflow context and returns the updated ResearchState.

The executor is just a thin wrapper around the Blogger agent. The handler calls the Blogger node and the node updates the state.

Continue reading
Posted in AI, C#, Programming | Comments Off on Migrating Agentic Code Python -> C# Part 6 (final)

.NET Live Turns the Tables

I had the great privilege of being interviewed about AI on .NET Live. You can find the video on YouTube.

Find my YouTube channel here.

Posted in AI | Comments Off on .NET Live Turns the Tables

Migrating Agentic Code Python -> C# Part 5

In the previous post we looked at implementing the Researcher in C#. In this, as promised, we’ll look at the Author and the Reviewer.

The Author is handed two objects when instantiated: the llm (an IChatClient object) and the chatOptions. Its primary method is InvokeAsync, which is passed the current ResearchState.

public class AuthorChain(IChatClient llm, ChatOptions chatOptions) : IAuthorChain
{
    public async Task<string> InvokeAsync(ResearchState state)
    {
        List<string> research = state.ResearchFindings;
        string researchText = research.Count > 0 ? string.Join("\n\n", research) : "No research available.";

Its expectation is that the state object will have research information from the Researcher. It creates its prompt based on the state and then sends that prompt, along with its options, to the llm. What it gets back is its first draft which it will pass to the Reviewer

Continue reading
Posted in AI, C#, Programming | Comments Off on Migrating Agentic Code Python -> C# Part 5