TencentDB Agent Memory architecture is the foundation for understanding how an AI agent can move beyond simple conversation history and maintain useful context across sessions, tasks, and long-running workflows.
How is the memory actually organized?
A production memory system cannot simply throw every conversation into one large storage bucket and hope semantic search finds the right answer.
It needs layers.
It needs retrieval paths.
It needs context management.
It needs memory compression.
And most importantly, it needs a strategy for deciding which information should remain close to the agent and which information can be stored externally until it becomes relevant again.
Tencent Cloud currently describes Agent Memory as having two major memory capabilities: short-term memory for managing and compressing context within the current task window, and long-term memory for persistent information across sessions and tasks. The documented architecture also describes a layered long-term memory model and a storage foundation built around vector database and file storage capabilities. (Tencent Cloud)

Why AI Agents Need a Memory Architecture
Consider a coding agent working with a developer for several days.
On Monday:
Developer:
We use TypeScript.
Agent:
Understood.
Later:
Developer:
Our E2E tests use Playwright.
Later:
Developer:
Run the tests through GitHub Actions.
Then, two days later:
Developer:
Fix the checkout test.
A stateless model may understand only:
"Fix the checkout test."
A memory-enabled agent can potentially reconstruct:
Language → TypeScript
Framework → Playwright
CI → GitHub Actions
Current project → Checkout
The important part is not simply storing those statements.
The system must determine:
What should remain immediately available?
What should be compressed?
What should be persisted?
What should be retrieved?
What should be ignored?
That is why architecture matters.
The Core Architecture
At a high level, the system can be understood as:
USER
│
▼
Current Request
│
▼
AGENT
│
┌─────────────┴─────────────┐
│ │
▼ ▼
Short-Term Memory Long-Term Memory
│ │
Current Task Persistent Knowledge
│ │
└─────────────┬─────────────┘
▼
Retrieval
│
▼
Context Builder
│
▼
LLM
│
▼
Response
│
▼
Memory Update
Tencent Cloud’s current documentation describes the overall Agent Memory architecture as three broad layers: a data foundation, the Agent Memory core, and application access. The memory core contains short-term and long-term capabilities, while applications can connect through supported integration mechanisms or SDKs. (Tencent Cloud)
This gives us an important mental model:
Storage
↓
Memory Engine
↓
Agent Application
The database is only one piece.
The memory engine determines how information becomes useful to the agent.
Short-Term Memory vs Long-Term Memory
The first architectural distinction is between information needed right now and information that should survive beyond the current task.
Short-Term Memory
Short-term memory is concerned with the active task context.
For example:
Current task:
Debug checkout API
Current error:
HTTP 500
Recent tool output:
Database timeout
Current file:
checkout.spec.ts
These details may be extremely important right now.
But they may become irrelevant tomorrow.
Long-Term Memory
Long-term memory contains information that can remain useful across interactions.
Examples:
Project:
Uses Playwright
Language:
TypeScript
CI:
GitHub Actions
Preference:
Concise technical explanations
Conceptually:
SHORT-TERM
Current task
Current state
Recent events
Temporary context
LONG-TERM
Stable facts
Preferences
Project knowledge
Historical experience
Tencent Cloud explicitly positions short-term memory around context compression and management within the current task window, while long-term memory supports persistent cross-session and cross-task accumulation. (Tencent Cloud)
Why You Should Not Put Everything Into Long-Term Memory
Imagine a long debugging session generates:
500 tool outputs
200 terminal logs
100 API responses
50 code changes
30 test reports
Should all of that become permanent memory?
Probably not.
A better pipeline is:
Raw Task Data
↓
Short-Term Context
↓
Compression
↓
Important Information
↓
Long-Term Memory
This prevents the long-term memory layer from becoming a dumping ground.
The strategic principle is:
Temporary context should remain temporary unless it has future value.
Context Window vs Memory
This distinction is easy to misunderstand.
An LLM context window is not the same thing as persistent memory.
Think about:
Context Window
=
What the model can see now
while:
Persistent Memory
=
What the agent can remember later
The relationship looks like:
Persistent Memory
│
▼
Retrieval
│
▼
Current Context
│
▼
LLM
The memory system decides what information crosses the boundary.
This is one of the most important concepts in TencentDB Agent Memory architecture.
The Four-Layer Long-Term Memory Model
Tencent Cloud’s current documentation describes long-term memory using a four-layer structure that progresses from raw information toward increasingly summarized and stable knowledge. The layers are presented as:
L0 → Raw Conversation
L1 → Atomic Memory
L2 → Scenario Memory
L3 → Core Memory
The system also emphasizes traceability between layers so that higher-level conclusions can be connected back toward their underlying source information. (Tencent Cloud)
Think of it as a knowledge pyramid:
┌───────────────┐
│ L3 Core │
│ Stable │
│ Knowledge │
└───────┬───────┘
│
┌───────┴───────┐
│ L2 Scenario │
│ Contextual │
│ Knowledge │
└───────┬───────┘
│
┌───────┴───────┐
│ L1 Atomic │
│ Facts │
└───────┬───────┘
│
┌───────┴───────┐
│ L0 Raw │
│ Conversation │
└───────────────┘
This architecture is powerful because not every query needs to retrieve the entire conversation history.
L0: Raw Conversation
L0 represents the original conversation or source information.
Example:
User:
We migrated our API tests to Playwright.
Assistant:
What language are you using?
User:
TypeScript.
Assistant:
Where do the tests run?
User:
GitHub Actions.
The raw conversation preserves the source.
Why keep it?
Because higher-level memory can eventually be wrong.
Suppose the system concludes:
Project uses Playwright.
Later, someone says:
We migrated from Playwright to Cypress.
The raw information becomes valuable for:
- Auditing
- Debugging
- Reprocessing
- Memory correction
- Historical analysis
This is why source traceability matters.
L1: Atomic Memory
The raw conversation can be transformed into structured facts.
For example:
{
"fact": "API testing framework",
"value": "Playwright"
}
And:
{
"fact": "Automation language",
"value": "TypeScript"
}
And:
{
"fact": "CI platform",
"value": "GitHub Actions"
}
Instead of retrieving an entire conversation, the agent can retrieve exactly the information it needs.
This is the first major compression step:
Conversation
↓
Individual useful facts
Why Atomic Memory Is Useful
Suppose the user asks:
What framework do we use for API testing?
The system does not need:
The entire conversation from three weeks ago.
It needs:
API testing framework → Playwright
That is much more efficient.
It also makes automated testing easier because the expected memory can be represented as structured information.
For example:
expected = {
"api_testing_framework": "Playwright",
"language": "TypeScript"
}
Your test can then validate whether retrieval returns the expected information.
L2: Scenario Memory
Atomic facts are useful, but isolated facts do not always provide enough context.
Consider:
Playwright
TypeScript
GitHub Actions
Checkout
API testing
Pull requests
A scenario-level memory can connect them:
Checkout Testing Strategy
The project uses TypeScript and Playwright
for checkout API and E2E testing.
Tests run through GitHub Actions
during pull-request validation.
Now the system has moved from:
Facts
to:
Contextual knowledge
This is particularly valuable for complex tasks.
Scenario Memory and Context
Suppose the user asks:
How should we run checkout tests in CI?
The agent may retrieve the scenario:
Checkout Testing Strategy
rather than separately retrieving:
Playwright
TypeScript
GitHub Actions
Checkout
This can reduce retrieval complexity.
Conceptually:
Atomic Facts
↓
Scenario
↓
Task Context
L3: Core Memory
At the top of the hierarchy is stable knowledge.
For example:
The engineering team prefers a
TypeScript-first Playwright automation
workflow integrated with GitHub Actions.
This is not a single conversation.
It is a higher-level representation formed from repeated evidence.
Core memory changes less frequently.
That makes it useful for personalization and stable agent behavior.
Tencent Cloud documents core memory as a higher-level persistent representation, and its current SDK documentation provides operations for reading and writing core memory. (Tencent Cloud)
The Information Compression Journey
The complete process can therefore look like:
L0
Raw Conversations
↓
L1
Atomic Facts
↓
L2
Scenario Knowledge
↓
L3
Core Knowledge
Notice what happens:
More information
↓
More structure
↓
Less noise
↓
Higher information density
This is much more sophisticated than simply storing chat history.
An Example From a Coding Agent
Imagine an AI coding agent has interacted with a developer for six months.
Raw information might include:
10,000+ messages
Thousands of tool outputs
Hundreds of files
Many test results
Multiple architectural decisions
The system could gradually derive:
L1
Language = TypeScript
Framework = Playwright
CI = GitHub Actions
Database = PostgreSQL
L2
Testing Architecture:
Playwright-based automation is written in
TypeScript and executed through GitHub Actions.
L3
Engineering Preference:
The project follows a TypeScript-first
automation strategy with Playwright.
Now imagine the user asks:
Create a new checkout E2E test.
The agent can potentially retrieve the higher-level information first.
That is the strategic advantage of hierarchical memory.
Retrieval Should Match the Question
Different questions require different memory levels.
Consider:
| User Query | Useful Memory |
|---|---|
| What framework do we use? | L1 |
| How does our checkout testing work? | L2 |
| What is our general testing philosophy? | L3 |
| What exactly did I say yesterday? | L0 |
| Why did we choose Playwright? | L0/L2 |
| What are my coding preferences? | L3 |
| What happened during the previous debugging session? | L0/L2 |
The retrieval layer should therefore be intelligent.
Query
↓
Identify intent
↓
Select memory layer
↓
Retrieve
↓
Rank
↓
Build context
This is more efficient than searching every layer equally.
Active Recall vs Tool-Based Recall
Tencent Cloud’s current self-developed Agent integration guidance describes two recall patterns.
Active Recall
The agent retrieves memory before sending the user’s message to the LLM.
Conceptually:
User Message
↓
Memory Recall
↓
Relevant Memories
↓
Prompt
↓
LLM
This is predictable.
The application decides when retrieval happens.
Tool-Based Recall
The memory retrieval capability can instead be exposed to the LLM as a tool.
User
↓
LLM
↓
"Need more context"
↓
Memory Tool
↓
Retrieved Memory
↓
LLM
This gives the model more control over when additional information is required.
Tencent Cloud’s current self-developed Agent integration documentation describes both approaches and notes that they can be used together: proactive retrieval before the LLM and tool-based retrieval when additional information is needed. (Tencent Cloud)
Compare the Two Retrieval Strategies
| Feature | Active Recall | Tool Recall |
|---|---|---|
| Retrieval timing | Before LLM | During reasoning |
| Control | Application | LLM |
| Predictability | High | Moderate |
| Extra tool call | Usually no | Possible |
| Latency | Easier to optimize | Can increase |
| Flexibility | Lower | Higher |
| Best use | Common context | Deep/conditional lookup |
A practical architecture can combine both:
User Request
│
▼
Active Recall
│
▼
LLM
│
├── Enough context?
│ │
│ YES
│ ↓
│ Response
│
└── NO
↓
Memory Tool
↓
More Context
↓
LLM
This is a useful pattern for production agents.
Why Hybrid Retrieval Matters
Memory retrieval is not always purely semantic.
Suppose the user asks:
What is my project code name?
A keyword or exact lookup may be excellent.
But:
Why did we choose this authentication architecture?
may require semantic retrieval.
Tencent Cloud currently describes its Agent Memory retrieval as combining keyword and vector-semantic retrieval with fusion ranking. (Tencent Cloud)
Conceptually:
Query
│
┌─────────┴─────────┐
│ │
Keyword Search Semantic Search
│ │
└─────────┬─────────┘
↓
Fusion Ranking
↓
Relevant Memory
This is stronger than depending on only one retrieval method.
Keyword Search vs Semantic Search
Consider the query:
"Playwright"
Keyword retrieval can be excellent.
Now consider:
"What framework do we normally use
for browser automation?"
The stored memory might say:
"Our E2E tests use Playwright."
The exact word pattern may differ.
Semantic retrieval can recognize the conceptual relationship.
| Retrieval | Strength |
|---|---|
| Keyword | Exact terms |
| Semantic | Meaning |
| Hybrid | Meaning + exact matching |
For production agent memory, hybrid strategies can provide better coverage.
Why Ranking Comes After Retrieval
Suppose the system retrieves:
Memory A → Playwright
Memory B → Cypress
Memory C → Selenium
Memory D → GitHub Actions
Memory E → PostgreSQL
The query is:
How should I create a Playwright test?
Retrieval produced candidates.
Ranking decides:
A → Very high
D → Low/moderate
B → Low
C → Low
E → Irrelevant
The final context might contain:
Playwright
and perhaps:
TypeScript
The rest can be excluded.
This separation is important:
Retrieval
=
Find candidates
Ranking
=
Choose useful candidates
Memory Retrieval as a Pipeline
A production-oriented model is:
User Query
↓
Query Understanding
↓
Memory Routing
↓
Candidate Retrieval
↓
Keyword + Semantic Search
↓
Fusion
↓
Ranking
↓
Filtering
↓
Context Construction
↓
LLM
This is much more powerful than:
Query
↓
Database
↓
Everything found
↓
LLM
The latter can quickly produce context overload.
Context Overload Is a Real Problem
Imagine retrieving 200 memories.
Even if each memory is individually relevant, the combined context can become noisy.
200 memories
↓
Too much context
↓
More tokens
↓
More latency
↓
More cost
↓
More distraction
A better approach is:
200 candidates
↓
Ranking
↓
Top 20
↓
Filtering
↓
Top 5–10
↓
LLM
The exact number depends on the task.
The principle is:
Retrieve broadly enough to avoid missing useful information, then filter aggressively enough to protect the model’s context.
Coding Example: Layered Memory Retrieval
A conceptual Python implementation might look like:
async def retrieve_agent_context(query):
atomic = await memory.retrieve_atomic(
query=query
)
scenarios = await memory.retrieve_scenarios(
query=query
)
core = await memory.read_core()
return {
"atomic": atomic,
"scenarios": scenarios,
"core": core
}
The actual method names depend on the SDK/API version you use.
The architectural idea is what matters:
Atomic
+
Scenario
+
Core
↓
Context
Tencent Cloud’s current SDK documentation provides separate operations for different memory levels, including core-memory operations, while its integration guide describes recalling atomic, scenario, and core memory for agent context. (Tencent Cloud)
Parallel Retrieval Can Reduce Latency
If different memory retrieval operations do not depend on one another, they can be executed concurrently.
Conceptually:
import asyncio
atomic_task = retrieve_atomic(query)
scenario_task = retrieve_scenario(query)
core_task = retrieve_core()
atomic, scenario, core = await asyncio.gather(
atomic_task,
scenario_task,
core_task
)
Instead of:
Atomic
↓
Scenario
↓
Core
you can potentially achieve:
Atomic ─────┐
Scenario ───┼──→ Context
Core ───────┘
Tencent Cloud’s current self-developed Agent integration guidance specifically recommends parallel retrieval for the independent memory paths to reduce waiting time. (Tencent Cloud)
For production systems, always measure actual latency rather than assuming concurrency will automatically improve performance.
Memory Architecture and Agent Identity
Memory becomes dangerous if the system does not know whose memory it is retrieving.
Imagine:
User A
Project A
Agent A
Session A
and:
User B
Project B
Agent B
Session B
The retrieval system needs clear boundaries.
Conceptually:
context = {
"team_id": "team-01",
"agent_id": "qa-agent",
"user_id": "user-01",
"session_id": "session-100"
}
Tencent Cloud’s current Agent Memory integration documentation describes identifiers for agent context and discusses multi-agent isolation during SDK initialization. (Tencent Cloud)
This is not just a configuration detail.
It is a security boundary.
Multi-Agent Memory
Consider an organization with:
QA Agent
Developer Agent
Release Agent
Documentation Agent
Some knowledge can be shared:
Project:
Uses PostgreSQL
Other information should remain specialized:
QA Agent:
Test strategy
Release Agent:
Deployment procedures
Documentation Agent:
Documentation conventions
A useful architecture is:
Shared Memory
│
┌────────────┼────────────┐
│ │ │
QA Dev Release
Agent Agent Agent
│ │ │
QA-specific Dev-specific Release-specific
This creates a strategic question:
What should be shared and what should be isolated?
That question should be answered before multiple agents begin writing to the same memory environment.
Memory Architecture vs Traditional Chat History
Traditional chat history looks like:
Conversation 1
Conversation 2
Conversation 3
Conversation 4
Agent memory architecture looks more like:
Raw History
↓
Extracted Facts
↓
Scenario Knowledge
↓
Stable Knowledge
↓
Relevant Retrieval
| Chat History | Layered Agent Memory |
|---|---|
| Conversation-centric | Knowledge-centric |
| Mostly chronological | Hierarchical |
| Large context | Compressed context |
| Manual interpretation | Structured retrieval |
| Difficult to personalize | Designed for personalization |
| Historical record | Reusable agent knowledge |
Chat history still has value.
It can provide the original source.
But persistent memory adds another layer of abstraction.
Memory Traceability
One particularly important architectural concept is traceability.
Suppose the agent says:
"The project uses Playwright."
Where did that conclusion come from?
A traceable memory system can conceptually provide:
Core Memory
↓
Scenario Memory
↓
Atomic Memory
↓
Original Conversation
This matters when:
A user disputes the information
A memory becomes outdated
A test fails
An administrator investigates behavior
A compliance audit occurs
Without traceability:
Memory
↓
???
With traceability:
Memory
↓
Source
↓
Evidence
Tencent Cloud’s current Agent Memory documentation explicitly highlights white-box traceability across memory layers. (Tencent Cloud)
Interactive Exercise: Design the Memory Layers
Imagine this conversation:
User:
We are building a banking application.
User:
The backend uses Java.
User:
Our UI automation uses Playwright.
User:
The team runs tests through GitHub Actions.
User:
For authentication tests, we need extra security checks.
User:
Today I'm debugging the login flow.
Now classify the information.
Raw
Entire conversation
Atomic
Industry = Banking
Backend = Java
UI Automation = Playwright
CI = GitHub Actions
Authentication = Security-sensitive
Scenario
Authentication Testing
- Playwright
- GitHub Actions
- Additional security checks
- Login flow debugging
Core
The team uses Java on the backend and
Playwright for UI automation with GitHub Actions.
Notice how the information becomes increasingly compact and reusable.
That is the core idea behind layered memory.
The Strategic Question
Now ask yourself:
If the user asks:
"How should I test the login page?"
Which memory should I retrieve?
A good strategy might retrieve:
Core:
Playwright automation
Scenario:
Authentication testing
Current session:
Login debugging
But it probably should not retrieve:
Unrelated banking conversations
Old deployment logs
Random historical messages
That is context-aware memory retrieval.
A Useful Architecture Pattern
For many applications, the following pattern is a strong starting point:
USER REQUEST
│
▼
Query Analysis
│
▼
Active Recall
│
┌───────────┼───────────┐
▼ ▼ ▼
L1 L2 L3
Atomic Scenario Core
│ │ │
└───────────┼───────────┘
▼
Fusion + Rank
│
▼
Context Builder
│
▼
LLM
│
┌────────┴────────┐
│ │
Response Tool Call
│ │
└────────┬────────┘
▼
Memory Write
This provides a clean separation between:
Recall
Reason
Act
Remember
What Should Happen After the Response?
Memory architecture does not end when the LLM responds.
The conversation can produce new information.
For example:
User:
We have migrated from Cypress to Playwright.
The system should potentially recognize:
Old:
Cypress
New:
Playwright
This creates a memory update problem.
A mature system should not blindly create:
Cypress
Playwright
as two equally current facts.
It should understand the relationship:
Cypress
↓
Historical
Playwright
↓
Current
This is why memory lifecycle and conflict resolution are as important as retrieval.
Memory Architecture for Long-Running Tasks
Consider an AI agent performing a task for several hours.
The task might produce:
10,000 tool messages
2,000 lines of logs
Hundreds of search results
Multiple code changes
Many intermediate decisions
Keeping everything in the active context is inefficient.
A better architecture is:
Active Task
↓
Important State
↓
Short-Term Memory
↓
Context Compression
↓
Externalized Cold Data
↓
Retrieve Details When Needed
Tencent Cloud currently describes short-term memory in terms of context compression and management and describes the ability to offload long tool logs, code, and search results while retaining lightweight summaries in the active context. (Tencent Cloud)
This pattern is especially relevant to coding agents and long-running automation agents.
The Difference Between Compression and Deletion
This distinction is important.
Compression:
Large information
↓
Small representation
Deletion:
Large information
↓
Nothing
A memory architecture can use compression to reduce context pressure without necessarily destroying the underlying source.
For example:
100 tool messages
↓
Summary:
"Authentication API returns 401
after token refresh."
The detailed records can remain available for deeper investigation if the architecture supports that behavior.
This creates:
Fast path:
Summary
Deep path:
Original details
That is an excellent pattern for long-running agents.
Testing the Architecture
As an SDET, do not test only whether memory exists.
Test whether the architecture behaves correctly.
def test_memory_hierarchy():
conversation = create_conversation(
"Project uses Playwright with TypeScript."
)
process(conversation)
atomic = retrieve_atomic(
"What testing framework is used?"
)
assert "Playwright" in str(atomic)
Then test scenario-level retrieval:
def test_scenario_retrieval():
result = retrieve_scenario(
"How does our testing workflow operate?"
)
assert "Playwright" in str(result)
assert "GitHub Actions" in str(result)
And core memory:
def test_core_memory():
result = read_core()
assert result is not None
These tests validate the hierarchy rather than merely the storage endpoint.
Architecture-Level Test Matrix
| Test | What It Validates |
|---|---|
| L0 preservation | Source conversation retained |
| L1 extraction | Facts correctly extracted |
| L2 grouping | Related facts form useful scenarios |
| L3 stability | Core information remains consistent |
| Retrieval | Relevant layer is found |
| Ranking | Useful memories are prioritized |
| Isolation | Users/agents do not leak memory |
| Freshness | New information supersedes stale facts |
| Compression | Context remains manageable |
| Traceability | Higher-level memory can be investigated |
This is where the architecture becomes directly relevant to professional QA.
A Strategic Rule for Developers
When designing memory, avoid this:
One giant memory bucket
+
One search function
+
Everything goes into the prompt
Prefer:
Multiple memory levels
+
Clear scope
+
Hybrid retrieval
+
Ranking
+
Controlled context
+
Lifecycle management
+
Observability
The result is not merely more sophisticated.
It is easier to reason about.
It is easier to test.
And it is easier to debug.

Your Architecture Checklist
Before calling your agent memory architecture production-ready, ask:
□ Do I separate short-term and long-term memory?
□ Do I distinguish raw conversations from extracted facts?
□ Do I have scenario-level context?
□ Do I have stable core knowledge?
□ Can the system retrieve the appropriate layer?
□ Do I combine semantic and keyword retrieval where useful?
□ Do I rank retrieved candidates?
□ Do I control how much memory enters the LLM context?
□ Can I isolate users and agents?
□ Can I handle stale information?
□ Can I trace a memory back to its source?
□ Can I test each memory layer independently?
□ Can I measure retrieval latency?
□ Can the system survive memory-service failures?
If several answers are “no”, the problem may not be the memory database.
The problem may be the architecture surrounding it.
The Bigger Engineering Picture
The most important lesson from TencentDB Agent Memory architecture is that persistent memory is not one component.
It is a pipeline:
Capture
↓
Understand
↓
Extract
↓
Compress
↓
Organize
↓
Store
↓
Retrieve
↓
Rank
↓
Inject
↓
Reason
↓
Update
Each step affects the final agent experience.
A failure at any layer can produce apparently “bad AI”.
For example:
Bad answer
↓
Maybe bad model?
Not necessarily.
It could be:
Bad answer
↓
Wrong memory
↓
Wrong retrieval
↓
Wrong ranking
↓
Wrong context
↓
LLM response
That is why debugging AI agents increasingly requires understanding the entire context pipeline, not just the model.
The Key Architecture Insight
A useful way to think about persistent memory is:
Memory Storage
≠
Memory Architecture
Storage answers:
Where is the information?
Architecture answers:
What information exists?
Why was it stored?
What level does it belong to?
Who can access it?
When should it be retrieved?
How should it influence the model?
When should it be updated?
Can we trace it?
Can we test it?
That is the difference between simply connecting an AI agent to a memory service and actually designing a reliable memory system.
For developers, AI engineers, and SDETs, this distinction is critical because the quality of an agent increasingly depends on how effectively it manages context over time.
The strongest architecture is not the one that remembers the most.
It is the one that organizes information intelligently and delivers exactly the context the agent needs for the current task.
Designing Reliable Memory Retrieval for AI Agents
TencentDB Agent Memory becomes genuinely useful when an agent can retrieve the right information at the right moment instead of simply storing everything that has ever happened.
That distinction is critical.
Imagine an AI coding assistant has accumulated months of conversations:
Thousands of user messages
Hundreds of debugging sessions
Project decisions
Tool outputs
Code discussions
Testing preferences
Temporary errors
Old architectural decisions
A user now asks:
How should I write the checkout E2E test?
The agent does not need thousands of memories.
It needs a small, high-quality context such as:
Framework: Playwright
Language: TypeScript
CI: GitHub Actions
Testing style: Page Object Model
Current feature: Checkout
The real engineering challenge is therefore not how much the agent can remember.
It is:
How accurately can the system retrieve useful memory without overwhelming the model?
That makes retrieval one of the most important parts of a production memory architecture.

Retrieval Is More Than Database Search
A common beginner mistake is thinking about memory like this:
User Query
↓
Database Search
↓
Memory
↓
LLM
A production system is usually more sophisticated:
User Query
↓
Query Understanding
↓
Memory Routing
↓
Candidate Retrieval
↓
Keyword Search + Semantic Search
↓
Fusion
↓
Ranking
↓
Filtering
↓
Context Construction
↓
LLM
Each step answers a different question.
| Stage | Main Question |
|---|---|
| Query understanding | What does the user actually need? |
| Routing | Which memory type should be searched? |
| Retrieval | Which memories might be relevant? |
| Fusion | How do different search signals agree? |
| Ranking | Which candidates are most useful? |
| Filtering | Which candidates should be removed? |
| Context building | What should the LLM actually see? |
This layered approach is central to building reliable TencentDB Agent Memory implementations.
Start With the User’s Intent
Before retrieving anything, understand the query.
Consider:
What framework does our team use for browser automation?
This is probably a stable project fact.
Compare it with:
What happened when we debugged the checkout failure yesterday?
This is primarily historical task context.
And:
What am I currently working on?
This may require current session or scenario memory.
The same memory store can contain all three types of information.
The retrieval system should not treat them identically.
A simple conceptual router could look like:
def route_memory(query: str) -> str:
query = query.lower()
if "yesterday" in query or "last session" in query:
return "historical"
if "currently" in query or "right now" in query:
return "scenario"
if "usually" in query or "normally" in query:
return "core"
return "hybrid"
This is intentionally simple.
A production system can use an LLM classifier, rules, metadata, or a combination.
The strategic lesson is more important:
Do not retrieve every type of memory for every question.
Retrieval From Different Memory Levels
A hierarchical memory system can route a query toward different levels.
Consider these examples:
| Query | Likely Retrieval Target |
|---|---|
| What framework do we use? | Atomic/Core |
| How do we test checkout? | Scenario |
| Why did we choose Playwright? | Scenario/Raw |
| What did I tell you yesterday? | Raw |
| What are my coding preferences? | Core |
| What happened during the last debugging session? | Raw/Scenario |
This creates a routing model:
QUERY
│
▼
Intent Analysis
│
┌──────────────┼──────────────┐
▼ ▼ ▼
Raw Scenario Core
L0 L2 L3
│ │ │
└──────────────┼──────────────┘
▼
Ranked Context
The goal is not to retrieve everything.
The goal is to retrieve the smallest useful context.
Keyword Search: Excellent for Exact Facts
Suppose the memory contains:
"Our browser automation framework is Playwright."
And the user asks:
Which framework do we use: Playwright or Cypress?
A keyword search is highly effective.
It can immediately identify:
Playwright
Keyword search is particularly useful for:
- Product names
- Framework names
- Project names
- Error codes
- File names
- API endpoints
- Ticket IDs
- Exact terminology
For example:
def keyword_candidates(query, documents):
terms = query.lower().split()
return [
document
for document in documents
if any(term in document.lower() for term in terms)
]
This is simplistic, but it illustrates the principle.
Keyword retrieval asks:
"Do these words appear?"
Semantic Search: Excellent for Meaning
Now consider:
Which browser automation framework does the team normally use?
The stored memory might be:
"Our UI tests are written using Playwright."
The words are not identical.
But the meanings are closely related.
Semantic retrieval represents information in a vector space where conceptually similar content can be found even when exact words differ.
Conceptually:
User Query
↓
Embedding
↓
Vector Search
↓
Semantically Similar Memories
A simplified example:
query_embedding = embed(
"Which browser automation framework do we use?"
)
results = vector_store.search(
query_embedding,
top_k=10
)
The actual implementation depends on your chosen SDK and infrastructure.
Keyword vs Semantic Retrieval
Neither approach is universally superior.
| Capability | Keyword | Semantic |
|---|---|---|
| Exact names | Excellent | Good |
| Error codes | Excellent | Moderate |
| File names | Excellent | Moderate |
| Meaning similarity | Moderate | Excellent |
| Paraphrased queries | Weak/Moderate | Excellent |
| Technical identifiers | Excellent | Moderate |
| Concept discovery | Moderate | Excellent |
This is why hybrid retrieval is attractive.
Instead of asking:
Keyword OR Semantic?
ask:
How can Keyword + Semantic work together?
Hybrid Retrieval
Tencent Cloud’s current Agent Memory documentation describes a retrieval approach combining keyword and vector-semantic retrieval with fusion ranking.
The conceptual architecture is:
Query
│
┌──────────┴──────────┐
▼ ▼
Keyword Search Semantic Search
│ │
▼ ▼
Candidates A Candidates B
│ │
└──────────┬──────────┘
▼
Fusion Rank
│
▼
Final Candidates
Suppose keyword retrieval returns:
A = Playwright
B = GitHub Actions
C = Cypress
Semantic retrieval returns:
A = Playwright
D = Browser automation
E = E2E testing
Fusion can recognize that:
A
appears strongly in both result sets.
That increases confidence.
Why Fusion Matters
Imagine two independent signals:
Keyword score
Semantic score
You can conceptually combine them:
final_score = (
0.4 * keyword_score +
0.6 * semantic_score
)
The exact weights should not be treated as universal.
Your application should determine them experimentally.
For one application:
Keyword = 70%
Semantic = 30%
may work well.
For another:
Keyword = 20%
Semantic = 80%
may produce better retrieval.
This is where AI engineering becomes empirical rather than theoretical.
Measure.
Test.
Tune.
Repeat.
Ranking Is Where Retrieval Becomes Intelligent
Imagine retrieving 50 candidate memories.
You cannot simply send all 50 to the model.
You need ranking.
Conceptually:
50 candidates
↓
Relevance scoring
↓
Freshness
↓
Memory importance
↓
Scope
↓
Conflict handling
↓
Top 5–10
A useful scoring model could conceptually consider:
score = (
relevance * 0.50
+ freshness * 0.20
+ importance * 0.20
+ scope_match * 0.10
)
Again, these numbers are illustrative rather than a prescribed Tencent Cloud configuration.
The key insight is:
Similarity alone does not necessarily mean usefulness.
Similarity Is Not the Same as Relevance
Suppose a project has used both Cypress and Playwright.
The user asks:
Create a Playwright test.
Semantic search may retrieve both because they are conceptually related to browser testing.
But the agent should prioritize:
Playwright
over:
Cypress
This is why ranking needs more than semantic similarity.
You may need:
Query relevance
+
Currentness
+
Project scope
+
User scope
+
Task scope
+
Memory importance
Freshness Changes the Answer
Consider these memories:
2025:
"Our project uses Cypress."
2026:
"We migrated to Playwright."
Both are relevant to:
What browser automation framework do we use?
But only one represents the current state.
A retrieval system should therefore consider time.
Conceptually:
def freshness_score(age_days):
return 1 / (1 + age_days)
This is only a conceptual example.
A real system might use:
- Time decay
- Explicit versioning
- Valid-from timestamps
- Valid-until timestamps
- Update events
- Conflict resolution
The important idea is that newer does not always mean better, but stale information should not automatically compete equally with current information.
Scope Is Another Ranking Signal
Imagine the same organization has:
Project A → Playwright
Project B → Cypress
The user asks:
How do we write tests?
If the current project is Project A, retrieving Project B’s memory could create a bad answer.
Therefore:
Project match
should influence retrieval.
Conceptually:
if memory.project_id == current_project:
score += project_bonus
This becomes especially important in multi-project assistants.
User Isolation Is Not Optional
Now consider:
User A:
"My preferred language is Python."
User B:
"My preferred language is TypeScript."
A memory retrieval bug that mixes those records can produce incorrect personalization.
Worse, in a sensitive application it can become a security problem.
The conceptual boundary should be:
Tenant
↓
Application
↓
Agent
↓
User
↓
Session
The exact identifiers depend on the application architecture.
Tencent Cloud’s current Agent Memory integration documentation discusses agent context identifiers and multi-agent isolation, reinforcing the importance of establishing clear memory boundaries.
Memory Retrieval Should Be Context-Aware
Imagine these two queries:
"How do I test login?"
and:
"How did we fix the login issue yesterday?"
The first is likely asking for general or project-specific knowledge.
The second explicitly asks for historical context.
A good router might respond:
Query 1 → Core + Scenario
Query 2 → Raw + Scenario
This prevents unnecessary retrieval.
Active Recall vs Tool-Based Recall
There are two useful ways an agent can access memory.
Active Recall
The application retrieves memory before sending the prompt to the LLM.
User
↓
Application
↓
Memory Retrieval
↓
Context
↓
LLM
This is useful when certain context is almost always needed.
For example:
User Preferences
Project Configuration
Current Task
Tool-Based Recall
The model decides that it needs additional memory.
User
↓
LLM
↓
"I need historical context"
↓
Memory Tool
↓
Retrieved Memory
↓
LLM
Tencent Cloud’s current self-developed Agent integration guidance describes both active recall and tool-based recall patterns and notes that they can be combined.
Compare Active Recall and Tool Recall
| Factor | Active Recall | Tool-Based Recall |
|---|---|---|
| Retrieval control | Application | Model |
| Predictability | High | Moderate |
| Extra reasoning step | No | Possible |
| Latency control | Easier | More variable |
| Flexibility | Moderate | High |
| Best for | Common context | Conditional context |
A hybrid approach can look like:
User Request
↓
Basic Active Recall
↓
LLM
↓
Need more information?
│
YES
↓
Memory Tool
↓
Additional Context
↓
LLM
This gives the system a useful balance.
Don’t Give the Agent Too Much Memory
One of the biggest memory mistakes is assuming:
More context = Better answer
That is not necessarily true.
Consider:
Top 5 memories
versus:
Top 500 memories
The second option may contain more information but produce worse reasoning.
The context can become:
Noisy
Redundant
Conflicting
Expensive
Slow
Distracting
A better strategy is:
Retrieve many candidates
↓
Rank
↓
Filter
↓
Compress
↓
Send only useful context
Memory Deduplication
Suppose retrieval returns:
Memory 1:
Project uses Playwright.
Memory 2:
Playwright is used for browser tests.
Memory 3:
Browser automation is implemented with Playwright.
Memory 4:
E2E tests use Playwright.
Four memories may effectively represent one fact.
A context builder can consolidate them:
The project uses Playwright for browser and E2E automation.
Conceptually:
memories = retrieve(query)
deduplicated = deduplicate(memories)
context = summarize(deduplicated)
This reduces token consumption and improves clarity.
Contradiction Detection
Deduplication is not enough.
Consider:
Memory A:
Database = MySQL
Memory B:
Database = PostgreSQL
This is not duplication.
It is a contradiction.
The system needs to investigate:
Which is current?
Which project?
Which environment?
Which date?
A useful representation could be:
{
"fact": "database",
"value": "PostgreSQL",
"valid_from": "2026-04-01",
"previous_value": "MySQL"
}
This makes memory more like a versioned knowledge system rather than a simple document collection.
Retrieval and Memory Importance
Not every memory deserves equal priority.
Consider:
Important:
User prefers concise responses.
Temporary:
User asked about a random movie.
The first may be useful across hundreds of conversations.
The second may never matter again.
A memory system can therefore conceptually assign importance:
memory = {
"content": "User prefers concise responses",
"importance": 0.92
}
The exact scoring mechanism depends on the application.
But the strategic question should always be:
Will this information improve future decisions?
If not, permanent storage may not be necessary.
Retrieval Testing for QA Engineers
This is where memory architecture becomes particularly interesting for SDETs.
Do not only test:
HTTP 200
Test:
Was the correct memory retrieved?
Was the wrong memory excluded?
Was stale memory suppressed?
Was user isolation preserved?
Was the context size acceptable?
A simple retrieval test:
def test_retrieves_playwright_memory():
result = memory.search(
"What framework do we use for browser testing?"
)
assert "Playwright" in result
Now create a negative test:
def test_does_not_prefer_old_cypress_memory():
result = memory.search(
"What framework do we currently use?"
)
assert "Playwright" in result
And an isolation test:
def test_user_memory_isolation():
result = memory.search(
"What language does this user prefer?",
user_id="user-a"
)
assert "user-b-private-data" not in str(result)
This is a much more meaningful test strategy.
Build a Retrieval Evaluation Dataset
For serious systems, create a dataset like:
| Query | Expected Memory | Wrong Memory |
|---|---|---|
| What framework do we use? | Playwright | Cypress |
| Which CI system do we use? | GitHub Actions | Jenkins |
| What database is current? | PostgreSQL | MySQL |
| What happened yesterday? | Recent session | Old session |
| What is my coding preference? | User preference | Another user |
Then evaluate:
Precision
Recall
MRR
Hit Rate
Latency
Context Size
This turns memory retrieval into something measurable.
Precision vs Recall
A simple mental model:
Precision
=
How many retrieved memories were actually useful?
Recall
=
How many useful memories did we successfully retrieve?
Suppose the correct memories are:
A B C
and the system retrieves:
A B C D E F
Recall is excellent.
But precision may suffer because:
D E F
are noise.
Now imagine retrieving:
A
Precision may be excellent.
But recall is poor because:
B C
were missed.
A production system needs a practical balance.
Retrieval Evaluation Loop
A useful engineering cycle is:
Collect Queries
↓
Define Expected Memories
↓
Run Retrieval
↓
Measure Results
↓
Inspect Failures
↓
Tune Ranking
↓
Repeat
This should become part of your AI testing workflow.
Observability Matters
When an agent gives a wrong answer, you need to know:
What did it retrieve?
Why did it retrieve it?
What did it rank highest?
What context reached the model?
A useful trace could look like:
{
"query": "What framework do we use?",
"retrieved": 20,
"selected": 5,
"top_memory": "Playwright",
"score": 0.94,
"latency_ms": 82
}
You do not necessarily expose all internal diagnostics to end users.
But developers need observability.
Without it:
Bad answer
↓
???
With it:
Bad answer
↓
Wrong memory
↓
Wrong ranking
↓
Fix retrieval
This can dramatically reduce debugging time.
A Practical Retrieval Architecture
A strong conceptual architecture for an AI application could be:
USER QUERY
│
▼
Query Classifier
│
▼
Memory Router
│
┌──────────────┼──────────────┐
▼ ▼ ▼
Raw/L0 Atomic/L1 Core/L3
│ │ │
└──────────────┼──────────────┘
▼
Keyword + Vector Search
│
▼
Fusion Ranking
│
▼
Freshness Filter
│
▼
Scope Validation
│
▼
Deduplication
│
▼
Context Builder
│
▼
LLM
│
▼
Memory Update
This architecture separates concerns.
Each component can be independently tested.
A Developer’s Design Exercise
Imagine you are building a customer-support agent.
The memory contains:
Customer:
Ali
Product:
Enterprise Plan
Issue:
API rate limit
Previous resolution:
Quota increased
Preference:
Email communication
The customer asks:
I'm having the same API problem again.
What should the agent retrieve?
Think before reading the answer.
A sensible context might be:
Customer identity
+
Enterprise plan
+
Previous API rate-limit issue
+
Previous resolution
+
Current conversation
But it probably does not need:
Unrelated support tickets
Old marketing conversations
Internal discussions about other customers
This exercise demonstrates the central principle:
Relevant memory is task-dependent.
TencentDB Agent Memory and Context Engineering
Memory retrieval should ultimately serve context engineering.
Think of the pipeline as:
Memory
↓
Retrieval
↓
Selection
↓
Context
↓
Reasoning
The memory service does not independently make the agent intelligent.
The application architecture determines how retrieved information influences the model.
This is why developers should measure the entire chain:
Retrieval Quality
+
Context Quality
+
Model Reasoning
=
Agent Quality
A highly accurate retrieval system can still produce poor answers if the context is badly formatted.
Format Retrieved Memory for the Model
Instead of dumping raw records:
Memory 1
Memory 2
Memory 3
construct structured context:
PROJECT CONTEXT
- Automation framework: Playwright
- Language: TypeScript
- CI: GitHub Actions
CURRENT TASK
- Checkout E2E testing
RELEVANT HISTORY
- Previous checkout tests use Page Objects.
This makes the information easier for the model to consume.
Conceptually:
context = f"""
PROJECT CONTEXT:
{project_memory}
CURRENT TASK:
{task_memory}
RELEVANT HISTORY:
{historical_memory}
"""
The exact prompt structure should be tested against your model and use case.
The Cost of Bad Retrieval
Poor retrieval can create a chain reaction:
Wrong retrieval
↓
Wrong context
↓
Wrong reasoning
↓
Wrong tool call
↓
Wrong action
↓
Bad user experience
For an AI coding agent, that could mean:
Wrong memory
↓
Wrong framework assumption
↓
Wrong test implementation
↓
Failed CI pipeline
For an enterprise assistant:
Wrong memory
↓
Wrong customer context
↓
Wrong recommendation
↓
Potential business impact
Memory retrieval is therefore not merely an optimization problem.
It is part of the agent’s correctness boundary.
Strategic Rules for Better Retrieval
Keep these principles in mind:
1. Route before retrieving.
2. Retrieve candidates, not everything.
3. Combine exact and semantic signals where useful.
4. Rank using more than similarity.
5. Consider freshness.
6. Respect user and project scope.
7. Deduplicate redundant memories.
8. Detect contradictions.
9. Control context size.
10. Measure retrieval quality continuously.
These principles make a memory system much easier to reason about.
A Simple Mental Model
Whenever you design TencentDB Agent Memory, think:
ASK
↓
UNDERSTAND
↓
ROUTE
↓
RETRIEVE
↓
RANK
↓
FILTER
↓
CONSTRUCT
↓
REASON
↓
UPDATE
If an AI agent remembers too little, investigate retrieval.
If it remembers irrelevant information, investigate ranking and filtering.
If it remembers outdated information, investigate freshness and lifecycle.
If it remembers another user’s information, investigate isolation.
If it consumes too many tokens, investigate context construction.
The memory database is only one piece of the system.
Architecture Review Challenge
Before implementing your own retrieval flow, answer these questions:
1. Which memory level should answer stable project questions?
2. Which memory level should answer historical questions?
3. When should semantic search be used?
4. When is keyword search better?
5. How will you combine the two?
6. How will stale information be handled?
7. How will users and projects be isolated?
8. How many memories should reach the LLM?
9. How will you test retrieval failures?
10. How will you observe why a memory was selected?
If you can answer all ten, you are no longer thinking about memory as simply a database feature.
You are designing an agent memory retrieval system.

The most effective memory system is not the one that retrieves the largest number of records.
It is the one that consistently delivers the smallest, most relevant, most trustworthy context required for the current decision.
That is the foundation of reliable AI-agent memory retrieval.
Building Memory Updates, Conflict Resolution, and Long-Running Agent Context
TencentDB Agent Memory becomes significantly more powerful when an AI agent can do more than retrieve old information. A reliable agent must also know when to create memory, when to update it, when to consolidate it, and when to leave it alone.
Imagine an AI coding assistant that initially learns:
Project uses Cypress.
Three months later, the developer says:
We migrated our E2E suite to Playwright.
A naive memory system may store both:
Cypress
Playwright
Now the agent has two apparently valid answers.
That is not memory.
That is memory pollution.
A useful persistent-memory architecture must understand the lifecycle of information:
Conversation
↓
Memory Candidate
↓
Extraction
↓
Validation
↓
Create / Update / Ignore
↓
Consolidation
↓
Retrieval
↓
Context
↓
New Evidence
↓
Memory Update
This makes memory a continuously evolving knowledge system rather than a static archive.

The Memory Write Problem
Retrieval receives most of the attention because it directly affects the answer the user sees.
But memory writing is equally important.
Suppose an agent receives:
User:
I prefer Playwright for browser automation.
A memory candidate could be:
{
"type": "preference",
"subject": "browser automation",
"value": "Playwright"
}
Later:
User:
For this project, we're moving to Cypress.
The system now needs to determine whether this means:
A. Global preference changed
B. Project-specific preference changed
C. Temporary experiment
D. Historical statement
E. Something else
The words alone may not be enough.
Context matters.
Create, Update, or Ignore?
A useful memory-writing decision can be represented as:
New Information
│
▼
Is it useful?
/ \
NO YES
│ │
Ignore ▼
Existing memory?
/ \
NO YES
│ │
Create Compare
│
┌───────────┼───────────┐
▼ ▼ ▼
Same Changed Contradiction
│ │ │
Ignore Update Resolve
This is a powerful pattern for production systems.
The agent should not write every sentence into permanent memory.
What Makes Information Worth Remembering?
A practical filter can ask:
Is this information:
✓ Stable?
✓ Reusable?
✓ Relevant to future tasks?
✓ User-specific?
✓ Project-specific?
✓ A meaningful decision?
✓ A recurring preference?
✓ An important constraint?
While information such as:
"Thanks!"
"Okay."
"Let's continue."
"That looks good."
normally has little value as persistent knowledge.
The strategic rule is simple:
Memory should capture information that can improve future decisions, not merely information that happened in the past.
Memory Candidate Extraction
A memory extraction layer can transform conversation into structured candidates.
For example:
def extract_memory_candidates(message):
candidates = []
if "prefer" in message.lower():
candidates.append({
"type": "preference",
"content": message
})
if "we use" in message.lower():
candidates.append({
"type": "project_fact",
"content": message
})
return candidates
This is intentionally simplistic.
A production implementation can use an LLM or structured extraction pipeline.
For example:
Conversation
↓
LLM Extraction
↓
Structured Memory Candidates
↓
Validation
The LLM can identify:
{
"memory_type": "project_fact",
"subject": "automation_framework",
"value": "Playwright",
"scope": "checkout-project"
}
The important architectural principle is separating:
Conversation Understanding
from:
Memory Persistence
Do not let the model directly decide that every extracted sentence should become permanent memory.
Add a Validation Layer
A safer architecture is:
LLM
↓
Memory Candidate
↓
Validation Rules
↓
Memory Store
For example:
def validate_memory(memory):
if not memory.get("content"):
return False
if memory.get("confidence", 0) < 0.70:
return False
return True
A validation layer can check:
- Required fields
- Confidence
- Scope
- Data sensitivity
- Memory type
- Duplicate status
- Existing conflicts
- Expiration requirements
This makes memory writes more deterministic.
Confidence Should Influence Persistence
Consider these two statements:
User:
Our production database is PostgreSQL.
versus:
User:
I think production might be using PostgreSQL.
They should not necessarily receive the same confidence.
Conceptually:
{
"content": "Production database is PostgreSQL",
"confidence": 0.95
}
versus:
{
"content": "Production database might be PostgreSQL",
"confidence": 0.55
}
The second may require more evidence before becoming durable memory.
This leads to an important design principle:
Confidence should influence memory persistence, not just answer generation.
Memory Scope Matters
One of the easiest ways to create bad memory is to store information without scope.
Consider:
User preference:
I prefer TypeScript.
This might be global.
But:
For Project Alpha, we use Python.
is project-specific.
The memory representation should preserve this difference:
{
"content": "Python",
"type": "language",
"scope": {
"project": "alpha"
}
}
while:
{
"content": "TypeScript",
"type": "language",
"scope": {
"user": "user-123"
}
}
Now retrieval can determine which fact has priority.
Global vs Project vs Session Memory
A useful hierarchy is:
User-Level
↓
Project-Level
↓
Agent-Level
↓
Session-Level
↓
Task-Level
For example:
| Memory | Scope |
|---|---|
| User prefers concise answers | User |
| Project uses Playwright | Project |
| QA agent uses a testing workflow | Agent |
| Current debugging state | Session |
| Current failing test | Task |
This prevents unrelated information from competing during retrieval.
Conflict Resolution
Now consider:
Memory A:
Project uses Cypress.
Memory B:
Project uses Playwright.
The system needs evidence.
A useful conflict-resolution process is:
Conflict
↓
Compare timestamps
↓
Compare scope
↓
Compare confidence
↓
Look for migration/change language
↓
Check supporting evidence
↓
Select current memory
↓
Preserve historical state
Do not simply delete the older memory.
The historical information can still matter.
Instead:
Cypress
Status: historical
Playwright
Status: current
This is far more useful.
Explicit Change Detection
Natural language often contains clues that information has changed.
Examples:
"We switched from Cypress to Playwright."
"We no longer use Jenkins."
"We migrated to PostgreSQL."
"The old API has been deprecated."
"We're testing a new framework."
A memory system should distinguish:
New Fact
from:
Changed Fact
A conceptual extraction format could be:
{
"operation": "update",
"old_value": "Cypress",
"new_value": "Playwright",
"subject": "E2E framework"
}
This makes memory evolution explicit.
Memory Versioning
Versioning provides another useful pattern.
Instead of:
database = PostgreSQL
store:
{
"subject": "database",
"versions": [
{
"value": "MySQL",
"valid_until": "2026-03-31"
},
{
"value": "PostgreSQL",
"valid_from": "2026-04-01"
}
]
}
Now the system can answer both:
What database do we use now?
and:
What database did we use before the migration?
That distinction becomes extremely valuable in enterprise systems.
Why Deletion Alone Is Dangerous
Suppose the system simply replaces:
Cypress
with:
Playwright
The current answer may be correct.
But you have lost:
When did the migration happen?
Why did it happen?
What was used previously?
Which tests still depend on the old framework?
Historical memory can be useful for:
- Debugging
- Auditing
- Migration analysis
- Incident investigation
- Architecture decisions
Therefore:
Update
≠
Erase history
Memory Consolidation
As an agent interacts with users over time, multiple memories may represent the same underlying fact.
For example:
User prefers concise responses.
User likes short answers.
User doesn't want unnecessary explanations.
User prefers direct technical responses.
These could potentially be consolidated into:
User preference:
Prefers concise and direct technical responses.
The consolidation pipeline becomes:
Multiple Memories
↓
Similarity Detection
↓
Group Related Facts
↓
Resolve Conflicts
↓
Create Summary
↓
Preserve Sources
This reduces memory fragmentation.
Consolidation vs Deduplication
These concepts are related but different.
Deduplication removes repeated representations.
Playwright
Playwright
Playwright
becomes:
Playwright
Consolidation combines related information.
Uses Playwright
+
Uses TypeScript
+
Runs tests in GitHub Actions
becomes:
The project uses TypeScript-based Playwright
automation executed through GitHub Actions.
| Operation | Goal |
|---|---|
| Deduplication | Remove duplicates |
| Consolidation | Create higher-level knowledge |
| Summarization | Reduce length |
| Versioning | Preserve change history |
| Conflict resolution | Determine current truth |
A mature memory system benefits from all of them.
Long-Running Agents Change the Problem
Short conversations are relatively easy.
Long-running agents are different.
Imagine an autonomous coding agent working for six hours:
Task
↓
Planning
↓
Search
↓
Code changes
↓
Tests
↓
Failures
↓
Debugging
↓
More code
↓
More tests
↓
Deployment
The amount of context can become enormous.
A model cannot keep every intermediate observation in its active context indefinitely.
This is where short-term memory and compression become strategically important.
Context Compression
Imagine the agent has:
2,000 tool outputs
Instead of keeping all of them active:
2,000 outputs
↓
Important observations
↓
Compressed state
For example:
Current task:
Fix checkout authentication.
Important findings:
- Login endpoint returns 401 after token refresh.
- Token refresh request succeeds.
- Failure occurs when cached token is reused.
- Relevant file: auth/session.ts.
- Playwright test reproduces the issue.
That summary is dramatically smaller.
The raw information may still be preserved externally if deeper investigation becomes necessary.
Hot, Warm, and Cold Context
A useful way to think about long-running agents is:
HOT
Current task state
Current decisions
Immediate context
WARM
Recent useful history
Recent tool results
Scenario memory
COLD
Old conversations
Large logs
Historical tool outputs
Archived evidence
The agent should primarily operate on:
HOT + selected WARM
and retrieve:
COLD
only when required.
This resembles caching architecture.
Memory vs Cache
The comparison is useful.
| Cache | Persistent Memory |
|---|---|
| Optimizes access | Preserves knowledge |
| Usually temporary | Can be long-lived |
| Often key-based | Often semantic/contextual |
| Data may expire quickly | Data may evolve |
| Performance-oriented | Reasoning-oriented |
A cache asks:
Can I get this faster?
Memory asks:
Will this information help the agent make a better decision?
They can work together.
Memory vs RAG
Another important comparison is with Retrieval-Augmented Generation.
Traditional RAG often retrieves information from an external knowledge base:
Documents
↓
Chunking
↓
Embeddings
↓
Vector Search
↓
LLM
Agent memory is more dynamic:
Interaction
↓
Memory Extraction
↓
Memory Update
↓
Retrieval
↓
Agent
↓
New Interaction
↓
Memory Update
| RAG | Agent Memory |
|---|---|
| Often document-centric | Interaction-centric |
| Knowledge base | Evolving experience |
| Mostly external knowledge | User/project/task knowledge |
| Retrieval-focused | Read + write lifecycle |
| Documents are primary source | Conversations and events can be sources |
| Often relatively static | Continuously changing |
They are not mutually exclusive.
A sophisticated agent may use:
RAG
+
Agent Memory
+
Tool Results
+
Current Session
Combining RAG and Memory
Consider a customer-support agent.
RAG contains:
Product documentation
Pricing rules
Policies
Technical manuals
Memory contains:
Customer preferences
Previous issues
Previous resolutions
Account context
The current session contains:
Current complaint
The agent can combine all three:
User Request
│
┌───────────────┼────────────────┐
▼ ▼ ▼
RAG Memory Session
│ │ │
└───────────────┼────────────────┘
▼
Context Builder
↓
LLM
This is a much stronger architecture than treating memory as a replacement for RAG.
Tool Results as Temporary Memory
Agent tools create another category.
Suppose a coding agent executes:
pytest tests/checkout
and receives:
17 passed
2 failed
Should that become permanent memory?
Usually not.
It may be:
Current task state
rather than:
Long-term project knowledge
But if the agent discovers:
Checkout tests consistently fail because
the payment sandbox requires a specific token.
that may be valuable future knowledge.
This creates another decision:
Tool Output
↓
Temporary observation
↓
Does it contain reusable knowledge?
/ \
NO YES
↓ ↓
Discard Persist
The Agent Memory Promotion Pipeline
A useful conceptual architecture is:
Raw Observation
↓
Short-Term Context
↓
Importance Evaluation
↓
Memory Candidate
↓
Validation
↓
Scope Assignment
↓
Conflict Detection
↓
Consolidation
↓
Long-Term Memory
This prevents temporary noise from automatically becoming permanent knowledge.
A Practical Example
Suppose an AI coding agent receives:
User:
Our checkout tests are flaky because the
payment sandbox sometimes responds slowly.
A candidate memory might be:
{
"type": "scenario",
"topic": "checkout testing",
"fact": "Payment sandbox can respond slowly",
"scope": "checkout-project",
"confidence": 0.88
}
Later:
User:
We fixed the payment sandbox timeout issue.
Now the memory should evolve.
Instead of keeping:
Payment sandbox is slow.
as permanently active knowledge, the system could update it:
{
"topic": "checkout testing",
"status": "resolved",
"previous_issue": "payment sandbox latency"
}
This is knowledge lifecycle management.
Why Stale Memory Is Dangerous
Stale memory can be worse than missing memory.
Suppose an agent remembers:
Deployment platform = Jenkins
but the organization migrated to:
GitHub Actions
The agent may generate:
pipeline:
agent: jenkins
which is technically plausible but operationally wrong.
This creates:
Stale Memory
↓
Incorrect Context
↓
Confident Model Response
↓
Bad Action
Therefore memory systems need freshness strategies.
Expiration Policies
Not every memory should live forever.
For example:
Current debugging state
→ expires quickly
Temporary feature flag
→ expires after deployment
Project architecture
→ long-lived
User preference
→ potentially long-lived
Historical conversation
→ retained according to policy
A conceptual metadata model:
{
"memory": "Current checkout failure",
"created_at": "2026-08-11T09:00:00Z",
"expires_at": "2026-08-12T09:00:00Z"
}
The actual retention policy should depend on the application’s requirements.
Memory Lifecycle Testing
As an SDET, test the lifecycle rather than just the endpoint.
For example:
def test_new_memory_is_created():
add_observation("Project uses Playwright")
memory = search_memory("browser framework")
assert "Playwright" in str(memory)
Then:
def test_memory_can_be_updated():
add_observation("Project uses Cypress")
add_observation("Project migrated to Playwright")
memory = search_memory("current browser framework")
assert "Playwright" in str(memory)
And:
def test_old_memory_is_not_current():
memory = search_memory("current browser framework")
assert "Cypress" not in str(memory)
Then test historical retrieval separately:
def test_historical_memory_remains_traceable():
memory = search_memory("previous browser framework")
assert "Cypress" in str(memory)
This is much stronger than testing only whether a database record exists.
Memory Mutation Tests
You can also test unusual sequences.
Create A
Update A → B
Update B → C
Retrieve current
Retrieve historical
Delete C
Restore B
A robust system should have predictable behavior.
Create a mutation matrix:
| Scenario | Expected Result |
|---|---|
| New fact | Create |
| Duplicate fact | Deduplicate |
| Updated fact | Replace/current + preserve history |
| Contradiction | Resolve |
| Temporary fact | Expire |
| Low-confidence fact | Avoid promotion |
| User-specific fact | Isolate |
| Project-specific fact | Scope |
| Historical query | Retrieve historical state |
This turns memory into a testable state machine.
Memory as a State Machine
You can model a memory item as:
CANDIDATE
↓
VALIDATED
↓
ACTIVE
↓
UPDATED
↓
HISTORICAL
↓
ARCHIVED
With alternative paths:
CANDIDATE → REJECTED
ACTIVE → EXPIRED
ACTIVE → DELETED
This gives engineering teams a clear lifecycle.
A Simple State Model
from enum import Enum
class MemoryState(Enum):
CANDIDATE = "candidate"
ACTIVE = "active"
UPDATED = "updated"
HISTORICAL = "historical"
EXPIRED = "expired"
REJECTED = "rejected"
Then:
def promote(memory):
if memory.confidence >= 0.8:
memory.state = MemoryState.ACTIVE
else:
memory.state = MemoryState.REJECTED
Again, this is an architectural illustration rather than a required Tencent Cloud implementation.
Memory Observability
When something goes wrong, you need visibility into:
What memory was created?
Why was it created?
What evidence supported it?
What scope was assigned?
What memory did it replace?
When was it updated?
Why was it retrieved?
A useful trace might look like:
{
"memory_id": "mem-123",
"operation": "update",
"old_value": "Cypress",
"new_value": "Playwright",
"reason": "explicit migration statement",
"confidence": 0.96,
"scope": "checkout-project"
}
This kind of observability is extremely valuable during production debugging.
What Should Never Become Memory Automatically?
Be conservative.
Do not blindly persist:
Temporary thoughts
Unverified assumptions
Random tool outputs
One-time conversational filler
Sensitive information without an appropriate policy
Low-confidence guesses
Outdated transient state
Instead, use:
Capture
↓
Classify
↓
Validate
↓
Persist selectively
Selective memory is usually more useful than maximum memory.
Interactive Challenge
Imagine your agent sees these statements:
1. "I usually prefer Python."
2. "For this project, we're using TypeScript."
3. "Yesterday the API returned 500."
4. "We migrated from MySQL to PostgreSQL."
5. "Thanks!"
6. "The new authentication design should be used for all future services."
Classify them.
A reasonable strategy is:
| Statement | Memory Treatment |
|---|---|
| Python preference | User-level memory |
| TypeScript | Project-level memory |
| API 500 | Temporary/session memory |
| MySQL → PostgreSQL | Versioned project memory |
| Thanks | Ignore |
| Authentication design | Potential core/project memory |
Notice how the exact same conversation can produce completely different persistence decisions.
That is intelligent memory management.
Compare Simple Storage With Memory Lifecycle Management
| Simple Storage | Lifecycle-Based Memory |
|---|---|
| Save everything | Save useful information |
| No scope | Explicit scope |
| No versions | Version-aware |
| No confidence | Confidence-aware |
| No conflict resolution | Conflict resolution |
| No expiration | Lifecycle policies |
| No consolidation | Knowledge consolidation |
| Hard to debug | Observable |
| History becomes noisy | History remains useful |
This is the difference between:
Database-backed chat history
and:
Agent memory architecture
Designing for Production
A practical architecture can be divided into six responsibilities:
1. Capture
Collect conversations and observations.
2. Extract
Identify candidate knowledge.
3. Validate
Check quality, confidence, and policy.
4. Store
Persist memory with scope and metadata.
5. Retrieve
Find useful information for the current task.
6. Evolve
Update, consolidate, expire, and preserve history.
Visualized:
AGENT MEMORY SYSTEM
Capture → Extract → Validate → Store
↓
Retrieve
↓
Agent
↓
Evolve
↓
Store Again
This creates a continuous feedback loop.
The Most Important Design Principle
A useful persistent memory system should behave less like:
INSERT INTO memories
and more like:
UNDERSTAND
↓
EVALUATE
↓
DECIDE
↓
CREATE / UPDATE / IGNORE
↓
CONSOLIDATE
↓
RETRIEVE
↓
LEARN FROM NEW EVIDENCE
That mindset changes how you design the entire system.

The key lesson is that persistent memory should not be treated as a passive storage layer.
It is an active information lifecycle.
The agent observes something, decides whether it deserves persistence, assigns scope and confidence, compares it with existing knowledge, resolves conflicts, and eventually retrieves it when the information can improve a future decision.
That lifecycle is what turns stored conversation data into useful agent intelligence.
Production Strategy: Making Agent Memory Reliable, Safe, and Measurable
TencentDB Agent Memory becomes truly valuable when memory is treated as an engineering system rather than simply another storage mechanism. Retrieval, persistence, consolidation, isolation, observability, and testing must work together if an agent is expected to operate reliably over weeks or months.
A useful way to think about a production agent is:
User
↓
Agent
↓
Current Context
↓
Memory Retrieval
↓
Reasoning
↓
Tool Execution
↓
New Evidence
↓
Memory Evaluation
↓
Memory Update
The loop never really ends.
Every interaction can potentially improve the agent’s understanding, but every interaction can also introduce noise. The engineering challenge is therefore to create a controlled learning loop.

From Prototype to Production
A prototype might look like this:
memory.save(message)
and later:
context = memory.search(query)
That can be enough to demonstrate the idea.
Production systems need considerably more control:
Capture
↓
Classify
↓
Validate
↓
Scope
↓
Persist
↓
Index
↓
Retrieve
↓
Rank
↓
Filter
↓
Construct Context
↓
Generate Response
↓
Observe
↓
Evaluate
↓
Update Memory
Each stage should have a clear responsibility.
If an agent produces an incorrect answer, you should be able to determine whether the problem originated from:
Memory extraction
Retrieval
Ranking
Stale information
Scope
Context construction
Model reasoning
Tool execution
That is the difference between an AI demo and an AI system that can be operated.
Build Memory Around Clear Data Contracts
A memory record should contain more than a text string.
A practical conceptual structure is:
{
"id": "mem_123",
"content": "Project uses Playwright for E2E testing.",
"type": "project_fact",
"scope": {
"project_id": "checkout-app"
},
"confidence": 0.94,
"importance": 0.88,
"status": "active",
"created_at": "2026-08-11T09:00:00Z",
"updated_at": "2026-08-11T09:00:00Z"
}
The exact schema depends on the implementation, but the principle is universal:
Memory needs metadata because meaning depends on context.
Without metadata, two identical sentences can become impossible to distinguish.
For example:
"We use Python."
could mean:
User preference
Project requirement
Temporary experiment
Historical fact
Current production configuration
The content alone does not tell you which one it is.
Metadata Is a Retrieval Signal
Metadata should not merely exist for administration.
It can improve retrieval.
Suppose a user asks:
What framework does this project use?
You could combine:
final_score = (
semantic_score
+ scope_score
+ freshness_score
+ importance_score
)
Conceptually, the ranking system becomes:
Semantic relevance
+
Project match
+
User match
+
Freshness
+
Importance
↓
Final ranking
This is more powerful than pure vector similarity.
Scope Isolation Should Be Designed First
Imagine an application serving 10,000 users.
A memory query should never behave like:
SELECT * FROM memories
WHERE content LIKE '%Python%';
without appropriate isolation.
Instead, the conceptual query should include identity boundaries:
SELECT *
FROM memories
WHERE tenant_id = ?
AND user_id = ?
AND project_id = ?;
The exact implementation depends on your architecture and database layer.
The principle is critical:
Tenant
↓
Application
↓
User
↓
Project
↓
Agent
↓
Session
The narrower the context, the smaller the chance of accidental memory leakage.
Security Is Part of Memory Architecture
Persistent memory can contain information that users did not expect to remain available indefinitely.
For example:
Personal preferences
Project decisions
Business information
Conversation history
Credentials mentioned accidentally
Internal architecture
Customer information
A production design should therefore establish:
What can be stored?
Who can access it?
How long can it remain?
Can it be deleted?
Can it be exported?
Can it be audited?
This should be defined before large-scale deployment.
A useful policy model is:
Memory Type
↓
Sensitivity Classification
↓
Retention Policy
↓
Access Policy
↓
Storage
Do not make persistence an uncontrolled side effect of conversation.
Memory and Privacy Boundaries
Consider a customer-support agent.
The user says:
My account number is 123456.
The application should not automatically assume:
Store permanently.
Instead:
Message
↓
Sensitive-data detection
↓
Policy evaluation
↓
Store / Mask / Reject
A safer architecture separates:
Useful personalization
from:
Information that should not become long-term memory
This is especially important when memory is persistent.
Retrieval Quality Is a Product Metric
Many teams measure:
Response latency
Token usage
API errors
but forget to measure retrieval quality.
Add metrics such as:
Retrieval hit rate
Top-k accuracy
Precision
Recall
MRR
Context relevance
Stale-memory rate
Duplicate-memory rate
Conflict rate
Memory write acceptance rate
Now you can observe memory as a system.
For example:
Query: "What browser framework do we use?"
Expected:
Playwright
Retrieved:
Playwright
Cypress
Selenium
Top result:
Playwright
That is measurable.
Build a Golden Memory Dataset
One of the most useful strategies for AI testing is a golden dataset.
Create records such as:
[
{
"query": "What browser automation framework do we use?",
"expected": "Playwright"
},
{
"query": "Which CI system runs the tests?",
"expected": "GitHub Actions"
},
{
"query": "What database are we using now?",
"expected": "PostgreSQL"
}
]
Then execute retrieval against every record.
for case in golden_dataset:
result = memory.search(case["query"])
assert case["expected"] in result
This creates a regression suite for memory.
Now a ranking change can be evaluated before deployment.
Test Positive and Negative Retrieval
Positive testing asks:
Did we retrieve the correct memory?
Negative testing asks:
Did we avoid retrieving misleading memory?
For example:
def test_current_framework():
result = memory.search(
"What framework do we currently use?"
)
assert "Playwright" in result
assert "Cypress" not in result
Negative retrieval tests are extremely valuable when your memory contains historical information.
The system should know that:
Relevant historically
does not always mean:
Relevant now
Test Temporal Reasoning
Create memories with explicit time relationships:
2025:
Cypress
2026:
Playwright
Then test:
Current framework?
→ Playwright
Framework before migration?
→ Cypress
This tests whether your memory architecture understands time.
A useful test matrix is:
| Query | Expected |
|---|---|
| Current framework | Playwright |
| Previous framework | Cypress |
| Framework used in 2025 | Cypress |
| Framework used in 2026 | Playwright |
This is much more realistic than testing only one static answer.
Test Scope Resolution
Suppose:
Project A → Cypress
Project B → Playwright
Run:
result = memory.search(
"What framework do we use?",
project_id="project-b"
)
Expected:
Playwright
Then:
result = memory.search(
"What framework do we use?",
project_id="project-a"
)
Expected:
Cypress
This verifies that memory retrieval is context-aware.
Test Cross-User Isolation
Create:
User A:
Preferred language = Python
User B:
Preferred language = TypeScript
Then:
result = memory.search(
"What language does the user prefer?",
user_id="user-a"
)
assert "Python" in result
assert "TypeScript" not in result
This is both a functional and security test.
A memory system should never pass this test accidentally.
It should pass it by architecture.
Test Memory Mutation
Memory should be tested as a stateful system.
Example:
memory.create(
subject="framework",
value="Cypress"
)
memory.update(
subject="framework",
value="Playwright"
)
Then:
current = memory.get_current("framework")
history = memory.get_history("framework")
Expected:
Current:
Playwright
History:
Cypress → Playwright
This validates both current knowledge and historical traceability.
Test Duplicate Detection
Send the same fact multiple times:
memory.add("Project uses Playwright.")
memory.add("Project uses Playwright.")
memory.add("The project uses Playwright for E2E tests.")
The system should not blindly create three independent permanent records.
A reasonable outcome could be:
One consolidated fact
+
Multiple evidence references
That keeps the knowledge base compact without losing provenance.
Test Contradictory Evidence
Now create:
Project uses Playwright.
Project uses Cypress.
Project migrated from Cypress to Playwright.
The system should interpret the third statement as evidence of transition rather than simply storing three competing facts.
A useful conceptual result:
{
"subject": "test_framework",
"current": "Playwright",
"previous": "Cypress",
"status": "migrated"
}
This demonstrates why memory needs reasoning around updates.
Provenance Makes Memory Trustworthy
A memory record should ideally answer:
Where did this fact come from?
For example:
{
"content": "Project uses Playwright",
"source": {
"type": "conversation",
"conversation_id": "conv_456",
"message_id": "msg_789"
}
}
Provenance is valuable because a developer can inspect the original evidence when a memory looks suspicious.
Without provenance:
Memory says X.
With provenance:
Memory says X
because the user explicitly stated X
during conversation Y.
That is much easier to trust and debug.
Confidence and Provenance Work Together
Consider:
Source A:
User explicitly says:
"We migrated to Playwright."
Source B:
Agent infers:
"Tests may be using Playwright."
These should not necessarily have equal confidence.
Conceptually:
Explicit user statement
→ High confidence
Observed repeated behavior
→ Medium/high confidence
Model inference
→ Lower confidence
The source should therefore influence the memory score.
score = (
confidence * 0.4
+ source_reliability * 0.3
+ relevance * 0.3
)
The values are illustrative.
The important concept is combining evidence quality with semantic relevance.
Memory Consolidation for Long Conversations
Consider a month of interactions:
Day 1:
Uses Playwright.
Day 7:
Playwright tests use Page Objects.
Day 15:
Checkout suite uses Playwright.
Day 25:
CI executes Playwright tests.
Day 30:
Playwright is now the team's standard UI framework.
A naive system could create five memories.
A consolidated representation could become:
Project testing architecture:
The team uses Playwright as its standard UI/E2E
framework, with Page Object patterns and CI execution.
This is more useful during retrieval.
However, the individual source memories can remain available for provenance.
Summarization Should Not Destroy Evidence
Bad compression:
Project uses Playwright.
Potentially useful information was lost:
Page Object pattern
CI integration
Checkout-specific usage
Migration history
Better compression:
The project uses Playwright as its standard UI/E2E framework.
Tests follow Page Object patterns and execute in CI.
Then retain source references.
This gives the agent concise context while preserving traceability.
Context Budgeting
Every retrieved memory consumes context.
Suppose:
10 memories × 200 tokens
equals approximately:
2,000 tokens
Now imagine:
50 memories × 200 tokens
That becomes:
10,000 tokens
The agent may spend more reasoning capacity processing irrelevant information.
A better pipeline is:
Retrieve 50
↓
Rank 20
↓
Filter 10
↓
Compress 5
↓
Send 5
The numbers are examples.
The strategic principle is:
Candidate retrieval can be broad; model context should be selective.
Retrieval Depth Should Depend on Query Complexity
A simple query:
What framework do we use?
may need only a few memories.
A complex query:
Why did we migrate from Cypress to Playwright,
and what changed in our CI pipeline?
may require:
Historical memories
Architecture decisions
CI configuration
Migration context
Recent project state
Therefore retrieval depth can be dynamic.
Simple question
→ Small retrieval budget
Complex historical question
→ Larger retrieval budget
This can reduce both latency and noise.
Latency Is Part of the Design
A memory architecture can be accurate but too slow.
Consider:
Query
↓ 50 ms
Memory search
↓ 100 ms
Reranking
↓ 200 ms
Compression
↓ 150 ms
LLM
The memory pipeline itself can become a significant part of response time.
Measure:
Retrieval latency
Ranking latency
Compression latency
Database latency
Network latency
A useful trace:
{
"memory_search_ms": 74,
"rerank_ms": 41,
"compression_ms": 28,
"context_build_ms": 9
}
This allows optimization based on evidence rather than assumptions.
Quality vs Latency
There is often a trade-off.
| Strategy | Quality | Latency |
|---|---|---|
| Keyword only | Moderate | Low |
| Vector only | High for semantic queries | Low/Moderate |
| Hybrid retrieval | High | Moderate |
| Hybrid + reranking | Very high | Higher |
| Hybrid + reranking + compression | Very high | Highest |
Do not automatically choose the most complicated architecture.
Instead ask:
What level of retrieval quality does this application require?
A personal assistant and an enterprise compliance agent may have very different requirements.
When Simplicity Wins
For a small application:
User
↓
Semantic Retrieval
↓
Top 5 memories
↓
LLM
may be completely adequate.
For a large multi-user platform:
User
↓
Intent Router
↓
Scoped Retrieval
↓
Hybrid Search
↓
Reranking
↓
Freshness
↓
Conflict Resolution
↓
Deduplication
↓
Compression
↓
LLM
may be justified.
The correct architecture follows the problem.
Use Memory as a Decision Support Layer
A common mistake is asking memory to generate answers.
Memory should provide evidence.
Think:
Memory
↓
Evidence
↓
LLM
↓
Reasoning
not:
Memory
↓
Final Answer
For example:
Memory:
The project migrated to Playwright in April.
The model can then reason:
Current date = August
Current framework = Playwright
Memory provides the evidence.
The agent provides the reasoning.
Memory Should Support Agent Planning
Consider a coding agent that remembers:
Project uses Playwright.
Tests use Page Objects.
CI runs GitHub Actions.
The user asks:
Add a checkout regression test.
The agent can construct a plan:
1. Inspect checkout Page Object.
2. Reuse Playwright conventions.
3. Add regression scenario.
4. Run existing test command.
5. Validate CI-compatible behavior.
This demonstrates why memory is not merely personalization.
It can influence planning and execution.
Memory + Tools
A production agent often looks like:
┌──────────────┐
│ Agent │
└──────┬───────┘
│
┌────────────┼────────────┐
▼ ▼ ▼
Memory RAG Tools
│ │ │
└────────────┼────────────┘
▼
Context
↓
Model
Each source answers a different question.
Memory:
What have we learned?
RAG:
What does the documentation say?
Tools:
What is happening right now?
This separation makes agent architecture easier to reason about.
An SDET’s Memory Test Pyramid
Memory testing can follow a pyramid.
E2E
/ \
Agent behavior
/ \
Retrieval tests Security tests
/ \ / \
Unit tests Ranking Isolation Policy
At the bottom:
Schema validation
Metadata validation
Memory state transitions
In the middle:
Retrieval accuracy
Ranking
Deduplication
Conflict resolution
At the top:
End-to-end agent behavior
This gives good coverage without relying exclusively on expensive agent-level tests.
A Practical Memory QA Matrix
| Area | Example Test |
|---|---|
| Creation | New useful fact is stored |
| Validation | Low-confidence fact is rejected |
| Retrieval | Correct fact appears |
| Ranking | Most relevant fact ranks first |
| Scope | Project memory stays isolated |
| Security | User memory cannot cross boundaries |
| Freshness | Current fact beats stale fact |
| Conflict | Contradictory facts are resolved |
| Deduplication | Repeated facts consolidate |
| Versioning | Historical state remains accessible |
| Expiration | Temporary memory disappears |
| Compression | Important information survives |
| Observability | Memory decision is traceable |
This turns memory into a first-class test domain.
Interactive Architecture Exercise
Imagine you are building an AI QA assistant.
It knows:
Project:
Playwright + TypeScript
Team preference:
Page Object Model
Current task:
Checkout regression
Recent failure:
Payment sandbox timeout
Historical framework:
Cypress
The user asks:
Create a checkout regression test.
Which memories should be retrieved?
Think about it before reading the suggested context.
A strong retrieval set would probably include:
Project:
Playwright + TypeScript
Team preference:
Page Object Model
Current task:
Checkout regression
Recent failure:
Payment sandbox timeout
The historical Cypress memory probably does not belong in the active context unless the user asks about migration history.
This illustrates an important rule:
A memory can be relevant to the project but irrelevant to the current decision.
Production Architecture Checklist
Before deploying an agent memory system, ask:
□ Do memories have explicit scope?
□ Can memory records be versioned?
□ Can stale information be identified?
□ Are contradictions detectable?
□ Are duplicate memories consolidated?
□ Is sensitive information controlled?
□ Is user isolation enforced?
□ Is project isolation enforced?
□ Can retrieval quality be measured?
□ Is there a golden evaluation dataset?
□ Are negative retrieval tests included?
□ Is provenance available?
□ Are retrieval decisions observable?
□ Is context size controlled?
□ Are memory writes tested?
□ Are memory updates tested?
□ Are expiration policies defined?
If several boxes remain unchecked, the memory layer is probably not production-ready.
The Strategic Architecture
A mature TencentDB Agent Memory design can be viewed as seven connected systems:
1. Memory Capture
↓
2. Memory Intelligence
↓
3. Memory Storage
↓
4. Memory Retrieval
↓
5. Context Engineering
↓
6. Agent Reasoning
↓
7. Memory Evaluation
↺
The final loop is important.
The system should not simply store information forever.
It should continuously answer:
Is this memory still useful?
Is it still true?
Is it still relevant?
Is it still in the correct scope?
Should it be consolidated?
Should it expire?
That is what makes long-running agents manageable.

Internal Links:
- Learn MCP – Zero to Hero
- Learn AI Agents for QA – Zero to Hero
- Playwright Automation – Zero to Hero
- TencentDB Agent Memory: Complete Zero to Hero
- LangGraph: Complete Zero to Hero
- Learn Python – Zero to Hero
- OpenAI Codex: Complete Zero to Hero
- Cursor AI: Complete Zero to Hero
- Claude Code Tutorial: Complete Zero to Hero
- AutoGen: Complete Zero to Hero Guide
- Free QA Resources Built From Real Experience
- QA Glossary: Test Automation Terms Every Engineer Should Know
External Links
People Asked Questions
What is TencentDB Agent Memory?
TencentDB Agent Memory refers to using TencentDB-based storage and retrieval capabilities as part of an AI agent architecture to preserve useful context and knowledge across interactions.
Why do AI agents need long-term memory?
Long-term memory allows agents to retain useful information beyond a single conversation, improving personalization, continuity, planning, and decision-making.
Is agent memory the same as RAG?
No. RAG generally retrieves external knowledge from documents or databases, while agent memory focuses on information learned or accumulated through interactions, tasks, observations, and evolving agent state.
How does agent memory handle outdated information?
A production memory system can use timestamps, versioning, confidence scores, expiration policies, and conflict-resolution mechanisms to prevent stale information from dominating current context.
Can agent memory be tested?
Yes. Memory systems can be tested for retrieval accuracy, scope isolation, duplicate detection, conflict resolution, temporal reasoning, security, memory updates, and stale-memory behavior.
What is the difference between short-term and long-term agent memory?
Short-term memory supports the current task or conversation, while long-term memory preserves useful information that may be relevant across future interactions.
AI Overview & Answer-Engine Optimization
TencentDB Agent Memory is an approach for giving AI agents persistent, retrievable context that can evolve as new information becomes available.
Agent memory helps AI systems:
- Retain useful information across interactions
- Retrieve context relevant to the current task
- Track changing information
- Resolve conflicting memories
- Maintain project-specific context
- Support long-running agent workflows
Conclusion
The real power of TencentDB Agent Memory is not simply the ability to remember previous conversations.
The value comes from building a disciplined lifecycle around those memories.
A reliable agent should:
Capture useful information
↓
Understand what it means
↓
Validate it
↓
Assign scope
↓
Persist it selectively
↓
Retrieve it intelligently
↓
Rank it according to relevance
↓
Protect it with isolation policies
↓
Compress it when necessary
↓
Update it when reality changes
↓
Measure whether retrieval actually helped
The biggest mindset shift is this:
Do not design memory as storage. Design memory as evolving evidence for agent decisions.
When retrieval, persistence, lifecycle management, security, evaluation, and context engineering are treated as one system, an AI agent can move beyond remembering isolated conversations and begin maintaining useful long-term knowledge.
That is the foundation required for reliable long-running agents.
Final Key Takeaways
- Memory is an information lifecycle, not simply a database table.
- Every memory should have a purpose, scope, and useful metadata.
- Create, update, ignore, consolidate, and expire are different memory operations.
- Historical information should not automatically compete with current information.
- Provenance makes memories easier to trust, debug, and audit.
- User, project, agent, session, and task scopes should be explicitly separated.
- Retrieval quality must be measured with real evaluation datasets.
- Negative retrieval testing is as important as positive retrieval testing.
- RAG, memory, session context, and tools solve different information problems and can complement each other.
- The best memory system retrieves the smallest trustworthy context that improves the agent’s current decision.
Continue Learning
Explore more expert articles on n8n, Autogen, TencentDB, Cursor AI, XCUITest iOS Testing, Postman AI, LangChain, CrewAI, MCP Servers, AI Agents, LlamaIndex, Docker, FastAPI, Playwright, Cypress, Test Automation, DevOps, and Software Engineering at www.skakarh.com.
QAPulse by SK delivers expert release analysis, AI engineering insights, enterprise automation strategies, migration guidance, DevOps best practices, and practical testing knowledge to help software professionals build scalable, intelligent, and production-ready software systems.

