microsoft / microsoft/agent-framework

.NET: Workflow AsAgent extension restricted to `List<ChatMessage>` return type

Open
#879 2 comments 0 reactions 1 assignee Assigned to @peibekwe View on GitHub
.NET question workflows
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

AIAgent RunAsync methods return either an `AgentRunResponse` or `ValueTask` when using extension methods.

https://github.com/microsoft/agent-framework/blob/0f913bcdeb8dae0abf88dce806ece5228ce33dcb/dotnet/src/Microsoft.Extensions.AI.Agents.Abstractions/AIAgent.cs#L124

https://github.com/microsoft/agent-framework/blob/0f913bcdeb8dae0abf88dce806ece5228ce33dcb/dotnet/src/Microsoft.Agents.Orchestration/AIAgentExtensions.cs#L31

However, the existing Workflow extensions restrict workflows to `Workflow>`

Workflows support `Workflow`. When invoked as agents, they should support `AgentRunResponse` or `ValueTask` just like agents do as a return type.

For example, this code doesn't compile and displays the following error.

```text
'Workflow' does not contain a definition for 'AsAgent' and the best extension method overload 'WorkflowHostingExtensions.AsAgent(Workflow>, string?, string?)' requires a receiver of type 'Microsoft.Agents.Workflows.Workflow>'
```

```csharp
IChatClient chatClient =
new AzureOpenAIClient(
endpoint: new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")),
credential: new DefaultAzureCredential())
.GetChatClient("gpt-4o-mini")
.AsIChatClient();

AIAgent writer = new ChatClientAgent(
chatClient,
new ChatClientAgentOptions
{
Name = "Writer",
Description = "An agent that writes a short story based on a prompt.",
Instructions = "Write stories that are engaging and creative."
});

AIAgent editor = new ChatClientAgent(
chatClient,
new ChatClientAgentOptions
{
Name = "Editor",
Description = "An agent that edits and improves a short story.",
Instructions = "Make the story more engaging, fix grammar, and enhance the plot."
});

Workflow workflow =
new WorkflowBuilder(writer)
.AddEdge(writer, editor)
.Build();

AgentRunResponse workflowResponse = await
workflow
.AsAgent()
.RunAsync("Write a short story about a haunted house.");
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.