Uh oh!
There was an error while loading. Please reload this page.
.NET: Adding AgentRunContext to allow accessing agent run info in external downstream components - #3476
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces AgentRunContext to provide ambient access to agent run information for downstream components like tools and middleware. This addresses issue #3411 regarding ConversationId propagation in Agent-as-a-Tool scenarios by making agent run context (agent, session, messages, options) accessible via AIAgent.CurrentRunContext using AsyncLocal<T>.
Changes:
- Added
AgentRunContextclass to encapsulate agent run state (agent, session, request messages, run options) - Modified
AIAgentto setCurrentRunContextusingAsyncLocal<T>at the start of each run (both streaming and non-streaming) - Added comprehensive unit tests for
AgentRunContextand updatedAIAgenttests to verify context propagation - Added architectural decision record documenting the design rationale
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunContext.cs | New sealed class providing read-only access to agent run information |
| dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs | Added AsyncLocal field and CurrentRunContext property; modified RunAsync/RunStreamingAsync to set context |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentRunContextTests.cs | Comprehensive unit tests for AgentRunContext constructor validation and property accessors |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentTests.cs | Added tests verifying CurrentRunContext is set for all RunAsync/RunStreamingAsync overloads; updated TestAgentSession visibility |
| docs/decisions/0015-agent-run-context.md | Architectural decision record explaining design choices and trade-offs |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Motivation and Context
#3411
Description
Contribution Checklist