AutoGen + HatiData: Collaborative Agent Memory
AutoGen's Conversation Model
AutoGen organizes agents into conversation patterns — two-agent chats, group chats, and nested chats. Agents exchange messages in a structured flow, with each agent building on the previous messages in the conversation. This conversational approach is powerful for collaborative problem-solving, but it has a memory limitation: the conversation context only exists for the duration of the chat session.
When a GroupChat ends, the messages are gone. When an assistant agent finishes a task, its accumulated understanding is gone. When you start a new conversation about the same topic next week, the agents start from scratch.
HatiData adds persistent memory to AutoGen conversations. Agents can store important findings from one conversation and retrieve them in future conversations. The accumulated knowledge grows with every interaction, making agents more effective over time.
Adding Memory to AutoGen Agents
The integration uses AutoGen's function-calling capability to give agents HatiData memory tools:
import autogen
import httpx
HATIDATA_URL = "http://localhost:5439"
HATIDATA_KEY = "hd_live_your_key"
# Define memory functions that AutoGen agents can call
def store_memory(content: str, namespace: str = "autogen/shared", importance: str = "normal") -> str:
"""Store an important finding or observation for future conversations."""
response = httpx.post(
f"{HATIDATA_URL}/v1/memory/store",
headers={"Authorization": f"Bearer {HATIDATA_KEY}"},
json={
"content": content,
"namespace": namespace,
"metadata": {"importance": importance, "source": "autogen"},
},
)
return f"Memory stored: {response.json()['memory_id']}"
def search_memory(query: str, namespace: str = "autogen/shared", limit: int = 5) -> str:
"""Search past conversations for relevant information."""
response = httpx.post(
f"{HATIDATA_URL}/v1/memory/search",
headers={"Authorization": f"Bearer {HATIDATA_KEY}"},
json={
"query": query,
"namespace": namespace,
"limit": limit,
},
)
memories = response.json()["memories"]
if not memories:
return "No relevant memories found from past conversations."
return "\n".join(
[f"- [{m['similarity']:.0%}] {m['content']}" for m in memories]
)
def query_data(sql: str) -> str:
"""Execute a SQL query against the data warehouse."""
response = httpx.post(
f"{HATIDATA_URL}/v1/query",
headers={"Authorization": f"Bearer {HATIDATA_KEY}"},
json={"sql": sql},
)
return str(response.json()["results"])GroupChat with Shared Memory
The most common AutoGen pattern is a GroupChat where multiple agents collaborate. With HatiData, each agent can store findings that other agents (and future conversations) can access:
# Configuration for all agents
config_list = [{"model": "gpt-4o", "api_key": "your-api-key"}]
llm_config = {
"config_list": config_list,
"functions": [
{
"name": "store_memory",
"description": "Store an important finding for future reference",
"parameters": {
"type": "object",
"properties": {
"content": {"type": "string", "description": "The information to store"},
"importance": {"type": "string", "enum": ["low", "normal", "high"]},
},
"required": ["content"],
},
},
{
"name": "search_memory",
"description": "Search past conversations for relevant information",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "What to search for"},
"limit": {"type": "integer", "description": "Max results"},
},
"required": ["query"],
},
},
{
"name": "query_data",
"description": "Run a SQL query against the data warehouse",
"parameters": {
"type": "object",
"properties": {
"sql": {"type": "string", "description": "SQL query to execute"},
},
"required": ["sql"],
},
},
],
}
# Create agents with memory capabilities
analyst = autogen.AssistantAgent(
name="Analyst",
system_message="You are a data analyst. Use search_memory to check for relevant past findings before starting analysis. Use store_memory to save important discoveries.",
llm_config=llm_config,
)
strategist = autogen.AssistantAgent(
name="Strategist",
system_message="You are a business strategist. Use search_memory to review past recommendations and their outcomes. Store new strategic insights with store_memory.",
llm_config=llm_config,
)
user_proxy = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER",
function_map={
"store_memory": store_memory,
"search_memory": search_memory,
"query_data": query_data,
},
)
# Create group chat
groupchat = autogen.GroupChat(
agents=[user_proxy, analyst, strategist],
messages=[],
max_round=10,
)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)Assistant/User Proxy Memory Sharing
In the two-agent pattern (assistant + user proxy), HatiData memory enables continuity across sessions:
# Session 1: Research phase
user_proxy.initiate_chat(
analyst,
message="Analyze our customer churn rate for Q4 2025",
)
# Analyst uses query_data to analyze, stores findings with store_memory
# ... days later ...
# Session 2: Follow-up
user_proxy.initiate_chat(
analyst,
message="What were the main churn drivers we identified last time?",
)
# Analyst uses search_memory("churn drivers Q4") and retrieves previous findingsThe key instruction in the agent's system message is: "Use search_memory to check for relevant past findings before starting analysis." This prompts the agent to check its memory at the start of each conversation, providing continuity without explicit session management.
Memory-Augmented Conversation Patterns
Pattern 1: Pre-Conversation Memory Load
Before starting a GroupChat on a specific topic, pre-load relevant memories and include them in the initial message:
# Load relevant context before starting conversation
past_context = search_memory("customer retention strategies", limit=10)
user_proxy.initiate_chat(
manager,
message=f"""Let's discuss customer retention strategies for Q1.
Relevant findings from past conversations:
{past_context}
Based on this context, what should we focus on?""",
)Pattern 2: Post-Conversation Summary Storage
After a GroupChat completes, extract and store key decisions:
# After conversation completes
summary = "Key decisions from retention strategy discussion: 1) Implement proactive outreach for at-risk accounts, 2) Launch loyalty program for mid-market, 3) Hire 2 additional CSMs for enterprise segment"
store_memory(
content=summary,
namespace="autogen/decisions",
importance="high",
)Pattern 3: Cross-Team Knowledge Transfer
Different GroupChats (representing different teams) can share knowledge through common namespaces:
# Sales team GroupChat stores competitive intelligence
store_memory(
content="Prospect mentioned they are evaluating three other vendors for agent infrastructure",
namespace="shared/competitive-intel",
)
# Product team GroupChat retrieves sales insights
past_intel = search_memory(
query="what are prospects saying about competition",
namespace="shared/competitive-intel",
)Production Considerations
Conversation Replay
Store each conversation's full message history as a single memory entry. This allows future conversations to retrieve not just individual findings, but the full context of how a conclusion was reached:
# After GroupChat completes
full_history = "\n".join(
[f"{msg['name']}: {msg['content']}" for msg in groupchat.messages]
)
store_memory(
content=f"Full conversation transcript: {full_history}",
namespace="autogen/transcripts",
importance="low",
)Memory Namespaces for AutoGen
A recommended namespace structure for AutoGen deployments:
autogen/shared— Cross-conversation findings accessible to all agentsautogen/decisions— Key decisions and commitmentsautogen/transcripts— Full conversation records for replayautogen/{team_name}— Team-specific knowledge (e.g.,autogen/sales,autogen/engineering)
Error Handling
AutoGen's function execution should handle HatiData unavailability gracefully:
def search_memory_safe(query: str, **kwargs) -> str:
try:
return search_memory(query, **kwargs)
except Exception:
return "Memory search temporarily unavailable. Proceeding without past context."Next Steps
The AutoGen integration uses HatiData's HTTP API, making it compatible with AutoGen's function-calling mechanism. For richer memory patterns with built-in vector search classes, see the LangChain integration. For team-based memory coordination, see the CrewAI integration. For the complete MCP tool suite, see the Claude MCP guide.