microsoft / microsoft/agent-framework

.NET: How can I provide a CustomMessageStore to a WorkflowAgent?

Open
#1,573 1 comment 0 reactions 2 assignees View on GitHub

@peibekwe is already working on this.

Since Jun 26, 2026.

.NET memory
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

I have a workflow that I want to use as an agent:

```csharp
builder.AddAIAgent("group-chat", (sp, key) =>
{
var documentAgent = sp.GetRequiredKeyedService("document-management-agent");
var financialAgent = sp.GetRequiredKeyedService("financial-analysis-agent");

Workflow workflow =
AgentWorkflowBuilder
.CreateGroupChatBuilderWith(agents =>
new RoundRobinGroupChatManager(agents)
{
MaximumIterationCount = 2
})
.AddParticipants(documentAgent, financialAgent)
.Build();

return workflow.AsAgentAsync(name: key).GetAwaiter().GetResult();
});
```

Since this agent is hosted in an API, I want to handle its conversation history in a CustomMessageStore (e.g. CosmosDB). I didn't find a way to provide the CustomMessageStore as I do with a ChatClientAgent:

```csharp
ChatClientAgentOptions options = new ()
{
Id = Guid.NewGuid().ToString(),
Name = "myagent",
Instructions = @"A friendly AI assistant"
Description = "A friendly AI assistant",
ChatOptions = new ChatOptions
{
Tools = [.. documentTools],
},

ChatMessageStoreFactory = ctx =>
{
// Create a new chat message store for this agent that stores the messages in a cosmos store.
return new CustomMessageStore(
sp.GetRequiredService(),
ctx.SerializedState,
ctx.JsonSerializerOptions
);
}
};

var agent = new ChatClientAgent(instrumentedChatClient, options);
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.