Uh oh!
There was an error while loading. Please reload this page.
.NET: [BREAKING] Provide agent and session to AIContextProvider & ChatHistoryProvider - #3695
Conversation
…ontextProvider and ChatHistoryProviders
There was a problem hiding this comment.
Pull request overview
This pull request enhances the AIContextProvider and ChatHistoryProvider abstractions by passing the AIAgent and AgentSession to their context objects. This enables providers to access session state and agent details, supporting more flexible and stateless provider implementations.
Changes:
- Updated
AIContextProvider.InvokingContextandAIContextProvider.InvokedContextto accept and storeAIAgentandAgentSession?parameters - Updated
ChatHistoryProvider.InvokingContextandChatHistoryProvider.InvokedContextto accept and storeAIAgentandAgentSession?parameters - Modified
ChatClientAgentto passthis(agent) and session to all provider context instantiations - Updated all test files, integration tests, and samples to use the new constructor signatures with mock agents/sessions
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs | Added Agent and Session properties to InvokingContext and InvokedContext with null validation for agent |
| dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs | Added Agent and Session properties to InvokingContext and InvokedContext with null validation for agent |
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs | Updated all provider context instantiations to pass this and session; changed notification methods from static to instance methods |
| dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs | Updated custom agent implementation to use new context constructor signatures |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/TestJsonSerializerContext.cs | Added JSON serialization support for test Animal class |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentSessionTests.cs | Added internal Animal class for testing |
| dotnet/tests/.UnitTests/.cs | Added mock agent/session fields and updated all context instantiations |
| dotnet/tests/.IntegrationTests/.cs | Updated test fixtures to accept agent parameter in GetChatHistoryAsync method |
| dotnet/tests/AgentConformance.IntegrationTests/IAgentFixture.cs | Updated interface signature for GetChatHistoryAsync to include agent parameter |
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: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
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.
Motivation and Context
It's valuable for an AIContextProvider or ChatHistoryProvider to know which agent or session it is working with. This allows greater flexibility for implementers to modify the behavior of the providers based on the current session state or agent details.
This also paves the way for a key scenario where state for a provider should ideally be contributed to the session, making providers stateless and reusable. A PR addressing this to follow.
Description
Contribution Checklist