microsoft / microsoft/agent-framework
.NET: How can I provide a CustomMessageStore to a WorkflowAgent?
@peibekwe is already working on this.
Since Jun 26, 2026.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.