Add agent lifecycle event handlers#599
Conversation
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>
There was a problem hiding this comment.
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 lifecyclevalueType/eventType. - Adds lifecycle-specific handler registration extensions (
OnAgentLifecycleand per-variant handlers) implemented as router routes overEventActivity. - Updates event parsing/serialization to support lifecycle discrimination (
EventNames.AgentLifecycle,EventActivity.ValueType, and lifecycle-awareEventActivity.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.
| 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); |
There was a problem hiding this comment.
why do we need this ? Will we ever send these activities ?
| return app.RegisterAgentLifecycleRoute( | ||
| EventNames.AgentLifecycle, | ||
| valueType: null, | ||
| AgentLifecycleEventActivity.FromEventActivity, |
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
Should this be part of AgentLifecycleEventActivity ?
| return new EventActivity(activity); | ||
| EventActivity eventActivity = new(activity); | ||
| return eventActivity.Name == EventNames.AgentLifecycle | ||
| ? AgentLifecycleEventActivity.FromEventActivity(eventActivity) |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Do we need to define all these classes ? All we need is AgentLifecycleEventActivity right ? along with values already defined
Summary
agentLifecycleevent activity/value models withvalueTypediscrimination for all lifecycle variants.EventNames.AgentLifecycle, lifecyclevalueType/eventTypeconstants, and strongly typed handler registration extensions includingOnAgentLifecycleand per-variant handlers.OnEventcompatibility and keep Teams activity metadata when deriving typed event contexts.Validation
dotnet test core/test/Microsoft.Teams.Apps.UnitTests/Microsoft.Teams.Apps.UnitTests.csprojdotnet build core/src/Microsoft.Teams.Apps/Microsoft.Teams.Apps.csproj --no-restore