Skip to content

[dotnet-port] Preserve AGUI session history across multi-turn runs #257

Description

@github-actions

Summary

The AGUI provider assigns a thread ID to the session on the first run by calling session.SetServiceID(threadID). The agent's history machinery interpreted any non-empty ServiceID as a signal that the service manages history server-side and therefore disabled the local HistoryProvider for all subsequent runs. This caused conversation history to be silently dropped after the first turn.

Root cause (two related issues):

  1. historyProviderForRun returned nil when session.ServiceID() != "", so the second run never loaded history.
  2. shouldStoreHistoryProvider returned false after the first run set the service ID, so history was never stored in the session after the first run.

Fix:

  • Add ServiceDoesNotManageHistory bool to ProviderConfig. Providers that never delegate history to the service (i.e. AGUI always requires the caller to send the full message history on every turn) set this flag to true.
  • When ServiceDoesNotManageHistory is true, historyProviderForRun, shouldStoreHistoryProvider, and handleHistoryProviderConflict all preserve the HistoryProvider regardless of session service ID.
  • Set ServiceDoesNotManageHistory: true in the AGUI provider constructor.

Ported .NET PRs

The .NET fix added a special IsAGUIProviderName check so that ChatHistoryProvider is always used when the provider is AGUI, even when a ConversationId (thread ID) is set. The Go fix generalises this into a provider-declared flag (ServiceDoesNotManageHistory) rather than hard-coding the provider name, which is more idiomatic and reusable.

Breaking Changes

No. The ServiceDoesNotManageHistory field defaults to false, which preserves the existing behaviour for all current providers. Only AGUI now sets it to true.

Tests and Examples

  • Added TestAGUIAgentRun_WithSession_PreservesHistoryAcrossMultipleTurns: creates a session, runs the agent twice, and asserts that the second AG-UI request carries the full conversation history (3 messages: user + assistant from turn 1, plus new user message from turn 2).
  • All existing tests continue to pass (go test ./... — 34 packages).

Notes

Commits af772997 (.NET GitHub Copilot SDK v1.0.0 migration) and 6a2efeae (hosting bugs for HostedFoundryMemoryProviderScopes) were skipped as they have no Go equivalent. 33120129 (declarative workflow single-column fix) was skipped as declarative workflows are .NET-only.

Generated by .NET to Go Porting Agent · ● 26M ·


Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch dotnet-port/agui-session-history-fix-aaccb6f14ccbd050.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (256 of 256 lines)
From 18b64681a282dac0402fe1df9149328851cd87a0 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Tue, 9 Jun 2026 10:19:45 +0000
Subject: [PATCH] agent/aguiagent: preserve session history across multi-turn
 AG-UI runs

The AG-UI provider assigns a thread ID to the session on the first run by
calling session.SetServiceID(threadID). The agent's history machinery
interpreted any non-empty ServiceID as a signal that the service manages
history server-side, and therefore disabled the local HistoryProvider for
every subsequent run. This caused conversation history to be dropped after
the first turn.

Add ServiceDoesNotManageHistory bool to ProviderConfig. Providers that
never delegate history to the service (e.g. AGUI) set this flag true; the
agent then preserves the HistoryProvider across runs regardless of whether
the session has a ServiceID. This also prevents the provider from being
flagged as a conflict when a user-configured HistoryProvider is present.

Set ServiceDoesNotManageHistory: true in the AGUI provider constructor.

Add TestAGUIAgentRun_WithSession_PreservesHistoryAcrossMultipleTurns to
verify that the second run sends the full conversation history (3 messages)
rather than only the new user message.

Ports behavior fix from microsoft/agent-framework#5904.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 agent/agent.go                        | 64 +++++++++++++++++----------
 agent/provider/aguiagent/agui.go      |  7 +--
 agent/provider/aguiagent/agui_test.go | 61 +++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 27 deletions(-)

diff --git a/agent/agent.go b/agent/agent.go
index 5a0fc703..fc991566 100644
--- a/agent/agent.go
+++ b/agent/agent.go
@@ -36,6 +36,14 @@ type ProviderConfig struct {
 
 	// CreateSession configures a provider-specific session.
 	CreateSession func(ctx context.Context, session *Session, options ...Option) error
+
+	// ServiceDoesNotManageHis
... (truncated)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions