- Newest
- Most votes
- Most comments
Hello,
This is Shubham from AWS !
Kindly note that Prompt Flows, by default, don't inherently maintain state or session information between invocations.
To achieve your goal of maintaining session and context for the agent throughout the entire prompt flow, you need to follow these recommendations:
-
Incorporate Agent Nodes: Add "Agent nodes" [1] to your prompt flow. These nodes are designed to work with Bedrock Agents and support memory retention.
-
Use Session Attributes: When configuring your Agent nodes, make use of sessionAttributes [2]. These attributes persist over a session between a user and an agent, allowing you to maintain context.
-
Implement Proper Session Management: When invoking the agent, provide a sessionId parameter. This unique identifier should be used across requests to continue the same conversation. Additionally, use a memoryId parameter, which is a unique identifier for each user, allowing the agent to retain a summary of the conversation for that memory and use it in subsequent sessions.
-
Leverage Data Connections: To maintain state across multiple nodes in your Prompt Flow, implement data connections to pass information from one node to another.
-
Consider Conditional Connections: These can be used to route data based on certain conditions, which might be useful for more complex conversation flows.
By implementing these changes, you should be able to design your Prompt Flow to use agent nodes and pass relevant context or session data between them.
For a more detailed understanding of how to implement these suggestions, I recommend reviewing the following resources:
[1] AWS Documentation on Flow Nodes [2] AWS Documentation on Agent Session State [3] AWS Documentation on FlowNodeConfiguration [4] AWS Documentation on Memory Retention in Bedrock Agents [5] Boto3 examples for creating and invoking an agent with session attributes
These resources should provide you with the necessary information to implement session and memory support in your Bedrock Prompt Flows.
I hope this information helps clarify the situation and provides a path forward. If you have any further questions or need additional assistance implementing these changes, please don't hesitate to ask. We're here to help ensure you get the most out of your AWS services.
References: [1] https://docs.aws.amazon.com/bedrock/latest/userguide/flows-nodes.html [2] https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html [3] https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_FlowNode.html [4] https://aws.amazon.com/blogs/aws/agents-for-amazon-bedrock-now-support-memory-retention-and-code-interpretation-preview/ [5] https://docs.aws.amazon.com/code-library/latest/ug/python_3_bedrock-agent_code_examples.html
To maintain session memory for a Bedrock Agent throughout a prompt flow, you need to understand how memory works in Amazon Bedrock and implement the appropriate configuration. Here's what you need to know and do:
-
Enable Memory: By default, Bedrock Agents retain conversational context only for a single session. To maintain context across multiple sessions or steps in a prompt flow, you need to explicitly enable memory for your agent.
-
Configure Memory Duration: When enabling memory, you can specify the storage duration for retaining the memory. This can be set for up to 30 days, allowing you to maintain context for extended periods if needed.
-
Use Consistent Session IDs: To maintain context across multiple steps in your prompt flow, you need to use the same session ID for each interaction. This allows the agent to access the stored conversation history and summaries from previous steps.
-
Provide Memory Identifier: If you're dealing with multiple users or flows, make sure to provide the same memory identifier (memoryId) for the same user or flow. This ensures that the agent loads the correct memory context for each interaction.
-
Invoke Agent Properly: When invoking the agent in your prompt flow, make sure to use the InvokeAgent action with the correct parameters. Set the sessionId to be consistent across steps, and only set endSession to 'true' when you want to finalize the memory context for that particular flow.
-
Consider Model Limitations: Memory features are only supported for specific models, such as Anthropic Claude 3 Sonnet v1 and Anthropic Claude 3 Haiku v1. Ensure you're using a compatible model for your agent.
-
Manage Memory Programmatically: You can use the GetAgentMemory action to retrieve memory information and DeleteAgentMemory to clear memory when needed.
By implementing these steps, you should be able to maintain session memory throughout your prompt flow, allowing the agent to remember previous inputs and maintain context until it reaches the required result. This approach will help ensure a continuous session context before moving to the next step in your flow.
Remember to test your implementation thoroughly to ensure that the memory retention works as expected across all steps of your prompt flow.
Sources
Retain conversational context across multiple sessions using memory - Amazon Bedrock
Amazon Bedrock Agents Runtime - Amazon Bedrock
MemoryConfiguration - Amazon Bedrock
answered 2 years ago
Relevant content
asked 2 years ago
asked 2 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 6 months ago

@Shubham_S do you have. a code snippet for point number 3, providing from a flow definition the session ID and memory ID to an agent invocation?