microsoft / microsoft/agent-framework

[Feature]: Allow saving partial AgentSession state when streaming is cancelled

Open
#8,157 1 comment 5 reactions 1 assignee View on GitHub

@rogerbarreto is already working on this.

Since Sep 8, 2026.

agents
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.