-
Notifications
You must be signed in to change notification settings - Fork 577
.NET: API to manage AgentThreads in hosting scenarios #1520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…orkflowExtensions.cs Co-authored-by: Copilot <[email protected]>
…crosoft/agent-framework into dmkorolev/workflow-extensions
|
||
return threadContent switch | ||
{ | ||
null => new ValueTask<AgentThread>(agent.GetNewThread()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the store should be responsible for obtaining a new thread from the agent, in addition to its existing "store" responsibilities. Shouldn't the store return null to indicate to the calling code that there is no thread available, allowing the calling/consumer code to decide whether to create a new thread or not? This would provide a clear separation of responsibilities and additional flexibility: the store would be responsible for storage, while the calling code would handle the absence of a thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit confusing at the moment, I agree. Current implementation is what we decided before via the call with Reuben, Weslie and Stephen: see #1520 (comment).
The point is that we have a "better" API on the store interface: otherwise I would expose JsonElement?
which is basically exposing inner implementation details. Maybe not everyone expects that type to be a representation of an AgentThread
.
also whatever mechanism under the hood has to return a thread, otherwise you would not pass anything into AIAgent.RunAsync()
and thread will not be returned to you. So we have to create a thread (that's why return type is not nullable)
dotnet/src/Microsoft.Agents.AI.Hosting/HostedAgentBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
…oft/agent-framework into dmkorolev/hosting-threads
This is a prototype / design proposal for the API which allows managing
AgentThread
in relationship withAIAgent
.PR showcases a simple scenario where Hosting.A2A package now obtains an ability to load the thread from in-app-memory based on
contextId
(input of the user), andagentId
(the id of a specificAIAgent
). It then saves the agent thread content back via serialization.Default behavior is to not have any thread store - the
NoContextAgentThreadStore
simply never saves or returns a thread. I think this is useful to not force any default behavior here, because storing all agent thread content in memory can quickly drain all of memory.The API added:
IAgentThreadStore
which regulates how agent thread data is being stored:and
AIHostAgent
which wraps theAIAgent
and a specificIAgentThreadStore
implementation.Schema of flow
This is a flow which shows the implementation as in the current PR. It leverages the separate
IAgentThreadStore
which is used to . It definitely works, uses the existingAIAgent
abstraction and uses a separate interface to save/restore thread via the conversationId.This is a "direct" flow, where no "extra" store is used, but the restoration of thread happens inside of the same MessageStore.