

# Use short-term memory
<a name="using-memory-short-term"></a>

In your AI agent, you write code to add events to [short-term memory](memory-types.md#short-term-memory) in an AgentCore Memory. These events are stored as short-term memory. They form the foundation for structured information extraction into long-term memory.

The following section discusses short-term memory with the AWS SDK. For examples that use the [Amazon Bedrock AgentCore samples repository](https://github.com/awslabs/amazon-bedrock-agentcore-samples) and the AWS SDK, see [Scenario: A customer support AI agent using AgentCore Memory](memory-customer-scenario.md) . For other SDKs see [Amazon Bedrock AgentCore Memory examples](memory-examples.md).

**Topics**
+ [

# Create an event
](short-term-create-event.md)
+ [

# Get an event
](short-term-get-event.md)
+ [

# List events
](short-term-list-events.md)
+ [

# Delete an event
](short-term-delete-event.md)

# Create an event
<a name="short-term-create-event"></a>

Events are the fundamental units of short-term from which structured informations are extracted into long-term memory in AgentCore Memory. The [CreateEvent](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_CreateEvent.html) operation lets you store various types of data within AgentCore Memory, organized by an actor and session. Events are scoped within memory under:

 **ActorId**   
Identifies the entity associated with the event, such as end-users or agent/user combinations

 **SessionId**   
Groups related events together, such as a conversation session

The `CreateEvent` operation stores a new immutable event within a specified memory session. Events represent individual pieces of information that your agent wants to remember, such as conversation messages, user actions, or system events.

This operation is useful for:
+ Recording conversation history between users, agents and tools
+ Storing user interactions and behaviors
+ Capturing system events and state changes
+ Building a chronological record of activities within a session

For example code, see [Scenario: A customer support AI agent using AgentCore Memory](memory-customer-scenario.md).

## Event payload types
<a name="event-payload-types"></a>

The `payload` parameter accepts a list of payload items, letting you store different types of data in a single event. Common payload types include:

 **Conversational**   
For storing conversation messages with roles (for example, "user" or "assistant") and content.

 **Blob**   
For storing binary format data, such as images and documents, or data that is unique to your agent, such as data stored in JSON format.

**Note**  
Currently, only conversational data flows into long-term memory.

## Event branching
<a name="short-term-event-branching"></a>

The `branch` parameter lets you organize events through advanced branching. This is useful for scenarios like message editing or alternative conversation paths. For example, suppose you have a long-running conversation, and you realize you’re interested in exploring an alternative conversation starting from 5 messages ago. You can use the `branch` parameter to start a new conversation from that message, stored in the new branch — which lets you also return to the original conversation. And more mundanely, this is useful if you want to let your user edit their most recent message (in case the user presses enter early or has a typo) and continue the conversation.

When creating a branch, you specify:

 **name**   
A descriptive name for the branch, such as "edited-conversation".

 **rootEventId**   
The ID of the event from which the branch originates.

Here’s an example of creating a branched event to represent an edited message:

```
{
  "memoryId": "mem-12345abcdef",
  "actorId": "/agent-support-123/customer-456",
  "sessionId": "session-789",
  "eventTimestamp": 1718806000000,
  "payload": [
    {
      "Conversational": {
        "content": "I'm looking for a waterproof action camera for extreme sports.",
        "role": "user"
      }
    }
  ],
  "branch": {
    "name": "edited-conversation",
    "rootEventId": "evt-67890"
  }
}
```

# Get an event
<a name="short-term-get-event"></a>

The [GetEvent](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_GetEvent.html) API retrieves a specific raw event by its identifier from short-term memory in AgentCore Memory. This API requires you to specify the `memoryId` , `actorId` , `sessionId` , and `eventId` as path parameters in the request URL.

```
import boto3

data_client = boto3.client('bedrock-agentcore')

response = data_client.get_event(
    memoryId="your-memory-id",
    actorId="your-actor-id",
    sessionId="your-session-id",
    eventId="your-event-id"
)

event = response['event']
print(f"Event ID: {event['eventId']}")
print(f"Timestamp: {event['eventTimestamp']}")
print(f"Payload: {event['payload']}")
```

# List events
<a name="short-term-list-events"></a>

The [ListEvents](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_ListEvents.html) operation is valuable for applications that need to reconstruct conversation histories, analyze interaction patterns, or implement memory-based features like conversation summarization and context awareness.

The `ListEvents` operation is a read-only operation that lists events from a specified session in AgentCore Memory instance. This paginated operation requires you to specify the `memoryId` , `actorId` , and `sessionId` as path parameters, and supports optional filtering through the `filter` parameter in the request body, letting you efficiently retrieve relevant events from your memory sessions. You can control whether payloads are included in the response using the `includePayloads` parameter (default is true), and limit the number of results with `maxResults`.

# Delete an event
<a name="short-term-delete-event"></a>

The [DeleteEvent](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_DeleteEvent.html) operation removes individual events from your AgentCore Memory. This operation helps maintain data privacy and relevance by letting you selectively remove specific events from a session while preserving the broader context and relationship structure within your application’s memory.

**Note**  
These are manual deletion operations, and do not overlap with automatic deletion of events based on the `eventExpiryDuration` parameter set at the time of [CreateEvent](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_CreateEvent.html) operation. Also deleting an event doesn’t remove the structured information derived out of it from the long term memory. For more information, see [DeleteMemoryRecord](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_DeleteMemoryRecord.html).