Skip to content

[BUG] PersistentAgentsClient.Messages.CreateMessageAsync fails with InvalidCastException #52571

@crickman

Description

@crickman

Library name and version

Azure.AI.Agents.Persistent 1.2.0-beta.4

Describe the bug

PersistentAgentsClient.Messages.CreateMessageAsync fails when providing an enumeration of MessageInputContentBlock.

Can be easily reproduced with an existing unit-test: Sample_PersistentAgents_ImageFileInputs.ImageFileInMessageExampleAsync

Is this test not running in your pipeline?

Expected behavior

Creates a message

Actual behavior

Throws exception due to a failed serialization

System.InvalidCastException: 
   at System.Text.Json.JsonSerializer.UnboxOnWrite[T](Object value)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue)
   at System.Text.Json.JsonSerializer.WriteStringAsObject(Object value, JsonTypeInfo jsonTypeInfo)
   at Azure.AI.Agents.Persistent.ThreadMessages.CreateMessageAsync(String threadId, MessageRole role, IEnumerable`1 contentBlocks, IEnumerable`1 attachments, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)

Reproduction Steps

Run your unit-test: Sample_PersistentAgents_ImageFileInputs.ImageFileInMessageExampleAsync

Environment

.NET 9.0

Metadata

Metadata

Assignees

Labels

AI AgentsClientThis issue is related to a non-management packageService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions