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
GetInMemoryHistory(session *Session, sourceID string) []*message.Message — reads the conversation messages stored in a session by NewInMemoryHistoryProvider. Returns a defensive copy; returns nil when nothing has been stored yet or session is nil.
SetInMemoryHistory(session *Session, sourceID string, messages []*message.Message) — replaces the stored history slice, enabling preloading, truncation, or clearing.
Both functions accept an empty sourceID and default to "in-memory" (matching NewInMemoryHistoryProvider's default key). Custom source IDs are fully supported.
This gives callers a typed, readable way to inspect or manipulate in-memory history between turns without knowing the internal session-state key. It also enables testing scenarios where you want to preset the conversation history before running the agent.
The Go port covers the session-level accessor helpers (TryGetInMemoryChatHistory / SetInMemoryChatHistory). The .NET PR also adds IChatReducer integration into InMemoryChatHistoryProviderOptions; that piece is not included here because Go uses messagefilter functions for the equivalent reduction and a follow-up that wires a compaction provider option into NewInMemoryHistoryProvider would be a separate, larger change.
Breaking Changes
No. These are new exported functions with no impact on existing APIs.
The feature comparison doc (docs/dotnet-go-sdk-feature-comparison.md) is updated to reflect that the Go SDK now has session history access helpers, keeping the "Chat history" row at Partial since reducer-trigger integration and additional built-in storage providers are still missing.
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-inmemory-history-helpers-3c07f119cef6f9f8.
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (243 of 243 lines)
From 42bf9fe47e00353f1b9942a6c8f5a2bd6166b2ee Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Sun, 24 May 2026 09:42:32 +0000
Subject: [PATCH] agent: add GetInMemoryHistory/SetInMemoryHistory session
helpers
Adds GetInMemoryHistory and SetInMemoryHistory to the agent package,
mirroring the .NET AgentSessionExtensions.TryGetInMemoryChatHistory
and SetInMemoryChatHistory helpers added in microsoft/agent-framework#5171
(commit 822a3eb5).
These helpers let callers inspect and replace the conversation messages
stored in a session by NewInMemoryHistoryProvider, without needing to
reach into session state directly or know the internal key name.
GetInMemoryHistory returns a copy of the stored messages (nil when no
history exists or session is nil). SetInMemoryHistory replaces the
stored slice, enabling preloading, truncation, or clearing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
agent/history.go | 41 +++++++
agent/history_test.go | 143 +++++++++++++++++++++++
docs/dotnet-go-sdk-feature-comparison.md | 2 +-
3 files changed, 185 insertions(+), 1 deletion(-)
diff --git a/agent/history.go b/agent/history.go
index 69aa8f29..c93a7ef4 100644
--- a/agent/history.go+++ b/agent/history.go@@ -209,3 +209,44 @@ func NewInMemoryHistoryProvider(sourceID string) *HistoryProvider {
type inmemoryState struct {
Messages []*message.Message `json:"messages,omitempty"`
}
++// GetInMemoryHistory returns the conversation messages stored in the session by the+// in-memory history provider identified by sourceID. If sourceID is empty it defaults+// to "in-memory" (matching [NewInMemoryHistoryProvider]'s default). When no history+// has been stored yet, or when session is nil, an empty slice is returned.+//+// This is the Go equivalent of the .NET AgentSessionExtensions.TryGetInMemoryChatHistory helper.+func GetInMemoryHistory(session *Session,
... (truncated)
Summary
Adds two new helpers to the
agentpackage:GetInMemoryHistory(session *Session, sourceID string) []*message.Message— reads the conversation messages stored in a session byNewInMemoryHistoryProvider. Returns a defensive copy; returnsnilwhen nothing has been stored yet or session is nil.SetInMemoryHistory(session *Session, sourceID string, messages []*message.Message)— replaces the stored history slice, enabling preloading, truncation, or clearing.Both functions accept an empty
sourceIDand default to"in-memory"(matchingNewInMemoryHistoryProvider's default key). Custom source IDs are fully supported.This gives callers a typed, readable way to inspect or manipulate in-memory history between turns without knowing the internal session-state key. It also enables testing scenarios where you want to preset the conversation history before running the agent.
Ported .NET PRs
.NET: Add helpers to more easily access in-memory ChatHistory and make ChatHistoryProvider management more configurable(commit 822a3eb5)The Go port covers the session-level accessor helpers (
TryGetInMemoryChatHistory/SetInMemoryChatHistory). The .NET PR also addsIChatReducerintegration intoInMemoryChatHistoryProviderOptions; that piece is not included here because Go usesmessagefilterfunctions for the equivalent reduction and a follow-up that wires a compaction provider option intoNewInMemoryHistoryProviderwould be a separate, larger change.Breaking Changes
No. These are new exported functions with no impact on existing APIs.
Tests and Examples
10 new tests in
agent/history_test.go:TestGetInMemoryHistory_NilSession_ReturnsNilTestGetInMemoryHistory_NoHistoryStored_ReturnsNilTestGetInMemoryHistory_DefaultSourceID_ReadsProviderHistoryTestGetInMemoryHistory_CustomSourceID_ReadsCorrectKeyTestGetInMemoryHistory_ReturnsCopyTestSetInMemoryHistory_NilSession_IsNoOpTestSetInMemoryHistory_DefaultSourceID_RoundTripsTestSetInMemoryHistory_ReplacesExistingHistoryTestSetInMemoryHistory_NilMessages_ClearsHistoryTestSetInMemoryHistory_IsReadByProviderAll 10 pass. Full
./agent/...test suite passes.Notes
The feature comparison doc (
docs/dotnet-go-sdk-feature-comparison.md) is updated to reflect that the Go SDK now has session history access helpers, keeping the "Chat history" row at Partial since reducer-trigger integration and additional built-in storage providers are still missing.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-inmemory-history-helpers-3c07f119cef6f9f8.Click here to create the pull request
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (243 of 243 lines)