-
Notifications
You must be signed in to change notification settings - Fork 143
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
Refactor memory layer to be used across flow and chat agent #1707
Refactor memory layer to be used across flow and chat agent #1707
Conversation
3d43a3c
to
0e2c00d
Compare
0e2c00d
to
c9765fa
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## feature/agent_framework_dev #1707 +/- ##
=================================================================
+ Coverage 68.60% 68.94% +0.34%
- Complexity 2591 2611 +20
=================================================================
Files 239 241 +2
Lines 12757 12875 +118
Branches 1284 1291 +7
=================================================================
+ Hits 8752 8877 +125
+ Misses 3404 3392 -12
- Partials 601 606 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@jngz-es @ylwu-amzn please review |
.getFinalInteractions(memoryId, PREVIOUS_INTERACTION, ActionListener.<List<Interaction>>wrap(interactions -> { | ||
if (interactions.size() == 0) { | ||
throw new IllegalStateException("No existing interactions to update"); | ||
} |
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.
Few questions here
- if flow agent don't have conversational agent as its tools, there should not have any interactions behind the memory. Should we throw exception for this case?
- Get last 1 interaction may not work when race condition happens, there may have new interaction before previous interaction have final answer
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.
Good question:
- Will update to create an empty interaction in case there are no existing interaction.
- As per my understanding
getFinalInteraction
will return previous interaction with final answer. @Zhangxunmt please confirm ifgetFinalInteractions
can result in race condition.
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.
getFinalInteractions returns all interactions that are not traces. The final interaction itself is always created when an interaction starts, with an empty response and it waits until all the traces are complete to obtain the final answer. So it's possible that new interaction is created before the previous one receives the final response.
String title = inputDataSet.getParameters().get(QUESTION); | ||
|
||
ConversationIndexMemory.Factory conversationIndexMemoryFactory = | ||
(ConversationIndexMemory.Factory) memoryFactoryMap.get(memoryType); |
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.
does this mean we can only use conversation_index
as memory type for all agents?
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.
In my opinion, memory should not be tied to an agent and should be common to all agents. We could have different implementations for memory that could be dynamically chosen but it should reusable across all agents.
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.
This memoryFactoryMap is supposed to support different memory types. Any memory that implements the "Memory" class can be registered in this Map at initialization. So any agent can fetch the memory based on their needs using a memory type. ATM, we only implemented ConversationIndexMemory but there will be more on the way.
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.
@jngz-es @ylwu-amzn have question about Memory
interface, is memory instance a single memory object or it's a memory container?
BufferedMemory
implements like a container for all sessions
ConversationIndexMemory
have a property conversation_id
associate with it, it's more like a single memory object
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.
Please ignore BufferedMemory for now, we don't use it right now as it is not P0 I think.
Yeah, ConversationIndexMemory is an object which is allocated for each request.
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.
This PR name is a little confusing. I thought its a big refactor for all the memory layer :).
f2215ec
to
584dfbc
Compare
584dfbc
to
b4dbe23
Compare
} | ||
String outputResponse = parseResponse(output); | ||
params.put(outputKey, outputResponse); | ||
additionalInfo.put(outputKey, outputResponse); |
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.
Using previous step output as chat history may not sufficient for generating suggestions. At least we should include question, that could include in prompt template. Further more, chat history in conversational agent should used.
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.
Parameters field already contains question as part of the map.
Adding historical chat context to flow parameters will be added as part of a different PR.
.updateInteraction( | ||
parentInteractionId, | ||
ImmutableMap.of(AI_RESPONSE_FIELD, finalAnswer1), | ||
ActionListener.<UpdateResponse>wrap(updateResponse -> { |
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.
why ADDITIONAL_INFO_FIELD, additionalInfo
been removed ?
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.
Resolved merge conflict
c29dee1
to
6dd5242
Compare
Signed-off-by: Arjun kumar Giri <[email protected]>
Signed-off-by: Arjun kumar Giri <[email protected]>
Signed-off-by: Arjun kumar Giri <[email protected]>
Signed-off-by: Arjun kumar Giri <[email protected]>
6dd5242
to
a7bb564
Compare
Signed-off-by: Arjun kumar Giri <[email protected]>
a7bb564
to
371b685
Compare
@@ -299,17 +298,7 @@ private void runReAct( | |||
String maxIteration = Optional.ofNullable(tmpParameters.get("max_iteration")).orElse("3"); | |||
|
|||
// Create root interaction. | |||
StepListener<CreateInteractionResponse> createRootItListener = new StepListener<>(); |
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.
Got it, thanks!
fcbfc7e
into
opensearch-project:feature/agent_framework_dev
Description
Refactored conversation creation to MLAgentExecutor so that the same memory ID could be used across multiple agents. Generated memory ID will be passed to agents as part of input parameters. Integrated memory with flow agent, with output of the flow agent being appended to additional info field of interaction.
Request:
Response:
Conversation history:
TODO:
Issues Resolved
[List any issues this PR will resolve]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.