Skip to content

.NET: More modular or structured way to define multi-agent workflows #1414

@rosieks

Description

@rosieks

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:

builder.AddAIAgent("knights-and-knaves", (sp, key) =>
{
    var chatClient = sp.GetRequiredKeyedService<IChatClient>("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.

Metadata

Metadata

Assignees

Labels

.NETworkflowsRelated to Workflows in agent-framework

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions