How to Set Up Multi-Agent Shared Context with Agno Integration
Set up multi-agent shared context with Agno by instantiating AgnoSharedContext, binding role-scoped agents with bind_agent(), and using the returned stores as memory parameters in your Agno agents—no additional configuration required.
The Agno integration in Semantica enables teams of AI agents to share a unified knowledge graph and vector store while maintaining role-scoped data boundaries. This article walks through the complete setup using AgnoSharedContext, thread-safe coordination, and real code examples from the semantica-agi/semantica repository.
Architecture of Agno Multi-Agent Shared Context
The integration centers on four interconnected components that handle coordination, storage, protocol compliance, and underlying memory services.
Core Components
| Component | File | Purpose |
|---|---|---|
AgnoSharedContext |
integrations/agno/shared_context.py |
Thread-safe coordinator holding one AgentContext and managing role-scoped views |
_AgentScopedStore |
integrations/agno/shared_context.py |
Per-role implementation of AgnoContextStore that tags all operations with an agent's role |
AgnoContextStore |
integrations/agno/context_store.py |
Agno MemoryDb protocol implementation using Semantica's hybrid memory |
AgentContext |
semantica.context |
Underlying vector store + knowledge graph with analytics and decision recording |
Thread Safety and Idempotency
AgnoSharedContext protects concurrent access using a re-entrant lock (threading.RLock) around bind_agent() at lines 117-122 of shared_context.py. Multiple calls to bind_agent("researcher") return the same _AgentScopedStore instance—verified by TestBindAgent.test_bind_idempotent in the test suite.
Shared Memory Pool Mechanics
The shared context maintains self._shared_memories (lines 84-86) as a central pool. When any agent calls upsert_memory(), data writes to both:
- The agent's local cache (
self._memories) - The shared pool (
self._shared._shared_memories)
This design ensures immediate cross-agent visibility without polling or synchronization delay.
Setting Up AgnoSharedContext
Basic Initialization
from semantica.context import ContextGraph
from semantica.vector_store import VectorStore
from integrations.agno import AgnoSharedContext
# Create coordinated shared context
shared = AgnoSharedContext(
vector_store=VectorStore(backend="faiss"),
knowledge_graph=ContextGraph(advanced_analytics=True),
decision_tracking=True, # Auto-record decisions on memory writes
graph_expansion=True, # Enrich retrievals with graph neighbors
)
The AgnoSharedContext constructor auto-creates a single AgentContext combining your vector backend and graph instance. No manual wiring between components is necessary.
Binding Role-Scoped Agents
# Create scoped stores for different team roles
researcher_store = shared.bind_agent("researcher")
analyst_store = shared.bind_agent("analyst")
pm_store = shared.bind_agent("product_manager")
Each call returns an _AgentScopedStore that:
- Delegates to the parent
AgentContext - Tags every operation with the bound role
- Shares data through the central pool
Integrating with Agno Agents and Teams
Agent Configuration with Shared Memory
from agno.agent import Agent
from agno.team import Team
from integrations.agno import AgnoKGToolkit, AgnoDecisionKit
researcher = Agent(
name="Researcher",
memory=researcher_store, # Role-scoped memory DB
tools=[AgnoKGToolkit(context=shared)], # Shared graph access
)
analyst = Agent(
name="Analyst",
memory=analyst_store,
tools=[AgnoDecisionKit(context=shared)], # Decision history access
)
pm = Agent(
name="ProductManager",
memory=pm_store,
tools=[AgnoKGToolkit(context=shared)],
)
# Coordinate mode enables multi-agent collaboration
team = Team(agents=[researcher, analyst, pm], mode="coordinate")
Pass the scoped stores directly to Agno's memory parameter—they fully implement the MemoryDb protocol that Agent expects.
Reading and Writing Shared Memories
Cross-Agent Data Visibility
# Researcher discovers information
researcher.memory.upsert_memory({
"memory": "GDPR amendment requires data residency in EU",
"user_id": "regulatory_scan"
})
# Analyst immediately retrieves without explicit sync
memories = analyst.memory.read_memories()
print([m.memory for m in memories])
# → ["GDPR amendment requires data residency in EU"]
The underlying AgentContext.store() and retrieve() operations handle persistence. Graph expansion (if graph_expansion=True) enriches results with semantically related nodes via the ContextGraph.
Explicit Decision Recording
For decisions requiring explicit categorization beyond automatic tracking:
shared.record_decision(
category="compliance_strategy",
scenario="EU market entry with new GDPR rules",
reasoning="Amendment shifts cost-benefit; revised ROI 340%",
outcome="proceed_with_caveat",
confidence=0.87,
agent_role="analyst" # Creates tagged category "compliance_strategy:analyst"
)
This writes directly to AgentContext.record_decision() and surfaces in AgnoDecisionKit queries.
Retrieving Context for LLM Grounding
Global Insights and Precedents
# Analytics summary across all agent contributions
prompt_context = shared.get_shared_insights()
# Relevant historical decisions
precedents = shared._context.find_precedents_advanced(
scenario="market expansion under regulatory constraint",
limit=5
)
# Inject into prompt
grounded_prompt = f"""Context: {prompt_context}
Relevant precedents:
{chr(10).join(f"- {p.scenario}: {p.outcome}" for p in precedents)}
Current task: ..."""
find_precedents_advanced() leverages the knowledge graph's structural relationships beyond vector similarity.
Configuration Options Reference
| Parameter | Default | Effect |
|---|---|---|
decision_tracking |
False |
Records lightweight decision entry on every upsert_memory() |
graph_expansion |
False |
Expands retrieval results with graph neighbors during read_memories() |
advanced_analytics |
False (on ContextGraph) |
Enables get_shared_insights() analytics methods |
backend |
required | Vector store backend: "faiss", "chroma", etc. |
Summary
AgnoSharedContextinintegrations/agno/shared_context.pyprovides thread-safe, single-instance coordination for multi-agent teamsbind_agent(role)returns idempotent, role-scoped stores that implement Agno'sMemoryDbprotocol- Shared visibility is automatic through
self._shared_memories; no polling or message passing required - Decision tracking can be automatic (per-memory) or explicit (via
record_decision()) - Graph expansion and analytics enrich agent context beyond raw vector retrieval
Frequently Asked Questions
Can multiple agents with the same role share one store safely?
Yes. bind_agent() is idempotent—multiple calls with identical role strings return the same _AgentScopedStore instance. The implementation uses threading.RLock to ensure thread-safe concurrent access, as verified in tests/integrations/agno/test_shared_context.py.
What happens when one agent writes memory—do others see it immediately?
Yes. The upsert_memory() implementation in _AgentScopedStore writes to both local cache and self._shared._shared_memories. Any other agent's read_memories() call retrieves from this shared pool through the underlying AgentContext, providing immediate visibility without explicit synchronization.
Is decision tracking mandatory, and what does it record?
No. decision_tracking=False by default. When enabled, each upsert_memory() automatically creates a lightweight decision entry via AgentContext.record_decision(). For explicit control, use shared.record_decision() directly with full metadata including category, scenario, reasoning, outcome, and confidence.
Can I use this with custom Agno tools beyond the provided kits?
Yes. AgnoSharedContext exposes the underlying AgentContext at shared._context and the scoped stores implement standard MemoryDb methods (upsert_memory, read_memories, delete_memory, clear). Custom tools can interact with these directly or use AgnoKGToolkit and AgnoDecisionKit as reference implementations.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →