Skip to content

.NET: Route messages are not handled polymorphically #782

@stephentoub

Description

@stephentoub

Registration appears to require the exact message Type, as it's just looked up in a dictionary by that type. I expect that if I have a route handler for IEnumerable<T>, then anything that implements IEnumerable<T> should satisfy it, or if I have a handler for List<T>, List<T> or anything deriving from it should satisfy it, but that is not happening.

Repro:

    [Fact]
    public async Task ReproAsync()
    {
        var workflow = new WorkflowBuilder(new StartExecutor()).Build<IEnumerable<string>>();
        StreamingRun run = await InProcessExecution.StreamAsync<IEnumerable<string>>(workflow, ["Hello, World!"]);
        await run.RunToCompletionAsync();
    }

    private sealed class StartExecutor : Executor
    {
        protected override RouteBuilder ConfigureRoutes(RouteBuilder routeBuilder) =>
            routeBuilder.AddHandler<IEnumerable<string>>(async (msg, ctx) =>
            {
                Debugger.Break();
                Console.WriteLine("In StartExecutor");
                await ctx.SendMessageAsync(msg);
            });
    }

Result:

System.NotSupportedException : No handler found for message type <>z__ReadOnlySingleElementList`1 in executor StartExecutor.

Metadata

Metadata

Assignees

Labels

.NETv1.0Features being tracked for the version 1.0 GAworkflowsRelated to Workflows in agent-framework

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions