Skip to content

AsChatMessages doesn't preserve role #6997

@ProTip

Description

@ProTip

Description

AsChatMessages in MicrosoftExtensionsAIChatExtensions converts from OpenAI messages to ext messages.

This is used in AIAgentWithOpenAIExtensions to accept OpenAI messages and return OpenAI updates.

Unfortunately the code does not map the role across, so all messages end up as User role. This results in a predictably misbehaving agent that does not respect my authoritah! 😆

Reproduction Steps

In LinqPad

using Microsoft.Extensions.AI;
using OpenAI.Chat;


List<OpenAI.Chat.ChatMessage> msgs = [new SystemChatMessage("Foo")];

msgs.AsChatMessages().ToList().ForEach(m => m.Role.Dump());

The resulting role will be user.

Expected behavior

The role should be system.

Actual behavior

The resulting role will be user.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

area-aiMicrosoft.Extensions.AI librariesbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions