chapter three

3 Building Chat Clients for Model Providers

 

This chapter covers

  • Understanding chatbots and chat clients in MEAI
  • Using Chat Completions with major AI model providers
  • Working with IChatClient as a unified abstraction
  • Managing conversation history and basic streaming

The Microsoft.Extensions.AI (MEAI) library is the foundational layer for any AI agent, connecting your applications to large language model providers. We explore MEAI and the building blocks you’ll need. You’ll use this foundation to dive deeper into Agent Framework and build complete agent systems.

Note

From now on, MEAI refers to Microsoft.Extensions.AI; we use the full name when clarity requires.

3.1 Introducing Robby, the Robot Car Assistant

Most of the time, analogies work best when dealing with abstract concepts, so we’ll imagine things from a robot-car perspective. Let’s name our robot car Robby. As we go, we’ll see how Robby evolves from a simple chatbot to an advanced AI agent and even benefits from a team of agents and an agentic AI architecture.

3.2 What is Chat Completion API?

3.2.1 Understanding the Request-Response Mechanism

3.3 Introduction to Chat Clients and Model Providers

3.3.1 IChatClient Abstraction Interface

3.3.2 Model Provider Implementation

3.3.3 Multi-Modal Support

3.4 Creating and Configuring Chat Clients

3.4.1 OpenAI Chat Completion Client

3.4.2 Azure OpenAI Chat Completion Client

3.4.3 Anthropic Client

3.4.4 Conversation History Management

3.4.5 Chat Options

3.4.6 Streaming Prompt Response

3.5 Adding Logging Using Middleware

3.6 Summary