Skip to content

Add Agent 365 agentLifecycle event support#492

Open
heyitsaamir wants to merge 3 commits into
feature_agent365_supportfrom
heyitsaamir-agent-lifecycle-events
Open

Add Agent 365 agentLifecycle event support#492
heyitsaamir wants to merge 3 commits into
feature_agent365_supportfrom
heyitsaamir-agent-lifecycle-events

Conversation

@heyitsaamir

@heyitsaamir heyitsaamir commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add typed Agent 365 agentLifecycle event activity models and value payloads for the observed lifecycle variants.
  • Wire agentLifecycle into EventActivity parsing via nested discriminators (name then valueType).
  • Add app routing/handler registration for on_agent_lifecycle and per-variant on_agentic_user_* handlers.
  • Add lifecycle logging handlers to examples/agent365 as a runnable validation/reference harness.
  • Sync uv.lock so the existing examples/formatted-messaging workspace member is represented in the lockfile.
  • Add API parsing tests and app route-selector tests.

Manual validation

Validated against live Agent 365 lifecycle traffic using examples/agent365 on port 4000 with handlers registered for both the general lifecycle event and each variant-specific lifecycle event.

Scenario Event / valueType Result
Create agentic user AgenticUserIdentityCreated General + variant handlers fired; creation manager shape included userId, email, and displayName.
Identity property update AgenticUserIdentityUpdated Observed Mail, Alias, and UserPrincipalName updates with versions.
Enable agentic user AgenticUserEnabled Observed after unblocking the agentic user.
Disable agentic user AgenticUserDisabled Observed after blocking the agentic user.
Primary manager change AgenticUserManagerUpdated Observed after updating the primary Entra manager via Graph; manager payload shape was manager.managerId.
Teams workload onboarding AgenticUserWorkloadOnboardingUpdated Observed with workloadName=Teams and workloadOnboardingState=succeeded.
Soft delete AgenticUserDeleted Observed after Graph soft delete.
Restore from deleted items AgenticUserUndeleted Observed after Graph restore.
Hard delete AgenticUserDeleted Observed after permanent delete.

Additional live-test findings:

  • Lifecycle activities arrived as type="event", name="agentLifecycle", channelId="agents", and from.id="system".
  • Activity-level valueType matched the concrete lifecycle variant and value.eventType matched the lower-camel event name.
  • General lifecycle handlers must call await ctx.next() for variant-specific handlers to run afterward.
  • Both soft delete and hard delete emitted AgenticUserDeleted; live payloads did not include a populated deletion reason, so the model keeps it optional.
  • Additional managers/sponsors did not trigger AgenticUserManagerUpdated; updating the primary Entra manager did.
  • Normal message handling still worked while lifecycle handlers were registered; incoming message POST returned 200 OK and Bot API reply returned 201 Created.

Validation

  • ruff check
  • pyright
  • pytest packages

heyitsaamir and others added 2 commits June 30, 2026 18:03
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>
@heyitsaamir heyitsaamir marked this pull request as ready for review July 2, 2026 00:24
@heyitsaamir heyitsaamir requested review from corinagum and lilyydu July 2, 2026 00:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant