Skip to content

Add fluent builder helpers to Core.Models (ease-of-use)#932

Draft
tracyboehrer wants to merge 1 commit into
mainfrom
users/tracyboehrer/model-ease
Draft

Add fluent builder helpers to Core.Models (ease-of-use)#932
tracyboehrer wants to merge 1 commit into
mainfrom
users/tracyboehrer/model-ease

Conversation

@tracyboehrer

@tracyboehrer tracyboehrer commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

Adds non-breaking, purely additive fluent/builder helpers to Microsoft.Agents.Core.Models, closing an ergonomics gap identified by comparing the SDK models against microsoft/teams.net (Microsoft.Teams.Api). The Agents SDK models are structurally equivalent, but teams.net offers a fluent, chainable builder style that the Agents SDK lacked. Every addition here is a new method/overload — no signature, type, or serialization changes, so nothing breaks for existing consumers.

What's added

ActivityBuilderExtensions.cs (new) — chainable extensions on IActivity (compose nicely with the existing Activity.Create* factories):

  • Setters: WithText, WithSpeak, WithInputHint, WithSummary, WithLocale, WithTextFormat, WithAttachmentLayout, WithDeliveryMode, WithName, WithValue, WithSuggestedActions
  • Adders: AddText (append), AddAttachment(params Attachment[]), plus overloads that auto-wrap HeroCard/ThumbnailCard/AnimationCard/AudioCard/VideoCard/ReceiptCard/OAuthCard/SigninCard
  • AddEntity, AddMention(account, text, addText) — injects <at> markup + a Mention entity
  • Type checks: IsMessage, IsEvent, IsInvoke, IsTyping, IsConversationUpdate, IsEndOfConversation, IsHandoff, IsTrace, IsCommand, IsCommandResult

IActivityExtensions.csGetAccountMention(id) and IsRecipientMentioned() (parity with teams.net mention query helpers; complements the existing GetMentions()).

SuggestedActions.cs — fluent AddAction, AddActions, AddRecipients (return this).

CardBuilderExtensions.cs (new) — fluent builders across HeroCard, ThumbnailCard, BasicCard, AnimationCard, AudioCard, VideoCard, MediaCard, ReceiptCard: WithTitle/WithSubtitle/WithText/WithTap, AddImage, AddMedia, AddButton/AddButtons, and receipt-specific WithTotal/WithTax/AddFact/AddItem. Backing collections are created on demand, so these are safe on default-constructed cards.

Examples

Building a message with a card and a mention in one expression:

var activity = Activity.CreateMessageActivity()
    .WithText("Here''s your summary")
    .WithSummary("Weekly report")
    .AddMention(user)
    .AddAttachment(new HeroCard()
        .WithTitle("Weekly Report")
        .WithSubtitle("2026-07-17")
        .AddImage("https://contoso/report.png", "chart")
        .AddButton("Open", type: ActionTypes.OpenUrl, value: "https://contoso/report")
        .AddButton("Dismiss", value: "dismiss"));

Suggested actions, fluently:

var activity = Activity.CreateMessageActivity()
    .WithText("Pick one:")
    .WithSuggestedActions(new SuggestedActions()
        .AddRecipients("user1")
        .AddAction(new CardAction(type: ActionTypes.ImBack, title: "Yes", value: "yes"))
        .AddActions(
            new CardAction(type: ActionTypes.ImBack, title: "No", value: "no"),
            new CardAction(type: ActionTypes.ImBack, title: "Maybe", value: "maybe")));

Mention queries:

if (activity.IsRecipientMentioned())
{
    var mention = activity.GetAccountMention(activity.Recipient.Id);
    // ...
}

Type checks:

if (activity.IsMessage()) { /* ... */ }

Notes / scope

  • I intentionally did not add ToAttachment() to MediaCard/BasicCard: those two types have no defined content-type constant in ContentTypes, so a standard attachment can''t be produced. They received fluent builders instead.
  • These are extension methods on IActivity (rather than interface members) specifically to avoid a breaking change to interface implementers.

Adds non-breaking, additive fluent/builder extensions to Microsoft.Agents.Core.Models,
inspired by the ergonomic API style of microsoft/teams.net (Microsoft.Teams.Api).

- ActivityBuilderExtensions: chainable With*/Add* methods on IActivity, card
  AddAttachment overloads, AddMention, AddEntity, and Is<Type>() helpers.
- IActivityExtensions: GetAccountMention(id) and IsRecipientMentioned().
- SuggestedActions: fluent AddAction/AddActions/AddRecipients.
- CardBuilderExtensions: fluent builders for Hero/Thumbnail/Basic/Animation/Audio/
  Video/Media/Receipt cards (With*/AddImage/AddMedia/AddButton, etc.).
- Tests covering all new helpers (net8.0 + net4.8).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a5b5eb02-9d4a-426c-9c0a-8c5699675860
@github-actions github-actions Bot added ML: Core Tags changes to core libraries ML: Tests Tags changes to tests labels Jul 17, 2026
@tracyboehrer tracyboehrer changed the title Add fluent builder helpers to Core.Models (teams.net-inspired ease-of-use) Add fluent builder helpers to Core.Models (ease-of-use) Jul 17, 2026
@MattB-msft

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ML: Core Tags changes to core libraries ML: Tests Tags changes to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants