# How AgentContext Provides Multi-Agent Shared Memory with Agno Integration

> Learn how AgentContext offers multi-agent shared memory using Agno integration. Agents access a unified vector store for instant memory sharing and collaboration.

- Repository: [Semantica /semantica](https://github.com/semantica-agi/semantica)
- Tags: how-to-guide
- Published: 2026-08-21

---

**AgentContext enables multi-agent shared memory by accepting a single Agno-backed vector store instance that multiple agents reference, allowing any agent's `store()` calls to become immediately visible to others through the unified `AgentMemory` interface.**

In the `semantica-agi/semantica` repository, the `AgentContext` class serves as the high-level façade that coordinates vector storage, knowledge graphs, and decision tracking for intelligent agents. When building distributed multi-agent systems, developers require a mechanism where specialized agents can read from and write to a coherent, unified memory space. The **AgentContext multi-agent shared memory Agno integration** solves this architectural challenge by allowing multiple `AgentContext` instances to share a single underlying Agno database through dependency injection.

## Core Architecture of AgentContext

### The Unified Memory Interface

The `AgentContext` class in [`semantica/context/agent_context.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/context/agent_context.py) delegates all memory operations to internal `AgentMemory` and `ContextRetriever` objects. These components abstract away the underlying storage mechanism, providing a consistent API for **Retrieval-Augmented Generation (RAG)** and **GraphRAG** operations regardless of which vector store backs the system.

### Constructor and Storage Components

According to the source code at lines 90-108, the constructor requires a `vector_store` parameter and optionally accepts a `knowledge_graph`:

```python

# semantica/context/agent_context.py#L90-L108

class AgentContext:
    def __init__(self, vector_store: Any, knowledge_graph: Optional[Any] = None, …):
        …
        self._memory = AgentMemory(**memory_config)            # shared memory

        self._retriever = ContextRetriever(**retriever_config)  # optional GraphRAG

```

All subsequent calls to `store()`, `retrieve()`, and `forget()` route through `self._memory`, ensuring that every agent interacts with the same storage backend when identical store instances are shared across contexts.

## Agno Integration for Shared Storage

### AgnoSharedContext Implementation

The Agno integration exposes `AgnoSharedContext` (available via `integrations.agno.shared_context`), which wraps the Agno memory database to implement the interface expected by `AgentContext`. The test suite at [`tests/integrations/agno/test_shared_context.py`](https://github.com/semantica-agi/semantica/blob/main/tests/integrations/agno/test_shared_context.py) demonstrates how a single Agno DB instance can be injected into multiple contexts:

```python

# tests/integrations/agno/test_shared_context.py#L14-L23

# Stub agno memory DB

agno = types.ModuleType("agno")
memory_pkg = types.ModuleType("agno.memory")
memory_db_pkg = types.ModuleType("agno.memory.db")
memory_db_base = types.ModuleType("agno.memory.db.base")
memory_db_row = types.ModuleType("agno.memory.db.row")
…

```

### Wiring Multiple Agents to One Store

To achieve multi-agent shared memory, instantiate one `AgnoSharedContext` and pass it to every `AgentContext` constructor:

```python
from semantica.context import AgentContext
from integrations.agno.shared_context import AgnoSharedContext

# Initialise a single Agno-backed vector store

shared_vs = AgnoSharedContext(vector_store_config={"type": "in_memory"})

# Create two agents that share the same store

agent_a = AgentContext(vector_store=shared_vs, knowledge_graph=kg)
agent_b = AgentContext(vector_store=shared_vs, knowledge_graph=kg)

# Agent A stores a memory – Agent B can retrieve it immediately

mem_id = agent_a.store("User asked about loan rates", conversation_id="conv1")
results = agent_b.retrieve("loan rates")

```

Because both agents hold references to the same underlying `AgentMemory` and Agno database object, writes from one agent are instantly readable by the other without synchronization delays.

## Advanced Shared Capabilities

### Shared Knowledge Graph and Decision Tracking

When `decision_tracking=True` and a knowledge graph is supplied, `AgentContext` initializes additional components including `DecisionRecorder`, `DecisionQuery`, `CausalChainAnalyzer`, and `PolicyEngine` (lines 29-44). These classes receive the same KG instance, enabling agents to share not only raw memories but also structured decision metadata:

```python

# semantica/context/agent_context.py#L29-L44

if decision_tracking and knowledge_graph:
    self._decision_recorder = DecisionRecorder(knowledge_graph)
    self._decision_query = DecisionQuery(graph_store=knowledge_graph, …)

```

This allows coordinated reasoning across agents:

```python

# Record a decision in one agent

decision_id = agent.record_decision(
    category="approval",
    scenario="loan_application",
    reasoning="high credit score",
    outcome="approved",
    confidence=0.96
)

# Later, any other agent with the same KG can query the decision

related = agent.find_precedents_advanced(
    query="loan approval",
    category="approval",
    use_kg_features=True
)

```

### Persistence Across Sessions

The `save()` and `load()` methods (lines 308-322) serialize the vector store, knowledge graph, and memory state to disk. When multiple agents point to the same persisted directory, they automatically rehydrate identical shared memory on restart:

```python

# semantica/context/agent_context.py#L308-L322

def save(self, path: str) -> None:
    …
    if hasattr(self._memory, "save"):
        self._memory.save(path)                     # persists shared memory

```

Example usage:

```python

# Save the whole shared state from one agent

agent_a.save("./shared_context")

# In a new process, load the same state for another agent

agent_b = AgentContext(vector_store=shared_vs, knowledge_graph=kg)
agent_b.load("./shared_context")

# The loaded agent sees all previously stored memories

print(agent_b.count())   # same count as before the restart

```

## Summary

- **AgentContext** acts as a façade that unifies vector storage, knowledge graphs, and decision tracking through `AgentMemory` and `ContextRetriever`.
- **Agno integration** provides `AgnoSharedContext`, allowing multiple agents to reference a single underlying database instance via the `vector_store` constructor parameter.
- **Shared state consistency** is achieved by injecting the same store instance into multiple `AgentContext` objects, making all `store()` operations immediately visible across agents through the unified interface.
- **Decision tracking** and **KG coupling** enable coordinated reasoning by sharing structured decision metadata alongside raw vector memories when the same `knowledge_graph` instance is shared.
- **Persistence methods** `save()` and `load()` ensure shared memory survives process restarts when agents reference the same serialized directory path.

## Frequently Asked Questions

### How does AgentContext ensure memory consistency across agents?

AgentContext ensures consistency by holding references to the same underlying storage objects. When multiple agents receive the same `AgnoSharedContext` instance, they all interact with a single `AgentMemory` object that delegates to the same Agno database. This means any `store()` operation immediately mutates the shared state that all other agents read from during `retrieve()` calls.

### Can different agent types share the same Agno-backed memory?

Yes. The `AgentContext` constructor accepts any vector store implementing the required interface, including Agno-backed stores. Because the storage contract is abstracted through `AgentMemory`, heterogeneous agents with different configurations can share memory as long as they receive the same `vector_store` instance during initialization.

### What happens to shared memory when agents restart?

The `save()` method serializes the vector store, knowledge graph, and memory state to disk as seen in [`semantica/context/agent_context.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/context/agent_context.py) lines 308-322. When agents restart and call `load()` pointing to the same path, they rehydrate the identical shared state. This persistence mechanism ensures that multi-agent shared memory remains consistent across process lifecycles.

### Is GraphRAG supported in multi-agent shared memory scenarios?

Yes. When agents share a `knowledge_graph` instance alongside their vector store, the `ContextRetriever` enables GraphRAG capabilities through hybrid retrieval. Multiple agents can write to and query the shared knowledge graph, allowing complex multi-hop reasoning and relationship-based retrieval across the collective memory of all agents.