Lesson 4 of 6 Agentic AI Workflows

Managing Agent State and Memory

This lesson explains how agents keep state to continue a conversation, track progress through a task and remember users across sessions, which the exam guide asks you to implement.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish conversation, task and long-term state.
  • Choose AWS options for agent state.
  • Keep state in managed stores rather than agent compute.

Kinds of state

Conversation state is the message history of the current session. Task state records progress through multi-step work, such as which approvals have been obtained. Long-term memory keeps facts and preferences about a user across sessions, such as "prefers email contact". Because context windows are finite and tokens cost money, agents cannot simply keep everything in the prompt; they need storage, summarisation and retrieval of relevant memories.

Match the pairs

Kinds of agent state

Exam skills 3.2.9

Match each kind of state with an example.

Log in to try this activity Interactive activities are free with an account.

AWS options

Bedrock Agents manage session state for a sessionId, accept session attributes (persist for the session and are passed to action group Lambda functions) and prompt session attributes (for the current turn), and can enable memory that summarises sessions for later ones. AgentCore Memory stores short-term memory as events per actor and session, and extracts long-term memory with built-in strategies: semantic (facts), user preferences and session summaries, or custom strategies; agents retrieve relevant memories by semantic search. For custom frameworks, DynamoDB is a common store for checkpoints and task state, and Step Functions holds state for deterministic workflows.

The following diagram shows where a travel-booking agent stores each kind of state: conversation events, long-term preferences and booking progress.

Where the travel agent keeps its state. Each conversation turn is written to AgentCore Memory as an event with the user as actor and the trip as session; the user-preference strategy extracts long-term memories such as aisle seat and vegetarian; and booking progress is stored in DynamoDB by trip ID. A new session, even on different compute, retrieves both before responding.
The scenario is illustrative.
Scenario questions

Where state lives

Exam skills 3.2.9

Choose where to store each kind of agent state.

Log in to try this activity Interactive activities are free with an account.

Design guidance

Agent state should live in managed stores rather than in the agent's compute, so that sessions survive restarts and the agent can scale across many instances; the compute itself stays stateless. Memory is scoped by user, or actor, to prevent information from leaking between users.

Memory also needs governance: retention periods limit how long it is kept, sensitive data is not stored unless necessary, and stored memory is encrypted. Long conversation histories are summarised rather than replayed in full, which keeps prompts short and costs down. The following table summarises the options.

NeedOption
Pass context to tools within a sessionBedrock Agents session attributes
Remember users across sessionsAgentCore Memory long-term strategies or Bedrock Agents memory
Short-term conversation historyAgentCore Memory events
Checkpoint a custom agent's task progressDynamoDB
Fixed multi-step process with waitsStep Functions
Worked example

A travel agent that remembers

A travel assistant built with Strands Agents on AgentCore Runtime should remember that a user prefers aisle seats and vegetarian meals, and resume a booking if the user returns hours later.

  • Write each conversation turn as an AgentCore Memory event with the user as actor and the trip as session.
  • Enable the user-preference strategy, which extracts "aisle seat" and "vegetarian" as long-term memories.
  • Store booking progress (flight held, payment pending) in DynamoDB keyed by trip ID.
  • On return, the agent retrieves preferences and booking state before responding.

Keeping state outside the runtime means a new session, even on different compute, continues where the user left off.

Check yourself

How is context passed to a Bedrock Agents Lambda action group?

Show answer

With session attributes.

Exam Tips

Remember for the exam

  • Remember facts and preferences across sessions: AgentCore Memory long-term strategies.
  • Pass context to Lambda action groups: session attributes.
  • Checkpoint custom agent progress: DynamoDB.
  • Keep compute stateless and state in managed stores.
  • Scope memory per user and set retention.