Add user identity pattern to dotnet/agent-framework sample#233
Merged
sellakumaran merged 10 commits intomainfrom Mar 6, 2026
Merged
Add user identity pattern to dotnet/agent-framework sample#233sellakumaran merged 10 commits intomainfrom
sellakumaran merged 10 commits intomainfrom
Conversation
Demonstrates how A365 agents identify the user they are talking to: - Log Activity.From (Id, Name, AadObjectId) at the start of each turn - CurrentUserTool exposes GetCurrentUser() (activity payload, no API call) and GetCurrentUserExtendedProfileAsync() (Microsoft Graph /me) as LLM-callable tools - Inject user's display name into agent instructions for personalized responses - README section explains both patterns and token requirements for Graph calls Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a “user identity” pattern to the .NET Agent Framework sample, showing how to identify the current user from the activity payload and (optionally) enrich that identity via Microsoft Graph, plus using the user’s name for more personalized agent behavior.
Changes:
- Introduces
CurrentUserToolexposing LLM-callable functions for basic identity (Activity.From) and extended profile (GET /mevia Graph). - Logs
Activity.Fromidentity fields at the start of each turn and injects the user display name into agent instructions/welcome message. - Documents both identity patterns and token requirements in the sample README.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| dotnet/agent-framework/sample-agent/Tools/CurrentUserTool.cs | Adds new tool for retrieving basic identity and (optionally) Graph /me profile. |
| dotnet/agent-framework/sample-agent/Agent/MyAgent.cs | Logs user identity each turn, registers the new tool, and personalizes instructions/welcome text using user display name. |
| dotnet/agent-framework/sample-agent/README.md | Documents basic identity vs. Graph-based extended profile and token requirements. |
You can also share your feedback on Copilot code review. Take the survey.
Activity.From.Name is not reliably populated in the MembersAdded event in Teams/A365 flows. The user name is injected into the LLM instructions on the first message turn instead, where Activity.From.Name is always set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove CurrentUserTool (LLM-callable tools + Graph /me) in favour of the minimal pattern used consistently across all samples: log Activity.From fields at message handler entry, inject display name into LLM instructions. - Delete Tools/CurrentUserTool.cs - MyAgent.cs: remove CurrentUserTool registrations and Graph instruction line - README.md: simplify "Working with User Identity" to activity-payload pattern only - Add docs/user-identity-rollout-plan.md with cross-repo rollout plan Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ernel and all Python samples Log Activity.From fields (Id, Name, AadObjectId) at message handler entry and inject the user's display name into LLM system instructions for personalized responses. Adds the standard 'Working with User Identity' README section to each sample. Samples updated: dotnet/semantic-kernel, python/agent-framework, python/claude, python/crewai, python/openai, python/google-adk. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Log activity.from fields (id, name, aadObjectId) at message handler entry and inject the user's display name into LLM system instructions for personalized responses. Adds the standard 'Working with User Identity' README section to each sample. Samples updated: nodejs/openai, nodejs/claude, nodejs/langchain, nodejs/vercel-sdk, nodejs/perplexity, nodejs/copilot-studio, nodejs/devin, nodejs/n8n (README only). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Document the Activity.From pattern — log Id/Name/AadObjectId at message handler entry and inject display name into LLM system instructions. Adds language-specific code snippets to dotnet, python, and nodejs design guides, and a cross-language summary table to the top-level design doc. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Updated the section heading from "7. Observability Integration" to "8. Observability Integration" to reflect changes in document structure. No other content was modified.
… dead code - Downgrade user identity log from LogInformation to LogDebug in MyAgent.cs (DisplayName, UserId, AadObjectId are PII and should not appear in production logs) - Sanitize Activity.From.Name before injecting into system prompt (strip control chars, enforce 64-char max) to prevent prompt injection via display name - Remove stale `pass` + dead comment at end of __init__ in python/openai agent.py - Remove commented-out try/except block from _enable_agentframework_instrumentation in python/agent-framework agent.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gwharris7
requested changes
Mar 5, 2026
- Delete docs/user-identity-rollout-plan.md - Add missing copyright headers to nodejs/langchain and nodejs/vercel-sdk - Fix self.AGENT_PROMPT instance mutation in python/agent-framework — use local variable, pass via setup_mcp_servers instructions parameter - Fix self.instruction/self.agent instance mutation in python/google-adk — use local variables, update _initialize_agent to accept agent parameter Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gwharris7
approved these changes
Mar 6, 2026
gwharris7
requested changes
Mar 6, 2026
Fix race condition in python/openai — use dataclasses.replace to create a per-turn agent clone with personalized instructions instead of mutating self.agent.instructions directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gwharris7
approved these changes
Mar 6, 2026
ajmfehr
approved these changes
Mar 6, 2026
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.
Demonstrates how A365 agents identify the user they are talking to: