From 6882e003f5e58d154575907f1f5fdd14a25693b0 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Mon, 9 Jun 2025 16:21:42 +0100 Subject: [PATCH] Add IMessagesRetrievableThread interface (#63) * Add a MessageAgentThread and GetService for Thread * Remove redundant check and experimental attribuet. * Address PR comments. * Fix file name. * Update comments. * Remove GetService --- .../IMessagesRetrievableThread.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 dotnet/src/Microsoft.Agents.Abstractions/IMessagesRetrievableThread.cs diff --git a/dotnet/src/Microsoft.Agents.Abstractions/IMessagesRetrievableThread.cs b/dotnet/src/Microsoft.Agents.Abstractions/IMessagesRetrievableThread.cs new file mode 100644 index 0000000000..ed0688794c --- /dev/null +++ b/dotnet/src/Microsoft.Agents.Abstractions/IMessagesRetrievableThread.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Threading; +using Microsoft.Extensions.AI; + +namespace Microsoft.Agents; + +/// +/// An interface for agent threads that allow retrieval of messages in the thread for agent invocation. +/// +/// +/// +/// Some agents need to be invoked with all relevant chat history messages in order to produce a result, while some must be invoked +/// with the id of a server side thread that contains the chat history. +/// +/// +/// This interface can be implemented by all thread types that support the case where the agent is invoked with the chat history. +/// Implementations must consider the size of the messages provided, so that they do not exceed the maximum size of the context window +/// of the agent they are used with. Where appropriate, implementations should truncate or summarize messages so that the size of messages +/// are constrained. +/// +/// +public interface IMessagesRetrievableThread +{ + /// + /// Asynchronously retrieves all messages to be used for the agent invocation. + /// + /// + /// Messages are returned in ascending chronological order. + /// + /// The to monitor for cancellation requests. The default is . + /// The messages in the thread. + /// The thread has been deleted. + IAsyncEnumerable GetMessagesAsync(CancellationToken cancellationToken = default); +}