Skip to content

.NET : Agents in Workflow. WorkflowOutputEvent not triggered #2938

@lisngt

Description

@lisngt

Hi all,

I would like to orchestrate some agents like the following example

https://github.com/microsoft/agent-framework/blob/main/dotnet/samples/GettingStarted/Workflows/_Foundational/03_AgentsInWorkflows/Program.cs

I've rewritten the code so that it works with my local Ollama

using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;
using System.Net;

var openAIClient = new ChatClient(
    model: "qwen3:0.6b",
    credential: new ApiKeyCredential("your_api_key"),
    options: new OpenAIClientOptions()
    {
        Endpoint = new Uri("http://localhost:11434/v1/")
    }
);

var frenchAgent = openAIClient.CreateAIAgent($"You are a translation assistant that translates the provided text to french.");
var spanishAgent = openAIClient.CreateAIAgent($"You are a translation assistant that translates the provided text to spanish.");
var englishAgent = openAIClient.CreateAIAgent($"You are a translation assistant that translates the provided text to english.");

var french = await frenchAgent.RunAsync("Hello, how are you?");
Console.WriteLine(french);
var spanish = await spanishAgent.RunAsync(french.Text);
Console.WriteLine(spanish);
var english = await englishAgent.RunAsync(spanish.Text);
Console.WriteLine(english);


var workflow = new WorkflowBuilder(frenchAgent)
    .AddEdge(frenchAgent, spanishAgent)
    .AddEdge(spanishAgent, englishAgent)
    .Build();


await using var run = await InProcessExecution.StreamAsync(workflow, new Microsoft.Extensions.AI.ChatMessage(ChatRole.User, "Translate this message: Hello World!"));
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
await foreach (var evt in run.WatchStreamAsync())
{
    Console.WriteLine(evt.GetType().Name);

    if (evt is WorkflowOutputEvent woe)
    {     
        Console.WriteLine($"Final output:{woe.Data}");
        Console.WriteLine($"This code line can't never be reached");
    }
}

If I call the agent sequentially by myself (code block below), I receive an acceptable output

var french = await frenchAgent.RunAsync("Hello, how are you?");
Console.WriteLine(french);
var spanish = await spanishAgent.RunAsync(french.Text);
Console.WriteLine(spanish);
var english = await englishAgent.RunAsync(spanish.Text);
Console.WriteLine(english);
Image

However I don't get any event of WorkflowOutputEvent with the workflow so that I can get the final result of the workflow.

I'm not sure if I have made any error here. Any help would be appreciated.

Thank you.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions