microsoft / microsoft/agent-framework
.NET: More modular or structured way to define multi-agent workflows
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 2.3k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 358
Description
In the knights and knaves sample, multiple agents are instantiated and composed directly inside the lambda passed to `AddAIAgent`.
While it works fine for small demos, this approach becomes difficult to maintain and reason about when dealing with more complex setups.
## Example from the documentation:
```csharp
builder.AddAIAgent("knights-and-knaves", (sp, key) =>
{
var chatClient = sp.GetRequiredKeyedService("chat-model");
ChatClientAgent knight = new(chatClient, "...", "Alice");
ChatClientAgent knave = new(chatClient, "...", "Bob");
ChatClientAgent narrator = new(chatClient, "...", "Narrator");
// TODO: How to avoid sync-over-async here?
return AgentWorkflowBuilder
.BuildConcurrent([knight, knave, narrator])
.AsAgentAsync(name: key)
.AsTask()
.GetAwaiter()
.GetResult();
});
```
## Problem
* The lambda becomes cluttered as the number of agents grows.
* It mixes dependency resolution, agent construction, and workflow composition logic.
* It’s hard to reuse or organize agent definitions in larger projects.
* There’s already a TODO comment in the sample about avoiding sync-over-async — which suggests this pattern isn’t ideal for production use.
Contributor guide
Assessment
This issue has not been assessed yet.