microsoft / microsoft/agent-framework
[Feature]: Allow saving partial AgentSession state when streaming is cancelled
@rogerbarreto is already working on this.
Since Sep 8, 2026.
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 2.3k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 358
Description
### Description
When using `AIAgent.RunStreamingAsync` with an `AgentSession`, cancelling the streaming operation via `CancellationToken` prevents the current interaction from being persisted into the session.
This is expected from a cancellation-flow perspective, but it creates an issue for chat applications: the user may have already received a partial assistant response, while the `AgentSession` does not contain either the user message or the partial assistant response.
As a result, the visible conversation shown to the user can diverge from the conversation state stored in the `AgentSession`.
It would be useful to have an opt-in flag/API that allows persisting the interaction up to the point where cancellation occurred.
## Why this matters
In real-time chat UIs, cancellation does not always mean "discard the turn". Often it means "stop generating now, but keep what the user already saw."
Without a supported way to persist that partial turn, applications have to choose between:
1. losing conversation consistency between UI and session state, or
2. implementing custom workarounds outside the Agent Framework session model.
An explicit opt-in flag would make this behavior predictable and avoid surprising session-history gaps.
### Language/SDK
Both
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.