.NET: Add AIContextProvider message event and fix internal agent issue#6505
Open
XiongHaoTrigger wants to merge 3 commits into
Open
.NET: Add AIContextProvider message event and fix internal agent issue#6505XiongHaoTrigger wants to merge 3 commits into
XiongHaoTrigger wants to merge 3 commits into
Conversation
…e issue where the internal agent in Workflow is unable to pass the content of AIContextProvider to the Workflow.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for persisting AIContextProvider-injected request messages into workflow chat history (and session serialization) while preventing those injected messages from being forwarded to downstream agents.
Changes:
- Emit a workflow event for
AIContextProvider-injected request messages detected during agent invocation. - Persist injected request messages into
WorkflowSessionchat history when the new event is observed. - Add unit tests covering serialization persistence and non-forwarding to downstream agents.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AIContextProviderWorkflow.cs | Adds regression tests for persisting injected context into workflow history/serialization and preventing downstream leakage |
| dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowSession.cs | Handles a new workflow event to persist AIContextProvider request messages into workflow chat history |
| dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs | Detects injected request messages by diffing stored chat history and emits an event to the workflow |
| dotnet/src/Microsoft.Agents.AI.Workflows/AgentAIContextProviderMsgEvent.cs | Introduces an internal workflow event carrying injected request messages |
…ain them every time.
… being truncated. Correct the file name of the test document.
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.
Motivation and Context
When a
ChatClientAgentis used directly, messages injected byAIContextProviderare included in the agent session history and are preserved when the session is serialized.However, when the same agent is wrapped with
AgentWorkflowBuilder.BuildSequential(...).AsAIAgent(), the workflow session only persisted the original user input and the final workflow response. The request-side messages injected by the inner agent'sAIContextProviderstayed inside the inner agent session and were not copied into the outerWorkflowSession.This caused the workflow-as-agent session history and serialized state to lose important contextual messages.
Fixes #6344.
Description
This change adds an internal workflow event for AIContextProvider-injected request messages.
AIAgentHostExecutornow captures the inner agent session history before and after invoking the hosted agent. Any newly added request messages marked withAgentRequestMessageSourceType.AIContextProviderare emitted as an internal workflow event.WorkflowSessionhandles this internal event by adding those messages to the workflow chat history. The messages are persisted into the outer workflow session, but they are not yielded as user-visible output and are not forwarded to downstream agents in the workflow.New regression tests verify that:
Contribution Checklist