Skip to content

Commit 780a834

Browse files
authored
Merge pull request #662 from westey-m/ichatclient-based-agent
Add docs for building an IChatClient based agent.
2 parents b8a1a94 + ee95bbf commit 780a834

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

agent-framework/user-guide/agents/agent-types/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
href: openai-responses-agent.md
1313
- name: OpenAI Assistants Agents
1414
href: openai-assistants-agent.md
15+
- name: Agent based on any IChatClient
16+
href: chat-client-agent.md
1517
- name: A2A Agents
1618
href: a2a-agent.md
1719
- name: Custom Agents
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Agent based on any IChatClient
3+
description: Learn how to use the Microsoft Agent Framework with any IChatClient implementation.
4+
zone_pivot_groups: programming-languages
5+
author: westey-m
6+
ms.topic: tutorial
7+
ms.author: westey
8+
ms.date: 09/25/2025
9+
ms.service: semantic-kernel
10+
---
11+
12+
# Agent based on any IChatClient
13+
14+
::: zone pivot="programming-language-csharp"
15+
16+
The Microsoft Agent Framework supports creating agents for any inference service that provides a [`Microsoft.Extensions.AI.IChatClient`](/dotnet/ai/microsoft-extensions-ai#the-ichatclient-interface) implementation. This means that there is a very broad range of services that can be used to create agents, including open source models that can be run locally.
17+
18+
In this document, we will use Ollama as an example.
19+
20+
## Getting Started
21+
22+
Add the required NuGet packages to your project.
23+
24+
```powershell
25+
dotnet add package Microsoft.Extensions.AI.Agents
26+
```
27+
28+
You will also need to add the package for the specific `IChatClient` implementation you want to use. In this example, we will use [OllamaSharp](https://www.nuget.org/packages/OllamaSharp/).
29+
30+
```powershell
31+
dotnet add package OllamaSharp
32+
```
33+
34+
## Creating a ChatClientAgent
35+
36+
To create an agent based on the `IChatClient` interface, you can use the `ChatClientAgent` class.
37+
The `ChatClientAgent` class takes `IChatClient` as a constructor parameter.
38+
39+
First, create an `OllamaApiClient` to access the Ollama service.
40+
41+
```csharp
42+
using System;
43+
using Microsoft.Extensions.AI.Agents;
44+
using OllamaSharp;
45+
46+
using OllamaApiClient chatClient = new(new Uri("http://localhost:11434"), "phi3");
47+
```
48+
49+
The `OllamaApiClient` implements the `IChatClient` interface, so you can use it to create a `ChatClientAgent`.
50+
51+
```csharp
52+
AIAgent agent = new ChatClientAgent(
53+
chatClient,
54+
instructions: "You are good at telling jokes.",
55+
name: "Joker");
56+
```
57+
58+
> [!IMPORTANT]
59+
> To ensure that you get the most out of your agent, make sure to choose a service and model that is well-suited for conversational tasks and supports function calling.
60+
61+
::: zone-end
62+
::: zone pivot="programming-language-python"
63+
64+
Documentation coming soon.
65+
66+
::: zone-end
67+
68+
## Using the Agent
69+
70+
The agent is a standard `AIAgent` and supports all standard agent operations.
71+
72+
See the [Agent getting started tutorials](../../../tutorials/overview.md) for more information on how to run and interact with agents.

agent-framework/user-guide/agents/agent-types/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ See the documentation for each service, for more information:
5353
|[OpenAI ChatCompletion](./openai-chat-completion-agent.md)|An agent that uses the OpenAI ChatCompletion service.|No|Yes|
5454
|[OpenAI Responses](./openai-responses-agent.md)|An agent that uses the OpenAI Responses service.|Yes|Yes|
5555
|[OpenAI Assistants](./openai-assistants-agent.md)|An agent that uses the OpenAI Assistants service.|Yes|No|
56-
|Ollama|An agent that uses the Ollama service.|Yes|No|
57-
|Any other ChatClient|You can also use any other ChatClient implementation to create a ChatClientAgent.|Varies|Varies|
56+
|[Any other ChatClient](./chat-client-agent.md)|You can also use any other [`Microsoft.Extensions.AI.IChatClient`](/dotnet/ai/microsoft-extensions-ai#the-ichatclient-interface) implementation to create an agent.|Varies|Varies|
5857

5958
## Complex custom agents
6059

0 commit comments

Comments
 (0)