You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The serialized session of a workflow hosted as an agent (workflow.AsAIAgent(), then agent.SerializeSessionAsync(session)) grows roughly with the cube of the number of turns. With an outer workflow that contains a handoff workflow bound via BindAsExecutor, we measured:
Turns
Serialized session
1
1.3 MB
4
47 MB
That makes an in-memory or distributed session store impractical after a few turns.
The growth comes from two things:
InMemoryCheckpointManager keeps every superstep checkpoint of every turn.
The sub-workflow keeps its own checkpoint manager inside the parent's checkpoint state. Each parent checkpoint therefore carries a full copy of the child's whole history.
Resuming a session only reads the session's lastCheckpoint, and inside it only the last entry of the sub-workflow manager's index. Every other checkpoint is kept only for time travel, which a chat agent never uses.
Expected behavior
A hosted workflow agent's session keeps only what a resume needs. Possible shapes:
SerializeSessionAsync writes only the checkpoint chain needed to resume.
A retention option on the in-memory checkpoint manager, such as "keep the last N checkpoints". Nested sub-workflow managers would honor it too.
Workaround we use
We post-process the serialized JSON. In each checkpoint manager we keep only the checkpoint that lastCheckpoint points to (for nested managers, the last index entry) and drop the rest. Four turns become about 430 KB, and multi-turn resume keeps working.
This depends on the internal serialization shape (store / checkpointIndex / cache, plus the type name Microsoft.Agents.AI.Workflows.Checkpointing.InMemoryCheckpointManager in stateData). Any framework update can break it silently.
Repro
Build a handoff workflow (AgentWorkflowBuilder.CreateHandoffBuilderWith(...)) with two or more agents.
Bind it with BindAsExecutor inside an outer WorkflowBuilder workflow.
Host the outer workflow with AsAIAgent().
Run four turns on one session, calling SerializeSessionAsync after each, and compare the payload sizes.
Reproduced this on main with a nested handoff, the session hits about 21 MB after 6 turns.
I have a fix locally and wanted to check the approach first. The sub-workflow keeps only its latest checkpoint, and the session's own manager drops older ones after a resumed run saves a new one. Custom managers/stores are left alone. Same 6 turns end up around 260 KB.
Downside is you can't recover to an earlier turn anymore, only the current one. Would an opt-in "keep last N" setting be worth adding for that?
Activity
kartikmadan11 commentedon Oct 27, 2026
Reproduced this on main with a nested handoff, the session hits about 21 MB after 6 turns.
I have a fix locally and wanted to check the approach first. The sub-workflow keeps only its latest checkpoint, and the session's own manager drops older ones after a resumed run saves a new one. Custom managers/stores are left alone. Same 6 turns end up around 260 KB.
Downside is you can't recover to an earlier turn anymore, only the current one. Would an opt-in "keep last N" setting be worth adding for that?
.NET: Bound workflow session checkpoint growth across turns