<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam" -->

---
title: Microsoft Agent Framework for .NET (part 3): Custom...
description: A tutorial walks through building custom AI agents with Microsoft Agent Framework for .NET, focusing on the ChatClientAgent class. It covers giving an agent a...
canonical: https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Microsoft Agent Framework for .NET (part 3): Custom Agents, for building a chat with custom instructions | daily.dev
og:description: A tutorial walks through building custom AI agents with Microsoft Agent Framework for .NET, focusing on the ChatClientAgent class. It covers giving an agent a...
og:url: https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam
og:image: https://api.daily.dev/og/posts/DEhVvDeaM.png
og:image:alt: Microsoft Agent Framework for .NET (part 3): Custom Agents, for building a chat with custom instructions
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft Agent Framework for .NET (part 3): Custom Agents, for building a chat with custom instructions

**[Code4IT](https://daily.dev/sources/code4it)** · 19 min read · 0 upvotes · 0 comments

## Summary

A tutorial walks through building custom AI agents with Microsoft Agent Framework for .NET, focusing on the ChatClientAgent class. It covers giving an agent a name and system prompt via custom instructions, inspecting the AgentResponse class, using Sessions to maintain multi-turn conversation context, serializing/deserializing sessions, and best practices for writing effective prompts (defining role, domain, expected input, constraints, output shape, and honesty rules). It also shows how to iteratively refine a prompt and test it with realistic, messy user inputs using a board-game recommendation agent example.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/maf-first-agent-custom-instructions>

## Questions this post answers

### How do I maintain conversation context across multiple turns with Microsoft Agent Framework's ChatClientAgent?

Use an AgentSession created via agent.CreateSessionAsync(), then pass it into agent.RunAsync(question, session) on each call. The RunAsync method is stateless by default and forgets prior messages, so without a session the agent will re-ask for information like player count that was already provided. Sessions can also be serialized with SerializeSessionAsync and restored later with DeserializeSessionAsync.

_daily.dev surfaces practical framework walkthroughs like this for developers wiring up stateful agent conversations._

### What should a good system prompt for a Microsoft Agent Framework ChatClientAgent include?

It should define the agent's role, its domain, the expected user input, output constraints, and an uncertainty policy. For example, a board game recommender agent benefits from instructions limiting it to 3 recommendations, requiring it to ask a follow-up question when data is missing, specifying that each recommendation include player count, complexity, and play time, and telling it to admit uncertainty about editions or rules rather than guessing.

_developers refining agent instructions can track prompt engineering patterns like these on daily.dev._

## Similar posts on daily.dev

- [Upgrading to Microsoft Agent Framework in Your .NET AI Chat App](https://daily.dev/posts/upgrading-to-microsoft-agent-framework-in-your-net-ai-chat-app-y6eiwakpg) · ASP.NET Blog · 7 upvotes · 0 comments
- [Microsoft Agent Framework \(Preview\): AI Agent Development for .NET](https://daily.dev/posts/microsoft-agent-framework-preview-ai-agent-development-for-net-uwehk5y4a) · Syncfusion · 2 upvotes · 0 comments
- [Microsoft Agent Framework - powering up your agentic teammate](https://daily.dev/posts/microsoft-agent-framework---powering-up-your-agentic-teammate-qaldzp5bp) · Scott Logic · 2 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#), [#prompt-engineering](https://daily.dev/tags/prompt-engineering)

[View this post on daily.dev](https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Microsoft Agent Framework for .NET (part 3): Custom Agents, for building a chat with custom instructions","url":"https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam"},"datePublished":"2026-10-04T13:06:40.392Z","dateModified":"2026-10-04T13:11:00.588Z","description":"A tutorial walks through building custom AI agents with Microsoft Agent Framework for .NET, focusing on the ChatClientAgent class. It covers giving an agent a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bc7ee4125c700860e927c8aecb06a795?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bc7ee4125c700860e927c8aecb06a795?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,.net,c#,prompt-engineering","timeRequired":"PT19M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"Microsoft Agent Framework for .NET (part 3): Custom Agents, for building a chat with custom instructions"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/microsoft-agent-framework-for-net-part-3-custom-agents-for-building-a-chat-with-custom-instruct-dehvvdeam#faq","mainEntity":[{"@type":"Question","name":"How do I maintain conversation context across multiple turns with Microsoft Agent Framework's ChatClientAgent?","acceptedAnswer":{"@type":"Answer","text":"Use an AgentSession created via agent.CreateSessionAsync(), then pass it into agent.RunAsync(question, session) on each call. The RunAsync method is stateless by default and forgets prior messages, so without a session the agent will re-ask for information like player count that was already provided. Sessions can also be serialized with SerializeSessionAsync and restored later with DeserializeSessionAsync. daily.dev surfaces practical framework walkthroughs like this for developers wiring up stateful agent conversations."}},{"@type":"Question","name":"What should a good system prompt for a Microsoft Agent Framework ChatClientAgent include?","acceptedAnswer":{"@type":"Answer","text":"It should define the agent's role, its domain, the expected user input, output constraints, and an uncertainty policy. For example, a board game recommender agent benefits from instructions limiting it to 3 recommendations, requiring it to ask a follow-up question when data is missing, specifying that each recommendation include player count, complexity, and play time, and telling it to admit uncertainty about editions or rules rather than guessing. developers refining agent instructions can track prompt engineering patterns like these on daily.dev."}}]}
```

