Add Agent 365 agentLifecycle event support#492
Merged
heyitsaamir merged 5 commits intoJul 9, 2026
Conversation
Model and route Agent 365 "agentLifecycle" event activities, which arrive as event activities (name="agentLifecycle") from the System user on the "agents" channel. The activity-level valueType names the variant and value carries the typed payload. - Add Pydantic models for the 8 agentLifecycle payloads, discriminated by eventType, with an unknown fallback (mirrors the Entity discriminator). - Add one typed activity class per variant plus an AgentLifecycleEventActivity union. - Switch EventActivity from a name-based discriminator to a callable Discriminator so agentLifecycle variants discriminate on valueType while meeting/read-receipt events still discriminate on name. - Add routing configs and regenerate handlers to expose on_agent_lifecycle plus per-variant on_agentic_user_* registration methods. - Add API parsing tests and apps route-selector tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lilyydu
approved these changes
Jul 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class Agent 365 agentLifecycle support across the SDK: typed event activities/value payloads, nested discriminator parsing (name → valueType), app routing/handler registration, and runnable example logging—plus corresponding unit tests and lockfile sync for an existing example workspace member.
Changes:
- Introduces
agentLifecycleevent activity/value models and exports them through the API activity unions. - Adds Apps routing selectors + generated handler registration methods for
on_agent_lifecycleand per-varianton_agentic_user_*handlers, with route-selector tests. - Updates
examples/agent365to log lifecycle traffic for live validation; updatesuv.lockto includeexamples/formatted-messaging.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Adds formatted-messaging workspace member package metadata to the lockfile. |
| packages/apps/tests/test_agent_lifecycle_routes.py | New tests asserting general + per-variant route selectors behave correctly. |
| packages/apps/src/microsoft_teams/apps/routing/generated_handlers.py | Adds handler registration methods and type imports for lifecycle events. |
| packages/apps/src/microsoft_teams/apps/routing/activity_route_configs.py | Adds lifecycle route configs and selectors (agentLifecycle + per-valueType variants). |
| packages/api/tests/unit/test_agent_lifecycle_event.py | New parsing/serialization unit tests for lifecycle event variants. |
| packages/api/src/microsoft_teams/api/activities/event/agent_lifecycle/value.py | Adds typed value payload models for observed lifecycle variants. |
| packages/api/src/microsoft_teams/api/activities/event/agent_lifecycle/activity.py | Adds typed activity models + valueType-discriminated union. |
| packages/api/src/microsoft_teams/api/activities/event/agent_lifecycle/init.py | Exports lifecycle activities/values from the new module. |
| packages/api/src/microsoft_teams/api/activities/event/init.py | Wires lifecycle into EventActivity parsing via name discriminator and exports symbols. |
| examples/agent365/src/main.py | Adds lifecycle handlers and logging as a runnable validation harness. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
agentLifecycleevent activity models and value payloads for the observed lifecycle variants.agentLifecycleintoEventActivityparsing via nested discriminators (namethenvalueType).on_agent_lifecycleand per-varianton_agentic_user_*handlers.examples/agent365as a runnable validation/reference harness.uv.lockso the existingexamples/formatted-messagingworkspace member is represented in the lockfile.Manual validation
Validated against live Agent 365 lifecycle traffic using
examples/agent365on port 4000 with handlers registered for both the general lifecycle event and each variant-specific lifecycle event.AgenticUserIdentityCreateduserId,email, anddisplayName.AgenticUserIdentityUpdatedMail,Alias, andUserPrincipalNameupdates with versions.AgenticUserEnabledAgenticUserDisabledAgenticUserManagerUpdatedmanager.managerId.AgenticUserWorkloadOnboardingUpdatedworkloadName=TeamsandworkloadOnboardingState=succeeded.AgenticUserDeletedAgenticUserUndeletedAgenticUserDeletedAdditional live-test findings:
type="event",name="agentLifecycle",channelId="agents", andfrom.id="system".valueTypematched the concrete lifecycle variant andvalue.eventTypematched the lower-camel event name.await ctx.next()for variant-specific handlers to run afterward.AgenticUserDeleted; live payloads did not include a populated deletion reason, so the model keeps it optional.AgenticUserManagerUpdated; updating the primary Entra manager did.200 OKand Bot API reply returned201 Created.Validation
ruff checkpyrightpytest packages