Skip to content

Add user identity pattern to dotnet/agent-framework sample#233

Merged
sellakumaran merged 10 commits intomainfrom
users/sellak/user-identity
Mar 6, 2026
Merged

Add user identity pattern to dotnet/agent-framework sample#233
sellakumaran merged 10 commits intomainfrom
users/sellak/user-identity

Conversation

@sellakumaran
Copy link
Contributor

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

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>
Copilot AI review requested due to automatic review settings March 4, 2026 00:31
@sellakumaran sellakumaran requested a review from a team as a code owner March 4, 2026 00:31
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 CurrentUserTool exposing LLM-callable functions for basic identity (Activity.From) and extended profile (GET /me via Graph).
  • Logs Activity.From identity 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.

sellakumaran and others added 5 commits March 3, 2026 16:46
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>
sellakumaran and others added 2 commits March 4, 2026 11:01
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>
- 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>
@sellakumaran sellakumaran enabled auto-merge (squash) March 5, 2026 23:28
@gwharris7 gwharris7 self-requested a review March 6, 2026 00:29
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>
@sellakumaran sellakumaran merged commit 08338c4 into main Mar 6, 2026
34 of 40 checks passed
@sellakumaran sellakumaran deleted the users/sellak/user-identity branch March 6, 2026 01:40
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.

4 participants