---
title: "AI Agents | Use Cases | SurrealDB"
description: "Build context-aware AI agents with SurrealDB and Agent Memory. Unified context, persistent memory, and structured knowledge in one transactional system."
url: https://surrealdb.com/use-cases/ai-agents
---

# Build context-aware AI agents

Agents fail because of context, not models. The database and agent memory give AI agents structured context, persistent memory, and transactional consistency in one system.

[Start free with SurrealDB](https://studio.surrealdb.com/current/instances/deploy) [Explore Agent Memory](https://surrealdb.com/agent-memory)

1. ![Babcock](https://surrealdb.com/assets/static/babcock.lo4rnVg1.svg)
2. ![ING](https://surrealdb.com/assets/static/ing.X3I6S3_V.svg)
3. ![British Airways](https://surrealdb.com/assets/static/british-airways.KEsZiwV-.svg)
4. ![Nvidia](https://surrealdb.com/assets/static/nvidia.DaIEuMil.svg)
5. ![Apple](https://surrealdb.com/assets/static/apple.D5pq4flY.svg)
6. ![SpaceX](https://surrealdb.com/assets/static/spacex.CQJEk-IL.svg)
7. ![Samsung](https://surrealdb.com/assets/static/samsung.CH-vQgnb.svg)
8. ![adidas](https://surrealdb.com/assets/static/adidas.DdTC5qhk.svg)
9. ![Tencent](https://surrealdb.com/assets/static/tencent.paQmLxyy.svg)
10. ![Alibaba](https://surrealdb.com/assets/static/alibaba.B16idgfM.svg)
11. ![PolyAI](https://surrealdb.com/assets/static/poly-ai.c3w_fAg6.svg)
12. ![Later](https://surrealdb.com/assets/static/later.Ds736jFO.svg)
13. ![Verizon](https://surrealdb.com/assets/static/verizon.BI7CajdX.svg)
14. ![Liberty Mutual](https://surrealdb.com/assets/static/liberty-mutual.B7qOU1pd.svg)
15. ![Walmart](https://surrealdb.com/assets/static/walmart.BjDg_Sr8.svg)
16. ![Carrier](https://surrealdb.com/assets/static/carrier.D21gC6NX.svg)
17. ![Saks Fifth Avenue](https://surrealdb.com/assets/static/saks-fifth-avenue.COIDpLSb.svg)
18. ![San Francisco Compute Company](https://surrealdb.com/assets/static/sfcc.B7jlImq4.svg)
19. ![Shield AI](https://surrealdb.com/assets/static/shield-ai.pINZ0KJr.svg)
20. ![Wix](https://surrealdb.com/assets/static/wix.DvHhmoBi.svg)

THE PROBLEM

## The context wall

Every AI team hits the same wall. The model is capable, but the agent cannot remember what happened two turns ago, cannot connect a user preference to a product entity, and cannot guarantee that concurrent writes stay consistent.

Today's teams assemble five or six systems - a vector database, a document store, a graph database, a cache, a queue, and a memory middleware layer - then spend months writing glue code to keep them consistent. Every seam is a place where context leaks.

### Context leakage

When data flows between separate systems, agents lose context. Relationships, history, and metadata get fragmented.

### No atomicity

Without unified transactions, an agent can update memory in one system but fail to update state in another.

### Latency spikes

Multi-system pipelines add round trips. Each hop introduces latency that compounds under load.

### Operational overhead

Five systems means five failure modes, five monitoring setups, five sets of credentials to manage.

THE SOLUTION

## The read-think-write loop

Agents operate in a continuous cycle: read context, reason over it, and write results back. The unified data layer keeps the entire loop inside one transactional system.

READ

Graph traversal, vector search, and temporal facts - one SurrealQL statement, one round trip.

SurrealQL

Multi-model query

Graph

Vector

Temporal

Unified result set

THINK

Documents, relationships, embeddings, and history arrive together. The agent reasons over complete context.

Result set

Multi-model query output

Documents

Relations

Vectors

History

Complete context

WRITE

Persist decisions, update entities, trigger events - one ACID transaction, no partial writes.

BEGIN TRANSACTION

ACID transaction boundary

Update

Create

Trigger

COMMITTED

CONTEXT ENGINEERING

## Context engineering in one query

SurrealQL lets you combine graph traversal, vector similarity, structured filters, and temporal queries in a single statement. One round trip gives the agent everything it needs.

```
1-- Context engineering: combine graph, vector, and temporal data2LET $user = user:jaime;3LET $query_vec = fn::embed("What products does this user like?");45SELECT6	->purchased->product AS purchase_history,7	->reviewed->product[WHERE vector::similarity::cosine(embedding, $query_vec) > 0.8] AS relevant_products,8	->preferences[WHERE valid_at <= time::now()] AS current_preferences9FROM ONLY $user;
```

MULTI-AGENT

## Multi-agent coordination

Multiple agents share the same knowledge graph and memory. Coordination happens through shared context with ACID guarantees - no message passing, no race conditions.

### Shared memory

Agents read from and write to the same Agent Memory graph. Knowledge accumulates across the team.

### ACID consistency

Concurrent writes from multiple agents are serialised. No conflicts, no lost updates.

### Event-driven handoffs

Live queries and events trigger downstream agents when relevant data changes.

### Unified permissions

RBAC and record-level permissions apply consistently across all agents accessing the system.

THE STACK

## Database and Agent Memory

SurrealDB provides the multi-model database for structured context. Agent Memory provides persistent memory for AI agents. Together, they form the unified data layer - one stack, one transaction boundary, one permission model.

### Structured context

SurrealDB stores documents, graphs, vectors, time-series, and relational data in one engine.

[Learn more](https://surrealdb.com/surrealdb)

Documents

Graphs

Vectors

Time-series

One engine

### Persistent memory

Agent Memory provides knowledge graphs, entity extraction, and temporal facts for agent memory.

[Learn more](https://surrealdb.com/agent-memory)

Knowledge graph

Entities

Relations

Memory layer

Temporal facts

Entity extraction

Agent Memory

### Hybrid retrieval

Combine vector similarity, graph traversal, and structured filters in a single query.

[Learn more](https://surrealdb.com/surrealdb)

Single query

SELECT ..., vector::similarity(...), ->relates->

Vector

Graph

Filter

One result set

### Managed infrastructure

Deploy the full stack in SurrealDB Cloud - fully managed, scale on demand.

[Learn more](https://surrealdb.com/cloud)

SurrealDB Cloud

✓

SurrealDB

Active

✓

Agent Memory

Active

✓

Storage layer

Active

WORKS WITH YOUR FRAMEWORK

## The unified data layer beneath your orchestrator

LangGraph, CrewAI, and AutoGen orchestrate agent logic - the control flow. SurrealDB provides the persistent data layer beneath - the data, the memory, the knowledge graph. They are complementary. Connect through MCP, SDKs, or direct API calls.

FREQUENTLY ASKED QUESTIONS

## AI agents

How does the context layer differ from RAG?

Can I use SurrealDB without Agent Memory for AI agents?

What frameworks does SurrealDB integrate with?

GET STARTED

## Build context-aware AI agents

Structured context, persistent memory, and transactional consistency. One stack.

![Samsung](https://surrealdb.com/assets/static/4c58b81e7b3c9466.C_Hv0eml.svg)![NVIDIA](https://surrealdb.com/assets/static/nvidia.DaIEuMil.svg)![Apple](https://surrealdb.com/assets/static/f7dc2519e0d212bc.Cn8MYAK7.svg)![Verizon](https://surrealdb.com/assets/static/18b99996c689000f.B5PQ-nI9.svg)![Tencent](https://surrealdb.com/assets/static/401d8346058682c8.DqM87mst.svg)

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

[Start free with SurrealDB](https://studio.surrealdb.com/current/instances/deploy) [Join agent memory early access](https://surrealdb.com/agent-memory/get-started)

```json
{"@context":"https://schema.org","@type":"Organization","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is the unified data layer for AI. A multi-model database for documents, graphs, vectors, and time-series.","foundingDate":"2022","hasCertification":[{"@type":"Certification","name":"SOC 2 Type 2"},{"@type":"Certification","name":"GDPR"},{"@type":"Certification","name":"Cyber Essentials Plus"},{"@type":"Certification","name":"ISO 27001"}],"owns":[{"@type":"SoftwareApplication","name":"SurrealDB","url":"https://surrealdb.com/surrealdb"},{"@type":"SoftwareApplication","name":"Agent Memory","url":"https://surrealdb.com/agent-memory"}],"knowsAbout":["multi-model databases","document databases","graph databases","vector search","time-series databases","SurrealQL","Agent Memory","real-time databases","embedded databases","context layer","graph ontology","distributed database","knowledge graphs","distributed transaction protocols","highly-scalable databases"],"sameAs":["https://www.wikidata.org/wiki/Q124316308","https://github.com/surrealdb/surrealdb","https://twitter.com/surrealdb","https://www.youtube.com/@surrealdb","https://www.linkedin.com/company/surrealdb","https://discord.gg/surrealdb","https://www.reddit.com/r/surrealdb","https://www.instagram.com/surrealdb","https://medium.com/surrealdb","https://dev.to/surrealdb"]}
```

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://surrealdb.com"},{"@type":"ListItem","position":2,"name":"AI agents","item":"https://surrealdb.com/use-cases/ai-agents"}]}
```

```json
{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"How does the context layer differ from RAG?","acceptedAnswer":{"@type":"Answer","text":"RAG retrieves chunks of text using vector similarity. The context layer provides structured, multi-modal context - graphs, documents, vectors, temporal facts, and agent memory - in one transactional system. RAG is one retrieval pattern within the context layer."}},{"@type":"Question","name":"Can I use SurrealDB without Agent Memory for AI agents?","acceptedAnswer":{"@type":"Answer","text":"Yes. SurrealDB provides the multi-model database for context, graph traversal, vector search, and real-time subscriptions. Agent Memory adds structured memory on top. You can start with SurrealDB and add Agent Memory when you need agent memory."}},{"@type":"Question","name":"What frameworks does SurrealDB integrate with?","acceptedAnswer":{"@type":"Answer","text":"SurrealDB integrates with LangChain, LlamaIndex, and any MCP-compatible client through the MCP server. Official SDKs are available for Python, JavaScript, Rust, Go, Java, .NET, and PHP."}}]}
```
