Skip to content

Add agent lifecycle event handlers#599

Open
heyitsaamir wants to merge 2 commits into
mainfrom
heyitsaamir-agent-lifecycle-events
Open

Add agent lifecycle event handlers#599
heyitsaamir wants to merge 2 commits into
mainfrom
heyitsaamir-agent-lifecycle-events

Conversation

@heyitsaamir

Copy link
Copy Markdown
Collaborator

Summary

  • Add typed Agent 365 agentLifecycle event activity/value models with valueType discrimination for all lifecycle variants.
  • Add EventNames.AgentLifecycle, lifecycle valueType/eventType constants, and strongly typed handler registration extensions including OnAgentLifecycle and per-variant handlers.
  • Preserve generic OnEvent compatibility and keep Teams activity metadata when deriving typed event contexts.

Validation

  • dotnet test core/test/Microsoft.Teams.Apps.UnitTests/Microsoft.Teams.Apps.UnitTests.csproj
  • dotnet build core/src/Microsoft.Teams.Apps/Microsoft.Teams.Apps.csproj --no-restore

Add Agent 365 agentLifecycle event activity models, typed value payloads, and handler registration extensions for all lifecycle variants.

Cover valueType discrimination, event serialization, generic event compatibility, and typed handler dispatch in Apps unit tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 00:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support for Agent 365 agentLifecycle events by introducing typed activity/value models with valueType discrimination and strongly-typed handler registration APIs, while preserving compatibility with the generic OnEvent pipeline.

Changes:

  • Introduces AgentLifecycleEventActivity + per-variant activity/value models and constants for lifecycle valueType / eventType.
  • Adds lifecycle-specific handler registration extensions (OnAgentLifecycle and per-variant handlers) implemented as router routes over EventActivity.
  • Updates event parsing/serialization to support lifecycle discrimination (EventNames.AgentLifecycle, EventActivity.ValueType, and lifecycle-aware EventActivity.FromActivity) and adds unit tests validating dispatch and JSON shape.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
core/test/Microsoft.Teams.Apps.UnitTests/AgentLifecycleHandlerTests.cs Adds unit tests for lifecycle variant discrimination, dispatch to generic/typed handlers, and JSON envelope preservation.
core/src/Microsoft.Teams.Apps/Schema/TeamsActivity.cs Adjusts TeamsActivity construction/copy behavior to preserve Teams-specific metadata when deriving typed contexts.
core/src/Microsoft.Teams.Apps/Handlers/EventHandler.Activity.cs Adds valueType support, lifecycle-aware event discrimination in FromActivity, and event JSON serialization behavior.
core/src/Microsoft.Teams.Apps/Handlers/AgentLifecycleHandler.Activity.cs Adds typed lifecycle event activity hierarchy and lifecycle valueType / eventType constants.
core/src/Microsoft.Teams.Apps/Handlers/AgentLifecycleHandler.Values.cs Adds typed lifecycle payload (value) models for each lifecycle variant.
core/src/Microsoft.Teams.Apps/Handlers/AgentLifecycleHandler.cs Adds OnAgentLifecycle and per-variant handler registration extensions built on router routes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +85
else
{
ChannelData = Properties.Extract<TeamsChannelData>("channelData");
Entities = Properties.Extract<EntityList>("entities");
}
Remove broad TeamsActivity metadata copy behavior and keep lifecycle tests focused on routing, valueType discrimination, and payload binding.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
public JsonNode? Value { get; set; }

/// <inheritdoc/>
public override string ToJson() => CoreActivity.ToJson(this);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this ? Will we ever send these activities ?

return app.RegisterAgentLifecycleRoute(
EventNames.AgentLifecycle,
valueType: null,
AgentLifecycleEventActivity.FromEventActivity,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, I think this should be AgentLifecycleEventActivity

/// Gets or sets the value payload type for event activities that carry typed variants.
/// </summary>
[JsonPropertyName("valueType")]
public string? ValueType { get; set; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of AgentLifecycleEventActivity ?

return new EventActivity(activity);
EventActivity eventActivity = new(activity);
return eventActivity.Name == EventNames.AgentLifecycle
? AgentLifecycleEventActivity.FromEventActivity(eventActivity)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid this ? for on event handler we always receive event activity

/// <summary>
/// Fired when an agentic user identity is created.
/// </summary>
public class AgenticUserIdentityCreatedActivity : AgentLifecycleEventActivity<AgenticUserIdentityCreatedValue>

@MehakBindra MehakBindra Jul 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to define all these classes ? All we need is AgentLifecycleEventActivity right ? along with values already defined

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants